@@ -145,8 +145,8 @@ def test_error_if_no_input(tmp_path):
145145 "dynamo" ,
146146 [
147147 None ,
148- pytest .param (False , marks = RunIf (min_torch = "2.6 .0" , dynamo = True , onnxscript = True )),
149- pytest .param (True , marks = RunIf (min_torch = "2.6 .0" , dynamo = True , onnxscript = True )),
148+ pytest .param (False , marks = RunIf (min_torch = "2.5 .0" , dynamo = True , onnxscript = True )),
149+ pytest .param (True , marks = RunIf (min_torch = "2.5 .0" , dynamo = True , onnxscript = True )),
150150 ],
151151)
152152@RunIf (onnx = True )
@@ -184,7 +184,7 @@ def to_numpy(tensor):
184184 assert np .allclose (to_numpy (torch_out ), ort_outs [0 ], rtol = 1e-03 , atol = 1e-05 )
185185
186186
187- @RunIf (min_torch = "2.6 .0" , dynamo = True )
187+ @RunIf (min_torch = "2.5 .0" , dynamo = True )
188188@pytest .mark .skipif (_ONNXSCRIPT_AVAILABLE , reason = "Run this test only if onnxscript is not available." )
189189def test_model_onnx_export_missing_onnxscript ():
190190 """Test that an error is raised if onnxscript is not available."""
@@ -193,21 +193,41 @@ def test_model_onnx_export_missing_onnxscript():
193193
194194 with pytest .raises (
195195 ModuleNotFoundError ,
196- match = re .escape (f"`{ type (model ).__name__ } .to_onnx(dynamo=True)` requires `onnxscript` to be installed." ),
196+ match = re .escape (
197+ f"`{ type (model ).__name__ } .to_onnx(dynamo=True)` requires `onnxscript` and `torch>=2.5.0` to be installed." ,
198+ ),
197199 ):
198200 model .to_onnx (dynamo = True )
199201
200202
201- @RunIf (onnx = True , min_torch = "2.6 .0" , dynamo = True , onnxscript = True )
203+ @RunIf (onnx = True , min_torch = "2.5 .0" , dynamo = True , onnxscript = True )
202204def test_model_return_type ():
203205 model = BoringModel ()
204206 model .example_input_array = torch .randn ((1 , 32 ))
205207 model .eval ()
206208
207209 onnx_pg = model .to_onnx (dynamo = True )
208- assert isinstance (onnx_pg , torch .onnx .ONNXProgram )
210+
211+ onnx_cls = torch .onnx .ONNXProgram if torch .__version__ >= "2.6.0" else torch .onnx ._internal .exporter .ONNXProgram
212+
213+ assert isinstance (onnx_pg , onnx_cls )
209214
210215 model_ret = model (model .example_input_array )
211216 inf_ret = onnx_pg (model .example_input_array )
212217
213218 assert torch .allclose (model_ret , inf_ret [0 ], rtol = 1e-03 , atol = 1e-05 )
219+
220+
221+ @RunIf (max_torch = "2.5.0" )
222+ def test_model_onnx_export_wrong_torch_version ():
223+ """Test that an error is raised if onnxscript is not available."""
224+ model = BoringModel ()
225+ model .example_input_array = torch .randn (5 , 32 )
226+
227+ with pytest .raises (
228+ ModuleNotFoundError ,
229+ match = re .escape (
230+ f"`{ type (model ).__name__ } .to_onnx(dynamo=True)` requires `onnxscript` and `torch>=2.5.0` to be installed." ,
231+ ),
232+ ):
233+ model .to_onnx (dynamo = True )
0 commit comments