Skip to content

Conversation

@thomas-chauchefoin-tob
Copy link
Collaborator

@thomas-chauchefoin-tob thomas-chauchefoin-tob commented Dec 3, 2025

This reduces the number of files created in the local folder. This PR doesn't touch the public API that sometimes expects file paths as arguments, so there will still be a few files here and here the associated tests.

@thomas-chauchefoin-tob thomas-chauchefoin-tob marked this pull request as ready for review December 3, 2025 15:58
@dguido
Copy link
Member

dguido commented Jan 9, 2026

This PR removes the Python 3.14+ compatibility handling that exists in master. The current test_pytorch.py has:

_lacks_torch_jit_support = sys.version_info >= (3, 14)

# In setUp:
if not _lacks_torch_jit_support:
    m = torch.jit.script(model)
    ...

# On tests:
@unittest.skipIf(_lacks_torch_jit_support, "PyTorch 2.9.1 JIT broken with Python 3.14+")
def test_torchscript_wrapper(self):
    ...

The PR removes all of this and unconditionally calls torch.jit.script(model), which will fail on Python 3.14+.

Why it fails: Python 3.14 removed __annotations__ from class instances (PEP 749), and TorchScript relies on it. Calling torch.jit.script() crashes with:

AttributeError: 'Module' object has no attribute '__annotations__'

PyTorch won't fix this because TorchScript is deprecated as of PyTorch 2.9 (replaced by torch.export).

Fix: Preserve the _lacks_torch_jit_support guards when migrating to temp directories:

import sys
_lacks_torch_jit_support = sys.version_info >= (3, 14)

def setUp(self):
    self.tmpdir = tempfile.TemporaryDirectory()
    tmppath = Path(self.tmpdir.name)
    
    model = models.mobilenet_v2()
    self.filename_v1_3 = tmppath / "test_model.pth"
    torch.save(model, self.filename_v1_3)
    
    if not _lacks_torch_jit_support:
        m = torch.jit.script(model)
        self.torchscript_filename = tmppath / "test_model_torchscript.pth"
        torch.jit.save(m, self.torchscript_filename)

And keep the @unittest.skipIf decorators on the TorchScript tests.

Refs:

@dguido dguido force-pushed the migrate-tests-bytesio branch from 1302886 to a0b7265 Compare January 20, 2026 16:12
@dguido dguido merged commit 819f4c3 into master Jan 20, 2026
14 checks passed
@dguido dguido deleted the migrate-tests-bytesio branch January 20, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants