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

feat: Add decorator utility to improve error messaging for legacy support #1738

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

gs-olive
Copy link
Collaborator

Description

  • Add general-purpose utility for intercepting invalid Torch version imports and displaying an error message to the user, halting compilation
  • Decorator can accept variable input versions and checks whether the current version in use in the environment is at least as large as the minimum specified version
  • Display clear error message upon calling the aten tracer when using a legacy Torch version, for which the Dynamo import is invalid

Fixes #1733

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • [ x ] My code follows the style guidelines of this project (You can use the linters)
  • [ x ] I have performed a self-review of my own code
  • [ x ] I have commented my code, particularly in hard-to-understand areas and hacks
  • [ x ] I have made corresponding changes to the documentation
  • [ x ] I have added tests to verify my fix or my feature
    • Manually tested - remainder is covered via CI
  • [ x ] New and existing unit tests pass locally with my changes
  • [ x ] I have added the relevant labels to my PR in so that relevant reviewers are notified

py/torch_tensorrt/fx/passes/pass_utils.py Outdated Show resolved Hide resolved
py/torch_tensorrt/fx/passes/pass_utils.py Outdated Show resolved Hide resolved
py/torch_tensorrt/fx/passes/pass_utils.py Outdated Show resolved Hide resolved
@gs-olive gs-olive force-pushed the function_decorator branch 2 times, most recently from 80d52fe to 1b03650 Compare March 15, 2023 21:21
Comment on lines +131 to +134
raise AssertionError(
f"Expected Torch version {min_torch_version} or greater, "
+ f"when calling {f}. Detected version {torch.__version__}"
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function f is printed in the error message, which includes its name.

- Add general-purpose utility for intercepting invalid Torch version
imports and displaying an error message to the user, halting compilation
- Utility automatically parses string inputs to semantic versions using
the `packaging` utility package
- Decorator can accept variable input versions and checks whether the
current version in use in the environment is at least as large as the
minimum specified version
- Display clear error message upon calling the aten tracer when using a
legacy Torch version, for which the Dynamo import is invalid
@@ -104,3 +105,36 @@ def f(*inp):
mod = run_const_fold(mod)
mod = replace_op_with_indices(mod)
return mod


def req_torch_version(min_torch_version: str = "2.dev"):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Default is "2.dev" since "2.0" is considered to be a larger version than "2.0.0.dev____".

Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

Lgtm

@gs-olive gs-olive merged commit 497d8ac into pytorch:main Mar 17, 2023
@gs-olive gs-olive deleted the function_decorator branch March 17, 2023 19:00
@gs-olive gs-olive restored the function_decorator branch March 17, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨[Feature] Create Decorator for Python functions Incompatible with Legacy Torch Versions
3 participants