Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable optimization via environment variable #1869

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
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
8 changes: 6 additions & 2 deletions onnxscript/_framework_apis/torch_2_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import onnx

from onnxscript import ir
from onnxscript import ir, optimizer
from onnxscript.function_libs.torch_lib import registration
from onnxscript.ir import _external_data

Expand All @@ -28,6 +28,9 @@
os.getenv("TORCH_ONNX_OFFLOAD_EXTERNAL_DATA_WITH_IR") != "0"
)

# Internal flag. Will go away.
_TORCH_ONNX_ENABLE_OPTIMIZATION = os.getenv("TORCH_ONNX_ENABLE_OPTIMIZATION") == "1'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "1'" -> "1"



@dataclasses.dataclass(frozen=True)
class _OnnxFunctionMeta:
Expand All @@ -50,7 +53,8 @@
def optimize(model: ir.Model) -> ir.Model:
"""Optimize the model."""

# TODO(justinchuby): Use the optimizer
if _TORCH_ONNX_ENABLE_OPTIMIZATION:
optimizer.optimize_ir(model)

Check warning on line 57 in onnxscript/_framework_apis/torch_2_5.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/_framework_apis/torch_2_5.py#L57

Added line #L57 was not covered by tests
return model


Expand Down
Loading