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

[dtensor] skip pytree when not necessary #110132

Closed
wants to merge 7 commits into from

Conversation

wanchaol
Copy link
Contributor

@wanchaol wanchaol commented Sep 27, 2023

Stack from ghstack (oldest at bottom):

pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:

  • exposes non-trival CPU overhead
  • many ops don't need pytree, only the one with list/dict ops needs
  • blindly use pytree to re-wrap have semantic issues for inplace/out
    ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Sep 27, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/110132

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 9be485d with merge base 40b83d9 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

wanchaol added a commit that referenced this pull request Sep 27, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: f35895d80052e81f37d539a6413e5da3d30378e8
Pull Request resolved: #110132
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: 72f3370dd99e467b9647655f825efa0c1b8d9d35
Pull Request resolved: #110132
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: d622e08c6218bb192d675bae2465cee7a6e0b4f8
Pull Request resolved: #110132
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: 2c399f73c2b056d5dd5e0db22e3a852fa2b14852
Pull Request resolved: #110132
Copy link
Contributor

@fduwjj fduwjj left a comment

Choose a reason for hiding this comment

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

LGTM, it's actually surprising to me that only two ops need treemap here..

pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: d506fdc7a843bc094e069316803001ab1abdb298
Pull Request resolved: #110132
@Chillee
Copy link
Contributor

Chillee commented Sep 28, 2023

Have you tried using optree?

pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: f2947786ac40ae350eb712fbf48c8c7b322fcac2
Pull Request resolved: #110132
@wanchaol
Copy link
Contributor Author

Have you tried using optree?

Oh just noticed that got landed!! I can try turn that on, is there a flag to turn it on?

My feeling is that even if that landed it would still have some overhead exposed (especially optree perf is most amazing on dicts, while operator arguments does not have too many dicts, maybe kwargs is a good try). This PR try to turn pytree/optree off completely for most ops which I thought it would be faster for either case?

@Chillee
Copy link
Contributor

Chillee commented Sep 28, 2023

@wanchaol might be a little bit annoying to actually land but the idea was that we would incrementally port usages over incrementally.

@wanchaol
Copy link
Contributor Author

@wanchaol might be a little bit annoying to actually land but the idea was that we would incrementally port usages over incrementally.

@Chillee sounds good, I'll give it a try in a follow up PR? the annoying part is that we need to guard the imports mostly so that all CI passes?

@Chillee
Copy link
Contributor

Chillee commented Sep 28, 2023

Yeah, see #109684

pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

[ghstack-poisoned]
wanchaol added a commit that referenced this pull request Sep 28, 2023
pytree is a great tool, but it sometimes considers to be evil for
tensor subclasses, it's useful to implement subclass quickly, but it:
* exposes non-trival CPU overhead
* many ops don't need pytree, only the one with list/dict ops needs
* blindly use pytree to re-wrap have semantic issues for inplace/out
ops

This PR avoid using pytree for most ops during torch_dispatch and only
enable it for certain ops

ghstack-source-id: dfddc15534ce75369e914b7875511d991b29e762
Pull Request resolved: #110132
@wanchaol wanchaol added ciflow/trunk Trigger trunk jobs on your pull request release notes: distributed (dtensor) release notes category labels Sep 28, 2023
@wanchaol
Copy link
Contributor Author

wanchaol commented Oct 2, 2023

@pytorchbot merge

@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

@facebook-github-bot facebook-github-bot deleted the gh/wanchaol/357/head branch October 6, 2023 14:23
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 release notes: distributed (dtensor) release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants