NamedTuple: Allow side effects for dynamic attributes#161645
NamedTuple: Allow side effects for dynamic attributes#161645morrison-turnansky wants to merge 16 commits intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/161645
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 7068799 with merge base 6737e2c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
There was a problem hiding this comment.
If supporting NamedTuple creation inside the compiled frame and then returning is hard, we can do a graph break and not support it in this PR.
Let me know - this PR is little more complicated than I anticipated because most of the code around tuples is written with immutability in mind, and named tuple creation in CPython is not a standard process (CPython generates some string, and then eval it on the fly), so using a UserDefinedObjectVariable is also not readily available.
|
If these changes are close to what you wanted, I am good to keep going. Otherwise, we can introduce a graph break. |
anijain2305
left a comment
There was a problem hiding this comment.
Very close to be done. Thanks for sending the PR.
b81dfd5 to
fed34a7
Compare
…ned variable call function. raised exception for converting dynamic attribute of named tuple variable to python constant when variable does not have to python constant method
a37a275 to
e9b7abd
Compare
|
Trigger the CI workflows. |
|
@anijain2305 Please review and/or resolve requested change. |
|
Looks great, merging, thank you! |
|
@pytorchbot merge |
|
This PR has pending changes requested. Please address the comments and update the PR before merging. |
|
@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 |
I confirmed that the tracing was correct i.e. NamedTupleVariable had the correct dynamic attribute added to it. The problem was that NamedTupleVariable was always marked as immutable. This does not reflect the behavior of namedtuple. Subclasses of namedtuple may be mutable, so when a NamedTupleVariable is derived from a subclass that is mutable, I made NamedTupleVariable mutable as well. Then side_effects correctly updates the returned object. Fixes pytorch#161610 Pull Request resolved: pytorch#161645 Approved by: https://github.com/anijain2305, https://github.com/StrongerXi
I confirmed that the tracing was correct i.e. NamedTupleVariable had the correct dynamic attribute added to it. The problem was that NamedTupleVariable was always marked as immutable. This does not reflect the behavior of namedtuple. Subclasses of namedtuple may be mutable, so when a NamedTupleVariable is derived from a subclass that is mutable, I made NamedTupleVariable mutable as well. Then side_effects correctly updates the returned object. Fixes pytorch#161610 Pull Request resolved: pytorch#161645 Approved by: https://github.com/anijain2305, https://github.com/StrongerXi
I confirmed that the tracing was correct i.e. NamedTupleVariable had the correct dynamic attribute added to it. The problem was that NamedTupleVariable was always marked as immutable. This does not reflect the behavior of namedtuple. Subclasses of namedtuple may be mutable, so when a NamedTupleVariable is derived from a subclass that is mutable, I made NamedTupleVariable mutable as well. Then side_effects correctly updates the returned object. Fixes pytorch#161610 Pull Request resolved: pytorch#161645 Approved by: https://github.com/anijain2305, https://github.com/StrongerXi
I confirmed that the tracing was correct i.e. NamedTupleVariable had the correct dynamic attribute added to it. The problem was that NamedTupleVariable was always marked as immutable. This does not reflect the behavior of namedtuple. Subclasses of namedtuple may be mutable, so when a NamedTupleVariable is derived from a subclass that is mutable, I made NamedTupleVariable mutable as well. Then side_effects correctly updates the returned object. Fixes pytorch#161610 Pull Request resolved: pytorch#161645 Approved by: https://github.com/anijain2305, https://github.com/StrongerXi
…Variable (#167468) Continuation of work from previous PR, see link for context #161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: #167468 Approved by: https://github.com/guilhermeleobas, https://github.com/StrongerXi, https://github.com/mlazos
…Variable (#167468) Continuation of work from previous PR, see link for context #161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: #167468 Approved by: https://github.com/guilhermeleobas, https://github.com/StrongerXi, https://github.com/mlazos
…Variable (#167468) Continuation of work from previous PR, see link for context #161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: #167468 Approved by: https://github.com/guilhermeleobas, https://github.com/Lucaskabela
…Variable (pytorch#167468) Continuation of work from previous PR, see link for context pytorch#161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: pytorch#167468 Approved by: https://github.com/guilhermeleobas, https://github.com/Lucaskabela
…Variable (pytorch#167468) Continuation of work from previous PR, see link for context pytorch#161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: pytorch#167468 Approved by: https://github.com/guilhermeleobas, https://github.com/Lucaskabela
…Variable (#167468) Continuation of work from previous PR, see link for context #161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: #167468 Approved by: https://github.com/Lucaskabela
…Variable (pytorch#167468) Continuation of work from previous PR, see link for context pytorch#161645 (comment) I think this PR is a step in that direction. There is probably some room for simplification. At a high level, the new class NamedTupleVariable handles methods that branch on structseq or the more dynamic subclasses of namedtuple, and falls back to UserDefinedTupleVariable otherwise. Please let me know what you think. @StrongerXi Pull Request resolved: pytorch#167468 Approved by: https://github.com/Lucaskabela
I confirmed that the tracing was correct i.e. NamedTupleVariable had the correct dynamic attribute added to it.
The problem was that NamedTupleVariable was always marked as immutable. This does not reflect the behavior of namedtuple.
Subclasses of namedtuple may be mutable, so when a NamedTupleVariable is derived from a subclass that is mutable, I made NamedTupleVariable mutable as well. Then side_effects correctly updates the returned object.
Fixes #161610
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @Lucaskabela