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

Make torch._dynamo lazy-importable #104368

Closed
wants to merge 3 commits into from
Closed

Conversation

malfet
Copy link
Contributor

@malfet malfet commented Jun 28, 2023

Use PEP-562 to import _dynamo and _inductor only when needed.

  • Remove redundant imports from tests
  • Add test_lazy_imports_are_lazy to make sure they will not get imported by accident

🤖 Generated by Copilot at bae8e90

Sing, O Muse, of the daring deeds of PyTorch, the swift and fiery
framework of deep learning, that with skill and cunning wrought
many wonders of dynamic compilation, using the hidden powers
of _dynamo and _inductor, the secret modules of LLVM and MLIR.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @anijain2305

Use https://peps.python.org/pep-0562 to import `_dynamo` and `_inductor` only when needed.

Remove redundant imports from tests
@pytorch-bot
Copy link

pytorch-bot bot commented Jun 28, 2023

🔗 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 Failure

As 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.

@malfet malfet requested review from albanD and jansel and removed request for albanD June 28, 2023 19:38
@malfet malfet added release notes: python_frontend release notes category topic: improvements topic category labels Jun 28, 2023
@malfet malfet requested a review from albanD June 28, 2023 19:40
@msaroufim msaroufim self-requested a review June 28, 2023 19:43
Copy link
Member

@msaroufim msaroufim left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Collaborator

@albanD albanD left a 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.

@malfet
Copy link
Contributor Author

malfet commented Jun 28, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 28, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Jul 1, 2023
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
@malfet malfet deleted the malfet/add-lazy-imporpt-of-dynamo branch January 20, 2024 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo module: inductor release notes: python_frontend release notes category topic: improvements topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants