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

Turn on TORCHLIB_EXPERIMENTAL_PREFER_TRACING #1304

Merged
merged 6 commits into from
May 24, 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
6 changes: 6 additions & 0 deletions onnxscript/function_libs/torch_lib/_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ def _load_boolean_flag(
*,
this_will: str,
deprecated: bool = False,
default: bool = False,
) -> bool:
"""Load a boolean flag from environment variable.

Args:
name: The name of the environment variable.
this_will: A string that describes what this flag will do.
deprecated: Whether this flag is deprecated.
default: The default value if envvar not defined.
"""
undefined = os.getenv(name) is None
state = os.getenv(name) == "1"
if state:
if deprecated:
Expand All @@ -32,6 +35,8 @@ def _load_boolean_flag(
)
else:
logger.warning("Experimental flag %s is enabled. This will %s.", name, this_will)
if undefined:
state = default
return state


Expand All @@ -42,6 +47,7 @@ def _load_boolean_flag(
EXPERIMENTAL_PREFER_TRACING: bool = _load_boolean_flag(
"TORCHLIB_EXPERIMENTAL_PREFER_TRACING",
this_will="trace all traceable functions to fold if branches and collapse constant expressions",
default=True,
)
EXPERIMENTAL_USE_IR: bool = _load_boolean_flag(
"TORCHLIB_EXPERIMENTAL_USE_IR",
Expand Down
Loading