pytorch/torch/_functorch
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
..
_activation_checkpointing [5/N] Apply ruff UP035 rule (#164423) 2025-10-02 07:31:11 +00:00
_aot_autograd [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
__init__.py
aot_autograd.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
apis.py [BE][PYFMT] migrate PYFMT for torch/_[a-h]*/ to ruff format (#144551) 2025-06-25 06:16:06 +00:00
autograd_function.py Fix pyrefly ignore syntax (#166438) 2025-10-29 00:02:21 +00:00
batch_norm_replacement.py
benchmark_utils.py [BE][PYFMT] migrate PYFMT for torch/_[a-h]*/ to ruff format (#144551) 2025-06-25 06:16:06 +00:00
compile_utils.py [3/N] fix typo in other folders (#166606) 2025-10-30 10:30:40 +00:00
compilers.py [1/N] Use "is" in python type comparison (#165037) 2025-10-10 12:36:50 +00:00
config.py [3/N] fix typo in other folders (#166606) 2025-10-30 10:30:40 +00:00
deprecated.py [5/N] Apply ruff UP035 rule (#164423) 2025-10-02 07:31:11 +00:00
eager_transforms.py [5/N] Apply ruff UP035 rule (#164423) 2025-10-02 07:31:11 +00:00
functional_call.py [2/N] Use "is" in python type comparison (#165142) 2025-10-10 15:36:44 +00:00
fx_minifier.py [5/N] Apply ruff UP035 rule (#164423) 2025-10-02 07:31:11 +00:00
make_functional.py Fix pyrefly ignore syntax (#166438) 2025-10-29 00:02:21 +00:00
partitioners.py partitioner option to ignore partitioner_tag for abstract usage (#166725) 2025-10-31 18:50:02 +00:00
predispatch.py [scan x vmap] support scan in vmap (#165580) 2025-10-22 09:46:00 +00:00
pyfunctorch.py [1/N] Remove unused loop variables (#166258) 2025-10-30 12:22:25 +00:00
python_key.py
pytree_hacks.py
top_operators_github_usage.py [BE][PYFMT] migrate PYFMT for torch/_[a-h]*/ to ruff format (#144551) 2025-06-25 06:16:06 +00:00
utils.py PEP585 update - torch/_functorch (#145139) 2025-01-19 07:06:10 +00:00
vmap.py Fix self assignment (#165816) 2025-10-18 18:51:52 +00:00