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
Make torch._dynamo
lazy-importable
#104368
Conversation
Use https://peps.python.org/pep-0562 to import `_dynamo` and `_inductor` only when needed. Remove redundant imports from tests
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104368
Note: Links to docs will display an error until the docs builds have been completed. ✅ 1 Unrelated FailureAs of commit 8578509: UNSTABLE - The following job failed but was likely due to flakiness present on trunk and has been marked as unstable:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Thank you!
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.
Very cool!
We should even still be able to test that it does not get eagerly imported.
@pytorchbot 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 |
This fixes the bug in profiler code exposed by #104368 that introduced on the fact that `import torch._dynamo` also imports `torch._inductor.config`: ``` $ python -c "import torch._inductor;print(torch._inductor.config)" Traceback (most recent call last): File "<string>", line 1, in <module> AttributeError: module 'torch._inductor' has no attribute 'config' (base) $ python -c "import torch._dynamo;print(torch._inductor.config)" <module 'torch._inductor.config' from '/home/nshulga/git/pytorch/pytorch/torch/_inductor/config.py'> ``` ### Testing D47159397 Pull Request resolved: #104477 Approved by: https://github.com/aaronenyeshi, https://github.com/malfet
Use PEP-562 to import
_dynamo
and_inductor
only when needed.test_lazy_imports_are_lazy
to make sure they will not get imported by accident🤖 Generated by Copilot at bae8e90
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @anijain2305