-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[Dynamo][Better Engineering] Type coverage for torch/_dynamo/utils.py
#159580
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/159580
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 1187733 with merge base 2a286cb ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
torch/_dynamo/utils.py
1eb77e6 to
a6dc480
Compare
d58c817 to
1187733
Compare
|
@pytorchmergebot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Skylion007
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits about these types
| code_options: dict[str, Any] = field(default_factory=dict) | ||
|
|
||
| def dump(self, f: IO[str]) -> None: | ||
| def dump(self, f: Union[IO[str], BufferedWriter]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, bufferedWriter doesn't necessarily subclass this? This is an fsspec bug, isn't it. :(
| code_options: dict[str, Any] = field(default_factory=dict) | ||
|
|
||
| def dump(self, f: IO[str]) -> None: | ||
| def dump(self, f: Union[IO[str], BufferedWriter]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, bufferedWriter doesn't necessarily subclass this? This is an fsspec bug, isn't it. :(
|
|
||
|
|
||
| def hashable(x): | ||
| def hashable(x: Any) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a typing_extension.TypeIs[Hashable] as return type. Also this is very antiquated, you can use the abc protocol for this now, can't you?
|
|
||
|
|
||
| def is_numpy_float_type(value): | ||
| def is_numpy_float_type(value: Any) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be TypeIs/Typeguard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These numpy types may be undefined unfortunately if the import fails, so I am not sure how to use them as type annotations in this event :/
|
|
||
|
|
||
| def is_numpy_int_type(value): | ||
| def is_numpy_int_type(value: Any) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Allows type narrowing
| return fn(*args, **kwargs) | ||
|
|
||
|
|
||
| def is_utils_checkpoint(obj): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be TypeIs return type with TypeChecking block to avoid circular import
|
@Lucaskabela Feel free to do a subsequent PR to further improve these |
|
@Skylion007 thanks for the feedback! I will follow up shortly with improvements :) Honestly before these comments I was not very familiar with TypeIs/TypeGuard for narrowing so thank you for bringing these to my attention! |
Summary: As part of better engineering effort, we would like to improve out type support to improve dev experience in dynamo This PR adds strict typing support to `torch/_dynamo/utils.py` Running ``` mypy torch/_dynamo/utils.py --linecount-report /tmp/coverage_log ``` | -------- | Lines Annotated | Lines Total | % lines covered | Funcs Annotated | Funcs Total | % funcs covered | | -------- | ------- | -------- | ------- | ------- | ------- | ------- | | Main | 2163 | 4792 | 45.14% | 121 | 268 | 45.15% | | This PR | 4818 | 4818 | 100.00% | 268 | 268 | 100.00% | | Delta | +2655 | +26 | +54.84% | +147 | 0 | +54.85% | X-link: pytorch/pytorch#159580 Approved by: https://github.com/williamwen42 Reviewed By: izaitsevfb Differential Revision: D79597355 fbshipit-source-id: 5bb7a21d68ef3c24659c5a79e148caeb9219a11f
Follow up to #159580 Pull Request resolved: #159824 Approved by: https://github.com/williamwen42
Follow up to #159580 Pull Request resolved: #159824 Approved by: https://github.com/williamwen42
Follow up to #159580 Pull Request resolved: #159824 Approved by: https://github.com/williamwen42
Follow up to #159580 Pull Request resolved: #159824 Approved by: https://github.com/williamwen42
…h#159824) Follow up to pytorch#159580 Pull Request resolved: pytorch#159824 Approved by: https://github.com/williamwen42
…h#159824) Follow up to pytorch#159580 Pull Request resolved: pytorch#159824 Approved by: https://github.com/williamwen42
…y` (pytorch#159580) As part of better engineering effort, we would like to improve out type support to improve dev experience in dynamo This PR adds strict typing support to `torch/_dynamo/utils.py` Running ``` mypy torch/_dynamo/utils.py --linecount-report /tmp/coverage_log ``` | -------- | Lines Annotated | Lines Total | % lines covered | Funcs Annotated | Funcs Total | % funcs covered | | -------- | ------- | -------- | ------- | ------- | ------- | ------- | | Main | 2163 | 4792 | 45.14% | 121 | 268 | 45.15% | | This PR | 4818 | 4818 | 100.00% | 268 | 268 | 100.00% | | Delta | +2655 | +26 | +54.84% | +147 | 0 | +54.85% | Pull Request resolved: pytorch#159580 Approved by: https://github.com/williamwen42
…h#159824) Follow up to pytorch#159580 Pull Request resolved: pytorch#159824 Approved by: https://github.com/williamwen42
…h#159824) Follow up to pytorch#159580 Pull Request resolved: pytorch#159824 Approved by: https://github.com/williamwen42
As part of better engineering effort, we would like to improve out type support to improve dev experience in dynamo
This PR adds strict typing support to
torch/_dynamo/utils.pyRunning
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames