-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Add dynamo config to HOP-ify context managers #152159
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
Open
soulitzer
wants to merge
8
commits into
gh/soulitzer/359/base
Choose a base branch
from
gh/soulitzer/359/head
base: gh/soulitzer/359/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+458
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/152159
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 7c77df3 with merge base e2c7ae5 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
See large code comment for details TODO: - tests cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
``` # Note [Hopifying Context Managers] # # If the context manager class has been added to a opt-in dynamo config, # we will convert it into a generic context manager HOP. When the # HOP is later called in AOTAutograd, it will run the captured # graph under the ctx. # # How does this work? # - On enter: # - Enter into a new subtracer # - The subtracer traces the body of the context manager into a graph # - On exit: # - Exit the subtracer # - Grab the inner fx graph from the subtracer and install it onto # the outer fx graph # - Create node on the outer fx graph that calls this subgraph # # Some notes: # # 1. Determining the inputs and outputs # # One trickiness here is that a HOP requires a function as input, # but, unlike functions, context managers don't have explicit inputs and # outputs. For inputs, we rely on lifted_freevars, which the subtracer # already tracks for ordinary HOPs. For outputs, ideally we might only # return the outputs that are referenceable later, e.g. not temporaries, # but doing that is hard, so instead we just return all intermediates # and rely on AOTAutograd to trace through the HOP and DCE any # unnecessary ops. # # 2. Fixing VariableTracker proxies # # Inserting the call to the subgraph into the outer fx graph creates # fresh variable trackers and proxies, but the instruction translator # still refers the original VTs, e.g. in its symbolic locals and these # VTs still hold the inner fx graph's proxies, which is wrong. # # We fix this by updating the VTs to hold the new outer fx graph # proxies (e.g. corresponding to the getitems of the call to the # subgraph). To know what those VTs are, we maintain a mapping from # fx graph node name to the VTs which is updated everytime a new # TensorVariable is created. ``` From discussion in HOP meeting: - Why do we need to put the body of the ctx in a HOP? Why not just insert two nodes into the graph? - There are pregrad passes and we don't want to match across the boundary - Could there be issues for caching? - Yes, we store the args to reconstruct a ctx onto the GraphModule, but those args aren't necessarily hashable. In this PR we limit to allowing only constants args, though we leave an exception for AC to pass in policy_fn (we'll deal with that later). cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
From discussion in HOP meeting:
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames