diff --git a/onnxscript/_framework_apis/torch_2_8.py b/onnxscript/_framework_apis/torch_2_8.py index bbd1ffc786..dca34086a0 100644 --- a/onnxscript/_framework_apis/torch_2_8.py +++ b/onnxscript/_framework_apis/torch_2_8.py @@ -1,6 +1,6 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -"""Stable APIs for PyTorch 2.7.""" +"""Stable APIs for PyTorch 2.8.""" from __future__ import annotations diff --git a/onnxscript/_framework_apis/torch_2_9.py b/onnxscript/_framework_apis/torch_2_9.py new file mode 100644 index 0000000000..88c9b85734 --- /dev/null +++ b/onnxscript/_framework_apis/torch_2_9.py @@ -0,0 +1,35 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +"""Stable APIs for PyTorch 2.9.""" + +from __future__ import annotations + +__all__ = [ + "check_model", + "convert_version", + "get_torchlib_ops", + "optimize", + "save_model_with_external_data", +] + +from typing import TYPE_CHECKING + +from onnxscript import version_converter +from onnxscript._framework_apis.torch_2_8 import ( + check_model, + get_torchlib_ops, + optimize, + save_model_with_external_data, +) + +if TYPE_CHECKING: + import onnx_ir as ir + + +def convert_version(model: ir.Model, target_version: int) -> ir.Model: + """Convert the model to the specified ONNX opset version. + + Starting from PyTorch 2.9, down conversion is turned on and supported. + """ + version_converter.convert_version(model, target_version, fallback=True) + return model diff --git a/onnxscript/version_converter/__init__.py b/onnxscript/version_converter/__init__.py index b95aa1a4fa..b0831a00f9 100644 --- a/onnxscript/version_converter/__init__.py +++ b/onnxscript/version_converter/__init__.py @@ -107,6 +107,13 @@ def call(self, model: ir.Model) -> ir.passes.PassResult: self.target_version, ) return ir.passes.PassResult(model, False) + else: + logger.warning( + "The model version conversion is not supported by the onnxscript version converter " + "and fallback is enabled. The model will be converted using the onnx C API " + "(target version: %d).", + self.target_version, + ) # If the onnxscript version converter does not support the conversion, # we can use the onnx C API to convert the model