pytorch/torch/_dynamo/variables
Tom Ritchford e1c4548441 [dynamo] Simplify creation of VariableTrackers (#135714)
## `VariableTracker::build()` hides the Builders

### The problem

In the current code, creating a `VariableTracker` involves choosing one of two `Builder` classes and either calling a method, or calling a constructor that creates an object that you immediately call, [like this](083c9149b7/torch/_dynamo/variables/functions.py (L761-L768)).

Variations on this code are repeated in many places.

More, the `Builder` classes have a lot of dependencies, so they have to be loaded late in the whole import process to avoid circular imports, so they end up being repeatedly imported at local scope.

### The solution

In this commit, the import from `builder` and the logic of choosing and calling the Builder class are hidden in a single static factory method, `VariableTracker.build()`, easier to reason about and to import.

This commit net lowers the total lines of code by over 150 lines by removing repetitive logic and unnecessary local imports.

**CHANGES:** Originally the name of the static method was `VariableTracker.create()` but a static method on a derived class, `LazyVariableTracker.create()` now exists with a different signature that's irreconcilable, so the new static method was renamed to `VariableTracker.build()`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/135714
Approved by: https://github.com/jansel
2024-10-18 09:36:46 +00:00
..
__init__.py Add host-side Triton TMA support to Dynamo (#137677) 2024-10-16 02:18:48 +00:00
base.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
builder.py Add host-side Triton TMA support to Dynamo (#137677) 2024-10-16 02:18:48 +00:00
builtin.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
constant.py [dynamo] Fix support for classmethod(property(...)) (#134968) 2024-09-18 04:47:51 +00:00
ctx_manager.py [Dynamo] Trace enter/exit of TorchFunctionModes (#135422) (#137114) 2024-10-09 02:29:40 +00:00
dicts.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
distributed.py Revert "[compiled autograd] Compiled autograd configs in TLS (#137821)" 2024-10-16 16:38:29 +00:00
functions.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
higher_order_ops.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
iter.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
lazy.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
lists.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
misc.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
nn_module.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
optimizer.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
script_object.py Add basic mypy annotations to dynamo (#132415) 2024-08-04 18:43:36 +00:00
sdpa.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
tensor.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
torch_function.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
torch.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00
user_defined.py [dynamo] Simplify creation of VariableTrackers (#135714) 2024-10-18 09:36:46 +00:00