pytorch/torch/ao
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
..
nn Fix pyrelfy ignore syntax in distributions and ao (#166248) 2025-10-26 22:13:48 +00:00
ns Use 'is' in callable comparisons (#166624) 2025-10-30 19:00:09 +00:00
pruning [ao][pruning] Replace assert statements with AssertionError exceptions (#164926) 2025-10-29 17:46:46 +00:00
quantization [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
__init__.py [BE][Easy] improve submodule discovery for torch.ao type annotations (#144680) 2025-01-13 17:16:19 +00:00