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
..
db Fix pyrefly ignore syntax (#166438) 2025-10-29 00:02:21 +00:00
pass_infra pyfmt lint more export files (#155783) 2025-06-12 23:04:11 +00:00
passes [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
serde [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
__init__.py [5/N] Apply ruff UP035 rule (#164423) 2025-10-02 07:31:11 +00:00
config.py Export should use aot_export_joint_with_descriptors (#165931) 2025-10-27 19:33:33 +00:00
converter.py [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
error.py
non_strict_utils.py Fix pyrefly ignore syntax (#166438) 2025-10-29 00:02:21 +00:00
pass_base.py [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
tools.py Fix flake8 B028 warnings (#166224) 2025-10-26 06:18:55 +00:00
utils.py [2/N] Use 'is' in callable comparisons (#166685) 2025-10-31 08:08:07 +00:00
verifier.py Support vmap + custom autograd function/improve DTensor constructor inefficiency (#162240) 2025-09-11 17:42:41 +00:00
wrappers.py Support vmap + custom autograd function/improve DTensor constructor inefficiency (#162240) 2025-09-11 17:42:41 +00:00