-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental flag for controlling initializers as inputs | feat(torch…
…lib) (#1112) Create a flag `TORCHLIB_EXPERIMENTAL_INITIALIZERS_AS_INPUTS=1` to mark initializers as inputs to the model. **This flag is experimental only for ONNX Runtime training and should not be assumed to exist in production.** Reference: microsoft/onnx-converters-private#182 Tested with the open-llama model with `transformers==4.31.0` with script https://gist.github.com/abock/2115d34d98df15a77516e8a2899b121c ![image](https://github.com/microsoft/onnxscript/assets/11205048/fe2d565f-bd2f-449d-82ba-9f865b335177)
- Loading branch information
1 parent
67f790b
commit 754accc
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Experimental flags. | ||
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, | ||
) -> 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. | ||
""" | ||
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) | ||
return state | ||
|
||
|
||
EXPERIMENTAL_INITIALIZERS_AS_INPUTS: bool = _load_boolean_flag( | ||
"TORCHLIB_EXPERIMENTAL_INITIALIZERS_AS_INPUTS", | ||
this_will="make initializers as inputs to the model graph", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters