pytorch/torch/export
Xuehai Pan e8fadba28c [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843)
The goal of this PR is to provide a standard way to create simple treespec instances and hide the implementation details of the `PyTreeSpec` class.

Changes:

1. Add function `treespec_leaf()` to replace `LeafSpec()`.
2. Add function `treespec_tuple(...)` and `treespec_dict(...)` to create treespec for `tuple` / `dict` which is used for `*args` / `**kwargs`. This avoids direct modification to `treespec` instances that rely on the implementation details of the `PyTreeSpec` class.
3. Change `len(spec.children_specs)` to `spec.num_children`.
4. Change `isinstance(spec, LeafSpec)` to `spec.is_leaf()`.

------

Pull Request resolved: https://github.com/pytorch/pytorch/pull/160843
Approved by: https://github.com/mlazos
2025-11-01 04:12:11 +00:00
..
experimental [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
passes Use 'is' in callable comparisons (#166624) 2025-10-30 19:00:09 +00:00
pt2_archive Fix pyrefly error syntax (2/n) (#166448) 2025-10-29 00:36:40 +00:00
__init__.py Fix flake8 B028 warnings (#166224) 2025-10-26 06:18:55 +00:00
_draft_export.py Fix pyrefly error syntax (2/n) (#166448) 2025-10-29 00:36:40 +00:00
_leakage_detection_utils.py More ruff SIM fixes (#164695) 2025-10-09 03:24:50 +00:00
_remove_auto_functionalized_pass.py Use 'is' in callable comparisons (#166624) 2025-10-30 19:00:09 +00:00
_remove_effect_tokens_pass.py [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
_safeguard.py
_swap.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
_trace.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
_tree_utils.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
_unlift.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
_wrapper_utils.py [reland] Make export._trace._WrapperModule work in strict mode (#146919) (#151264) 2025-04-15 18:35:34 +00:00
custom_obj.py
custom_ops.py Support vmap + custom autograd function/improve DTensor constructor inefficiency (#162240) 2025-09-11 17:42:41 +00:00
decomp_utils.py Back out "Do not decompose in functionalization/proxy tensor if autograd wouldn't have decomposed (#164939)" (#165910) 2025-10-21 16:36:38 +00:00
dynamic_shapes.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
exported_program.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
graph_signature.py Add support for param mutation under inference mode (#159661) 2025-08-14 03:34:04 +00:00
unflatten.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00