11import os
2+ import sys
23import unittest
34
45import torch
78from fickling .fickle import Pickled
89from fickling .pytorch import PyTorchModelWrapper
910
11+ _lacks_torch_jit_support = sys .version_info >= (3 , 14 )
1012
1113class TestPyTorchModule (unittest .TestCase ):
1214 def setUp (self ):
1315 model = models .mobilenet_v2 ()
1416 self .filename_v1_3 = "test_model.pth"
1517 torch .save (model , self .filename_v1_3 )
1618 self .zip_filename = "test_random_data.zip"
17- m = torch .jit .script (model )
18- self .torchscript_filename = "test_model_torchscript.pth"
19- torch .jit .save (m , self .torchscript_filename )
19+ if not _lacks_torch_jit_support :
20+ m = torch .jit .script (model )
21+ self .torchscript_filename = "test_model_torchscript.pth"
22+ torch .jit .save (m , self .torchscript_filename )
2023
2124 def tearDown (self ):
22- for filename in [self .filename_v1_3 , self .zip_filename , self .torchscript_filename ]:
25+ files = [self .filename_v1_3 , self .zip_filename ]
26+ if not _lacks_torch_jit_support :
27+ files .append (self .torchscript_filename )
28+ for filename in files :
2329 if os .path .exists (filename ):
2430 os .remove (filename )
2531
@@ -29,6 +35,7 @@ def test_wrapper(self):
2935 except Exception as e : # noqa
3036 self .fail (f"PyTorchModelWrapper was not able to load a PyTorch v1.3 file: { e } " )
3137
38+ @unittest .skipIf (_lacks_torch_jit_support , "PyTorch 2.9.1 JIT broken with Python 3.14+" )
3239 def test_torchscript_wrapper (self ):
3340 try :
3441 PyTorchModelWrapper (self .torchscript_filename )
@@ -40,6 +47,7 @@ def test_pickled(self):
4047 pickled_portion = result .pickled
4148 self .assertIsInstance (pickled_portion , Pickled )
4249
50+ @unittest .skipIf (_lacks_torch_jit_support , "PyTorch 2.9.1 JIT broken with Python 3.14+" )
4351 def test_torchscript_pickled (self ):
4452 result = PyTorchModelWrapper (self .torchscript_filename )
4553 pickled_portion = result .pickled
0 commit comments