-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[pytree][Easy] preserve dict keys in insertion order in CXX pytree
#130140
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/130140
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c21880a with merge base 6a9a02a ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
dict keys in insertion order in CXX pytreedict keys in insertion order in CXX pytree
ghstack-source-id: e37db61 Pull Request resolved: pytorch#130140
ghstack-source-id: 813b328 Pull Request resolved: pytorch#130140
ghstack-source-id: 782fe2b Pull Request resolved: pytorch#130140
ghstack-source-id: 50a63f4 Pull Request resolved: pytorch#130140
| __TORCH_DICT_SESSION = optree.dict_insertion_ordered(True, namespace="torch") | ||
| __TORCH_DICT_SESSION.__enter__() # enable globally and permanently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @zou3519
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're sure about this. The fun thing is if someone imports torch cxx_pytree and uses optree then they will override the optree behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only affects optree functions that passed with namespace="torch".
|
@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 |
optreeand JAX pytree traversal thedictin sorted key ordering (see Key Ordering for Dictionaries). While in PyTorch Python pytree, we traversal thedictin insertion order. See also:dicts do not imply equal leaves and equal treespecs #114392This aligns the behavior of CXX pytree with Python pytree.
Stack from ghstack (oldest at bottom):
torch.utils.pytreeby default #138056torch.distributed#144332torch.func#137884torch.utils._pytree->torch.utils.pytree.python#144405torch.utils.pytree#137400dictkeys in insertion order in CXX pytree #130140cc @zou3519