Repository: pytorch
Issue: [dynamic-shapes][dynamo] Iist index out of range for constraint with out=
Labels: triaged,oncall: pt2,module: dynamic shapes,module: dynamo

Repro

~~~
import torch

def fn(a, b, c):
    torch.add(a, b, out=c)
    return c

opt_fn = torch.compile(fn, backend="eager")
# opt_fn = fn

print(opt_fn(torch.ones(3, 3), torch.ones(3, 3), torch.empty(0)))
# print(opt_fn(torch.ones(4, 4), torch.ones(4, 4), torch.empty(0)))
~~~

~~~
I0703 15:36:46.875000 140292637426816 torch/fx/experimental/symbolic_shapes.py:3671] [0/0] produce_guards
V0703 15:36:46.876000 140292637426816 torch/fx/experimental/symbolic_shapes.py:3853] [0/0] track_symint L['c'].size()[0] 3 None
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0] Error while creating guard:
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0] Name: ''
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Source: shape_env
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Create Function: SHAPE_ENV
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Guard Types: None
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Code List: None
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Object Weakref: None
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     Guarded Class Weakref: None
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0] Traceback (most recent call last):
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]   File "/data/users/anijain/pytorch/torch/_guards.py", line 259, in create
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     return self.create_fn(builder, self)
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]   File "/data/users/anijain/pytorch/torch/_dynamo/guards.py", line 1690, in SHAPE_ENV
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     guards = output_graph.shape_env.produce_guards(
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]   File "/data/users/anijain/pytorch/torch/fx/experimental/symbolic_shapes.py", line 3978, in produce_guards
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0]     track_symint(property_source, ss, constraint[i])
E0703 15:36:46.876000 140292637426816 torch/_guards.py:261] [0/0] IndexError: list index out of range
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0] Created at:
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]   File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 564, in transform
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]     tracer = InstructionTranslator(
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]   File "/data/users/anijain/pytorch/torch/_dynamo/symbolic_convert.py", line 2385, in __init__
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]     output=OutputGraph(
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]   File "/data/users/anijain/pytorch/torch/_dynamo/output_graph.py", line 313, in __init__
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]     self.init_ambient_guards()
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]   File "/data/users/anijain/pytorch/torch/_dynamo/output_graph.py", line 452, in init_ambient_guards
E0703 15:36:46.877000 140292637426816 torch/_guards.py:263] [0/0]     self.guards.add(ShapeEnvSource().make_guard(GuardBuilder.SHAPE_ENV))
Traceback (most recent call last):
  File "/data/users/anijain/pytorch/examples/aliasing.py", line 10, in <module>
    print(opt_fn(torch.ones(3, 3), torch.ones(3, 3), torch.empty(0)))
  File "/data/users/anijain/pytorch/torch/_dynamo/eval_frame.py", line 434, in _fn
    return fn(*args, **kwargs)
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 1121, in __call__
    return self._torchdynamo_orig_callable(
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 948, in __call__
    result = self._inner_convert(
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 472, in __call__
    return _compile(
  File "/data/users/anijain/pytorch/torch/_utils_internal.py", line 85, in wrapper_function
    return StrobelightCompileTimeProfiler.profile_compile_time(
  File "/data/users/anijain/pytorch/torch/_strobelight/compile_time_profiler.py", line 129, in profile_compile_time
    return func(*args, **kwargs)
  File "/home/anijain/local/miniconda3/envs/pytorch/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 846, in _compile
    raise InternalTorchDynamoError(str(e)).with_traceback(
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 817, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/data/users/anijain/pytorch/torch/_dynamo/utils.py", line 233, in time_wrapper
    r = func(*args, **kwargs)
  File "/data/users/anijain/pytorch/torch/_dynamo/convert_frame.py", line 726, in compile_inner
    check_fn = CheckFunctionManager(
  File "/data/users/anijain/pytorch/torch/_dynamo/guards.py", line 2104, in __init__
    guard.create(builder)
  File "/data/users/anijain/pytorch/torch/_guards.py", line 259, in create
    return self.create_fn(builder, self)
  File "/data/users/anijain/pytorch/torch/_dynamo/guards.py", line 1690, in SHAPE_ENV
    guards = output_graph.shape_env.produce_guards(
  File "/data/users/anijain/pytorch/torch/fx/experimental/symbolic_shapes.py", line 3978, in produce_guards
    track_symint(property_source, ss, constraint[i])
torch._dynamo.exc.InternalTorchDynamoError: list index out of range
~~~

cc @ezyang @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames