[pytree][Easy] preserve dict keys in insertion order in CXX pytree#130140
[pytree][Easy] preserve dict keys in insertion order in CXX pytree#130140XuehaiPan wants to merge 102 commits into
dict keys in insertion order in CXX pytree#130140Conversation
🔗 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. |
| __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.
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.
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