pytorch/torch/_dynamo/variables
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
..
__init__.py [user-streams] Move StreamContextVariable into streams module (#164343) 2025-10-29 02:49:54 +00:00
base.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
builder.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
builtin.py [dynamo] Implement iter with a polyfill (#162768) 2025-10-29 21:54:37 +00:00
constant.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
ctx_manager.py [user-streams] Move StreamContextVariable into streams module (#164343) 2025-10-29 02:49:54 +00:00
dicts.py [3/N] fix typo in other folders (#166606) 2025-10-30 10:30:40 +00:00
distributed.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
functions.py [dynamo] Move more FUNCTION_MATCH to CLOSURE_MATCH (#166444) 2025-10-28 23:19:42 +00:00
higher_order_ops.py [pytree] add treespec_{leaf,tuple,dict} functions for args_spec modification (#160843) 2025-11-01 04:12:11 +00:00
iter.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
lazy.py Fix pyrefly ignores 1/n (#166239) 2025-10-26 00:44:10 +00:00
lists.py [dynamo] Fix ListIterator tracking mutations to original list (#166350) 2025-10-29 21:54:37 +00:00
misc.py [dynamo] support tracing new typing union syntax X | Y (#166599) 2025-10-30 23:59:27 +00:00
nn_module.py [dynamo] Add __iter__ for iterable VariableTrackers (#166349) 2025-10-29 21:54:37 +00:00
optimizer.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
script_object.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
sdpa.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
streams.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
tensor.py [dynamo] Add __iter__ for iterable VariableTrackers (#166349) 2025-10-29 21:54:37 +00:00
torch_function.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
torch.py [BE][Typing][Dynamo] Type misc files in torch/_dynamo/variables/ (#166569) 2025-10-31 20:42:27 +00:00
user_defined.py Revert "[user-streams] Fix stream graph output semantics (#164819)" 2025-10-30 16:53:32 +00:00