[inductor] unexpected dynamic shape error encountered in TritonTemplate
Labels: triaged, ezyang's list, oncall: pt2, module: dynamic shapes

### 🐛 Describe the bug

`TritonTemplate` cannot deal with some symbolic variable right now. (to be supported in #105295)
But these symbolic variables still show up even if used with `dynamic=False`.


```python
import torch

@torch.compile(mode='max-autotune', dynamic=False)
def func(inp, mat1, mat2):
    res = torch.addmm(inp, mat1, mat2)
    return res

inp = torch.randn(128, device='cuda')
mat1 = torch.randn(16, 64, device='cuda')
mat2 = torch.randn(64, 128, device='cuda')
res = func(inp, mat1, mat2)
print('res', res)

# change size of mat1
mat1 = torch.randn(32, 64, device='cuda')
res = func(inp, mat1, mat2)
print('res', res)
```

error message:
```
Traceback (most recent call last):
  File "/home/constroy/projects/model-zoo/HuggingFace/debug_bmm.py", line 17, in <module>
    res = func(inp, mat1, mat2)
  File "/home/constroy/projects/pytorch/torch/_dynamo/eval_frame.py", line 306, in _fn
    return fn(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_dynamo/eval_frame.py", line 466, in catch_errors
    return callback(frame, cache_size, hooks, frame_state)
  File "/home/constroy/projects/pytorch/torch/_dynamo/convert_frame.py", line 545, in _convert_frame
    result = inner_convert(frame, cache_size, hooks, frame_state)
  File "/home/constroy/projects/pytorch/torch/_dynamo/convert_frame.py", line 128, in _fn
    return fn(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_dynamo/convert_frame.py", line 364, in _convert_frame_assert
    return _compile(
  File "/home/constroy/projects/pytorch/torch/_dynamo/utils.py", line 179, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_dynamo/convert_frame.py", line 434, in _compile
    out_code = transform_code_object(code, transform)
  File "/home/constroy/projects/pytorch/torch/_dynamo/bytecode_transformation.py", line 1002, in transform_code_object
    transformations(instructions, code_options)
  File "/home/constroy/projects/pytorch/torch/_dynamo/convert_frame.py", line 419, in transform
    tracer.run()
  File "/home/constroy/projects/pytorch/torch/_dynamo/symbolic_convert.py", line 2068, in run
    super().run()
  File "/home/constroy/projects/pytorch/torch/_dynamo/symbolic_convert.py", line 727, in run
    and self.step()
  File "/home/constroy/projects/pytorch/torch/_dynamo/symbolic_convert.py", line 687, in step
    getattr(self, inst.opname)(inst)
  File "/home/constroy/projects/pytorch/torch/_dynamo/symbolic_convert.py", line 2156, in RETURN_VALUE
    self.output.compile_subgraph(
  File "/home/constroy/projects/pytorch/torch/_dynamo/output_graph.py", line 791, in compile_subgraph
    self.compile_and_call_fx_graph(tx, list(reversed(stack_values)), root)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/constroy/projects/pytorch/torch/_dynamo/output_graph.py", line 915, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "/home/constroy/projects/pytorch/torch/_dynamo/utils.py", line 179, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_dynamo/output_graph.py", line 971, in call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "/home/constroy/projects/pytorch/torch/_dynamo/output_graph.py", line 967, in call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "/home/constroy/projects/pytorch/torch/_dynamo/repro/after_dynamo.py", line 117, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/home/constroy/projects/pytorch/torch/__init__.py", line 1549, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 861, in compile_fx
    return compile_fx(
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 1045, in compile_fx
    return aot_autograd(
  File "/home/constroy/projects/pytorch/torch/_dynamo/backends/common.py", line 55, in compiler_fn
    cg = aot_module_simplified(gm, example_inputs, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_functorch/aot_autograd.py", line 3755, in aot_module_simplified
    compiled_fn = create_aot_dispatcher_function(
  File "/home/constroy/projects/pytorch/torch/_dynamo/utils.py", line 179, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_functorch/aot_autograd.py", line 3294, in create_aot_dispatcher_function
    compiled_fn = compiler_fn(flat_fn, fake_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/constroy/projects/pytorch/torch/_functorch/aot_autograd.py", line 2098, in aot_wrapper_dedupe
    return compiler_fn(flat_fn, leaf_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/constroy/projects/pytorch/torch/_functorch/aot_autograd.py", line 2278, in aot_wrapper_synthetic_base
    return compiler_fn(flat_fn, flat_args, aot_config, fw_metadata=fw_metadata)
  File "/home/constroy/projects/pytorch/torch/_functorch/aot_autograd.py", line 1552, in aot_dispatch_base
    compiled_fw = compiler(fw_module, flat_args)
  File "/home/constroy/projects/pytorch/torch/_dynamo/utils.py", line 179, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 987, in fw_compiler_base
    return inner_compile(
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/constroy/projects/pytorch/torch/_dynamo/repro/after_aot.py", line 80, in debug_wrapper
    inner_compiled_fn = compiler_fn(gm, example_inputs)
  File "/home/constroy/projects/pytorch/torch/_inductor/debug.py", line 220, in inner
    return fn(*args, **kwargs)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 48, in newFunction
    return old_func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 303, in compile_fx_inner
    compiled_graph: CompiledFxGraph = fx_codegen_and_compile(
  File "/home/constroy/projects/pytorch/torch/_inductor/compile_fx.py", line 502, in fx_codegen_and_compile
    graph.run(*example_inputs)
  File "/home/constroy/projects/pytorch/torch/_dynamo/utils.py", line 179, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/graph.py", line 419, in run
    return super().run(*args)
  File "/home/constroy/projects/pytorch/torch/fx/interpreter.py", line 138, in run
    self.env[node] = self.run_node(node)
  File "/home/constroy/projects/pytorch/torch/_inductor/graph.py", line 675, in run_node
    result = super().run_node(n)
  File "/home/constroy/projects/pytorch/torch/fx/interpreter.py", line 195, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/graph.py", line 566, in call_function
    raise LoweringException(e, target, args, kwargs).with_traceback(
  File "/home/constroy/projects/pytorch/torch/_inductor/graph.py", line 563, in call_function
    out = lowerings[target](*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/lowering.py", line 275, in wrapped
    out = decomp_fn(*args, **kwargs)
  File "/home/constroy/projects/pytorch/torch/_inductor/kernel/mm.py", line 180, in tuned_addmm
    mm_template.maybe_append_choice(
  File "/home/constroy/projects/pytorch/torch/_inductor/select_algorithm.py", line 375, in maybe_append_choice
    self.generate(
  File "/home/constroy/projects/pytorch/torch/_inductor/select_algorithm.py", line 470, in generate
    assert list(call_args) == expected_args, (call_args, expected_args)
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
LoweringException: AssertionError: (['arg0_1', 'arg2_1', 'arg3_1', 'buf_out', s0], ['arg0_1', 'arg2_1', 'arg3_1', 'buf_out'])
  target: aten.addmm.default
  args[0]: TensorBox(StorageBox(
    InputBuffer(name='arg0_1', layout=FixedLayout('cuda', torch.float32, size=[128], stride=[1]))
  ))
  args[1]: TensorBox(StorageBox(
    InputBuffer(name='arg2_1', layout=FixedLayout('cuda', torch.float32, size=[s0, 64], stride=[64, 1]))
  ))
  args[2]: TensorBox(StorageBox(
    InputBuffer(name='arg3_1', layout=FixedLayout('cuda', torch.float32, size=[64, 128], stride=[128, 1]))
  ))

```

### Versions

Collecting environment information...
PyTorch version: 2.1.0a0+git631ab5d
Is debug build: False
CUDA used to build PyTorch: 11.5
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: 14.0.0-1ubuntu1
CMake version: version 3.26.4
Libc version: glibc-2.35

Python version: 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-69-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA A100-PCIE-40GB
Nvidia driver version: 515.105.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          56
On-line CPU(s) list:             0-55
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
CPU family:                      6
Model:                           79
Thread(s) per core:              2
Core(s) per socket:              14
Socket(s):                       2
Stepping:                        1
CPU max MHz:                     2400.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        4800.10
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm arat pln pts md_clear flush_l1d
Virtualization:                  VT-x
L1d cache:                       896 KiB (28 instances)
L1i cache:                       896 KiB (28 instances)
L2 cache:                        7 MiB (28 instances)
L3 cache:                        70 MiB (2 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54
NUMA node1 CPU(s):               1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] flake8-bugbear==23.3.23
[pip3] flake8-comprehensions==3.12.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.3.1
[pip3] flake8-simplify==0.19.3
[pip3] mypy==0.960
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.3
[pip3] pytorch-triton==2.1.0+3c400e7818
[pip3] torch==2.1.0a0+git631ab5d
[conda] Could not collect


cc @ezyang @msaroufim @wconstab @bdhirsh @anijain2305