pytorch/torch/_dynamo/variables
Yidi Wu 741c1710e8 [cond] inlining into one of the branches when pred is a python constant (#130493)
Reland https://github.com/pytorch/pytorch/pull/128709.

When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants.

We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph.

Test Plan:
The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches,

Pull Request resolved: https://github.com/pytorch/pytorch/pull/130493
Approved by: https://github.com/BoyuanFeng
2024-07-12 18:02:09 +00:00
..
__init__.py [dynamo][unspecialized-nn-module] Distinguish between user-defined and builtin nn module (#130416) 2024-07-11 14:13:24 +00:00
base.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
builder.py [torchbind] add tracing_mode support (#129586) 2024-07-12 18:01:47 +00:00
builtin.py [easy][dynamo] Remove try except from call_getattr (#129217) 2024-06-21 23:56:00 +00:00
constant.py Fix #121334: graph break on constant method call (#130158) 2024-07-12 17:34:46 +00:00
ctx_manager.py [3.13, dynamo] codegen PUSH_NULL when callable is codegen'd (#129172) 2024-06-22 17:25:23 +00:00
dicts.py [dynamo][compile-time][inlining-inbuilt-nn-modules] Manually implement nn.Module._call_impl (#129285) 2024-06-25 01:31:26 +00:00
distributed.py support as_python_constant on PlacementClassVariable (#124398) 2024-05-01 21:56:01 +00:00
functions.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
higher_order_ops.py [cond] inlining into one of the branches when pred is a python constant (#130493) 2024-07-12 18:02:09 +00:00
iter.py [dynamo] Improve constant-prop for regex/torch.__version__ (#123705) 2024-04-12 19:03:13 +00:00
lazy.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
lists.py Add python type for list iterators (#130511) 2024-07-12 01:14:18 +00:00
misc.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
nn_module.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
optimizer.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00
script_object.py Flip default value for mypy disallow_untyped_defs [1/11] (#127838) 2024-06-08 18:16:33 +00:00
sdpa.py [3.13, dynamo] codegen PUSH_NULL when callable is codegen'd (#129172) 2024-06-22 17:25:23 +00:00
tensor.py [HOP] Use user directed names for variables where possible (#130271) 2024-07-10 13:59:20 +00:00
torch_function.py [Dynamo x torch_function] fix incorrect source (#128980) 2024-06-20 14:54:00 +00:00
torch.py [dynamo][dynamic-shapes] Graph break if out shape changes on out= variants (#130074) 2024-07-04 08:36:12 +00:00
user_defined.py [BE][Easy] apply autofix for ruff rules unnecessary-collection-call (C408): list() / tuple() / dict() (#130199) 2024-07-11 17:30:28 +00:00