-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add prepend argument to nn.Module hooks #87370
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/87370
Note: Links to docs will display an error until the docs builds have been completed. ✅ No Failures, 3 PendingAs of commit 510d0aa: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ghstack-source-id: e01b3bba5a6994c14f83d5d867637025a4b63a89 Pull Request resolved: #87370
[ghstack-poisoned]
ghstack-source-id: 64c9492f5bb1fe14fcab903973681f862d8914ce Pull Request resolved: #87370
[ghstack-poisoned]
ghstack-source-id: 6beebd38d8a924d3f4be00719170a100b9cfe700 Pull Request resolved: #87370
What is the exact use case for which you want this? cc @soulitzer related to hook ordering questions we were having. |
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 7fb74675c5964713a58e15847dc9104365e2f770 Pull Request resolved: #87370
We are working on converting some distributed features to hook-based solutions, so that we won't mess up FQNs as module wrapper did. To maintain the similar behavior as today DDP/FSDP, we plan to split their forward into top and bottom halves and install those as pre and post forward hooks. And the pre hook needs to be called before any existing hooks on the local module.
This should be OK for now, as we expect DDP logic is added after local model preparations. |
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 3ccbf150f92874aed50ff18166aba2b9e99dddf6 Pull Request resolved: #87370
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 96ad4992d503b23fce8f33902a9778e33cc97f4e Pull Request resolved: #87370
Sure, but I'm not sure how to convey that to the end user of this flag in the doc :p (btw docs need updating). |
For hooks in general it feels like provide guarantees about ordering is something we'd want to do as long as it doesn't complicate the implementation, so the idea sounds OK. For this case in particular though, communicating to the user about what "prepend" does can be tricky because hooks registered globally will still execute before those prepend, and I'm not sure we even document that anywhere currently? |
Hey @albanD @soulitzer, thanks a lot for the comments!
Would I be correct that global hooks are mainly for debugging/profiling purposes. Or have we seen cases where program relies on global hooks to produce correct results?
Any suggestions on which of the following might be better?
Edit: chatted with @albanD offline, since private args will still render in the doc, it's not really private. So let's avoid that. |
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: c2647f464f7fc189aa7baeea553f5875249a5767 Pull Request resolved: #87370
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: a882c6765f387e19de0be34928d43d3443558d57 Pull Request resolved: #87370
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 1b2f9416254cbaa5075f255fadc35248cf1cc22d Pull Request resolved: #87370
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 7f288d76ab80f6f0e8bf10063e2febd0fc9c79bd Pull Request resolved: #87370
Thanks for the updated documentation, looks great.
To explain the ordering of hooks fully, we may also want to think about the interaction of full_backward_pre_hooks with hooks registered to module outputs (but that might be out of the scope of this PR)
We might want to have some documentation regarding module hooks in general now, but that can be done in a follow up. |
cc ezyang gchanan [ghstack-poisoned]
This PR needs a labelIf your changes are user facing and intended to be a part of release notes, please use a label starting with If not, please add the For more information, see https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work. |
cc ezyang gchanan [ghstack-poisoned]
ghstack-source-id: 2c2800e1fa2ce7cec45590c2c63318ff167f6009 Pull Request resolved: pytorch#87370
@pytorchbot merge -g |
Merge startedYour change will be merged once all checks on your PR pass since you used the green (-g) flag (ETA: 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
cc @ezyang @gchanan Pull Request resolved: pytorch#87370 Approved by: https://github.com/soulitzer
cc @ezyang @gchanan Pull Request resolved: pytorch#87370 Approved by: https://github.com/soulitzer
cc @ezyang @gchanan Pull Request resolved: pytorch#87370 Approved by: https://github.com/soulitzer
Stack from ghstack (oldest at bottom):
cc @ezyang @gchanan