-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix permission error for ORTModule lock file #7814
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
Merged
Thiago Crepaldi (thiagocrepaldi)
merged 3 commits into
master
from
thiagofc/fallback-lock
May 26, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,27 +11,49 @@ | |
| ################################################################################ | ||
| ONNX_OPSET_VERSION = 12 | ||
| MINIMUM_TORCH_VERSION_STR = '1.8.1' | ||
| TORCH_CPP_BUILD_DIR = os.path.join(os.path.dirname(__file__),'torch_inline_extensions') | ||
|
|
||
| # Use one of the available directories as Torch CPP extension in the following order: | ||
| # 1) Path at listed at TORCH_EXTENSIONS_DIR environment variable | ||
| # 2) Default Python package dir | ||
| # 3) <Home directory>/.cache | ||
| home_dir = os.path.expanduser("~") | ||
| python_package_dir = os.path.dirname(__file__) | ||
| torch_extensions_dir = os.environ.get('TORCH_EXTENSIONS_DIR') | ||
|
|
||
| TORCH_CPP_BUILD_DIR = os.path.join(python_package_dir,'torch_inline_extensions') | ||
| TORCH_CPP_BUILD_DIR_BACKUP = os.path.join(home_dir, '.cache', 'torch_ort_extensions') | ||
|
|
||
| if torch_extensions_dir is not None and os.access(torch_extensions_dir, os.X_OK | os.W_OK): | ||
| TORCH_CPP_BUILD_DIR = torch_extensions_dir | ||
| elif not os.access(python_package_dir, os.X_OK | os.W_OK): | ||
| if os.access(home_dir, os.X_OK | os.W_OK): | ||
| TORCH_CPP_BUILD_DIR = TORCH_CPP_BUILD_DIR_BACKUP | ||
| else: | ||
| extra_message = '' | ||
| if torch_extensions_dir: | ||
| extra_message = 'or the path pointed by the TORCH_EXTENSIONS_DIR environment variable ' | ||
| raise PermissionError('ORTModule could not find a writable directory to cache its internal files.', | ||
|
thiagocrepaldi marked this conversation as resolved.
|
||
| f'Make {python_package_dir} or {home_dir} {extra_message}writable and try again.') | ||
|
|
||
| # Check whether Torch C++ extension compilation was aborted in previous runs | ||
| if not os.path.exists(TORCH_CPP_BUILD_DIR): | ||
| os.makedirs(TORCH_CPP_BUILD_DIR, exist_ok = True) | ||
| elif os.path.exists(os.path.join(TORCH_CPP_BUILD_DIR,'lock')): | ||
| print("WARNING: ORTModule detected PyTorch CPP extension's lock file during initialization, " | ||
| "which can cause unexpected hangs. " | ||
| f"Delete {os.path.join(TORCH_CPP_BUILD_DIR,'lock')} to prevent unexpected behavior.") | ||
| f"Delete {os.path.join(TORCH_CPP_BUILD_DIR,'lock')} if a hang occurs.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid using the word "hang" in our code. We can say it stops responding. |
||
|
|
||
| # Verify proper PyTorch is installed before proceding to ONNX Runtime initializetion | ||
| # Verify proper PyTorch is installed before proceding to ONNX Runtime initialization | ||
| try: | ||
| import torch | ||
| torch_version = version.parse(torch.__version__.split('+')[0]) | ||
| minimum_torch_version = version.parse(MINIMUM_TORCH_VERSION_STR) | ||
| if torch_version < minimum_torch_version: | ||
| raise RuntimeError( | ||
| f'ONNXRuntime ORTModule frontend requires PyTorch version greater or equal to {MINIMUM_TORCH_VERSION_STR}, ' | ||
| f'ONNX Runtime ORTModule frontend requires PyTorch version greater or equal to {MINIMUM_TORCH_VERSION_STR}, ' | ||
| f'but version {torch.__version__} was found instead.') | ||
| except: | ||
| raise(f'PyTorch {MINIMUM_TORCH_VERSION_STR} must be installed in order to run ONNXRuntime ORTModule frontend!') | ||
| raise(f'PyTorch {MINIMUM_TORCH_VERSION_STR} must be installed in order to run ONNX Runtime ORTModule frontend!') | ||
|
|
||
| # ORTModule must be loaded only after all validation passes | ||
| from .ortmodule import ORTModule | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.