metaopt / optree

OpTree: Optimized PyTree Utilities
https://optree.readthedocs.io
Apache License 2.0
136 stars 6 forks source link

[Feature Request] Add constructors to create `PyTreeSpec` instances on Python side #118

Closed XuehaiPan closed 8 months ago

XuehaiPan commented 8 months ago

Required prerequisites

Motivation

Currently, we can only create PyTreeSpec instances via optree.tree_flatten(...), optree.tree_structure(...), or similar APIs. It requires the user to get a pytree first and then flatten it.

Now we only have:

functions to create PyTreeSpec instances via its children treespecs. Some primitive Python types (e.g., list, dict) are not supported yet.

Solution

Add more constructor functions, e.g.:

Alternatives

No response

Additional context

No response