Closed XuehaiPan closed 1 year ago
After some benchmarking (3-way multi-treemap in benchmark.py
), it got ~45% performance regression with the set
-based approach and ~25% with the sort
-based approach.
Other than sorting the keys, we can check the key equality by iterating over the keys and calling PyDict_Contains
.
Required prerequisites
Motivation
The tree-map function uses a
treespec.flatten_up_to
to deal with the multi-input scenario. Theflatten_up_to
method requires the incoming pytree to have the exact same type and metadata as thetreespec
. For convenience, users may want to mapOrderedDict
withdict
, or vice versa. Thetree_map
function will raise a error:NOTE: this feature is not backward compatible.
Solution
Reimplement the
PyTreeSpec::FlattenUpTo
method. Useset
equality and ignore the key orders.Alternatives
No response
Additional context
No response