Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onnxscript/_framework_apis/torch_2_8.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
37 changes: 37 additions & 0 deletions onnxscript/_framework_apis/torch_2_9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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

import onnx_ir as ir

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:
from onnxscript import 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
7 changes: 7 additions & 0 deletions onnxscript/version_converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading