mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Use `TORCH_ONNX_ENABLE_DRAFT_EXPORT` to control whether draft_export should be used as a strategy in onnx export. Follow up of https://github.com/pytorch/pytorch/pull/161454 Pull Request resolved: https://github.com/pytorch/pytorch/pull/162225 Approved by: https://github.com/xadupre, https://github.com/titaiwangms
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""Internal feature flags for torch.onnx.
|
|
|
|
NOTE: These flags are experimental only. Any flag here can be removed at any
|
|
time without notice.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _load_boolean_flag(
|
|
name: str,
|
|
*,
|
|
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:
|
|
logger.error(
|
|
"Experimental flag %s is deprecated. Please remove it from your environment.",
|
|
name,
|
|
)
|
|
else:
|
|
logger.warning(
|
|
"Experimental flag %s is enabled. This will %s.", name, this_will
|
|
)
|
|
if undefined:
|
|
state = default
|
|
return state
|
|
|
|
|
|
ENABLE_DRAFT_EXPORT: bool = _load_boolean_flag(
|
|
"TORCH_ONNX_ENABLE_DRAFT_EXPORT",
|
|
this_will="enable torch.export.draft_export as a strategy for capturing models",
|
|
default=False,
|
|
)
|