-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[dynamo] Fix error when inlining certain nested closure returned by another function #137510
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/137510
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c788357 with merge base 4aed81c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
21301cc
to
cf9336c
Compare
1 line fix, in |
Rebasing to fix failure from another reverted PR #137447. |
…nother function See #136814 for more context. In #90286, we introduced an optimization so that for captured cells that are unmodified during a Dynamo trace, `UserFunctionVariable` will represent them as variable of the cell's actual value, rather than a `NewCellVariable`. Later on we introduced more mechanisms to model such cells across function calls (#104222), and across function calls where `NestedUserFunctionVariable::bind_args` need to look up further in the parent frames (#106491) to find these cells' values. This patch removes `InlinedClosureVariable` in favor of a simpler modelling which is also more consistent with what was introduced in #90286, i.e., just model these cells as their contents, in `symbolic_locals`. This fixes #136814 because resolution of `InlinedClosureVariable` to the underlying cell content value happens in `NestedUserFunctionVariable::bind_args`, which requires Dynamo to have the value in scope at the function call site (when Dynamo starts inlining), but's not always the case (as the test case shows). However, if we model the cells in `symbolic_locals`, we never need such resolution, and the values are directly stored into the `NestedUserFunctionVariable::closure` upon the function creation, at which point Dynamo always has the cell value in `symbolic_locals` for look up. Fixes #136814.
cf9336c
to
c788357
Compare
@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 |
See
test_inline_closure_returned_by_another_function_and_captures
and #136814 for more context.In #90286, we introduced an optimization so that for captured cells that are unmodified during a Dynamo trace,
UserFunctionVariable
will represent them as variable of the cell's actual value, rather than aNewCellVariable
.Later on we introduced more mechanisms to model such cells across function calls (#104222), and across function calls where
NestedUserFunctionVariable::bind_args
need to look up further in the parent frames (#106491) to find these cells' values.This patch removes
InlinedClosureVariable
in favor of a simpler modelling, which is also more consistent with what was introduced in #90286, i.e., just model these cells as their contents, insymbolic_locals
.This fixes #136814 because resolution of
InlinedClosureVariable
to the underlying cell content value happens inNestedUserFunctionVariable::bind_args
, which requires Dynamo to have the value in scope at the function call site (when Dynamo does inlining), but's not always the case (as the test case shows). However, if we model the cells insymbolic_locals
, we never need such resolution, and the values are directly stored into theNestedUserFunctionVariable::closure
upon the function creation, at which point Dynamo always has the cell value insymbolic_locals
for look up.Fixes #136814.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @rec