Repository: pytorch
Issue: [inductor][torchbench] Unsupported operator issue when running the torch_multimodal_clip model with batch size 4.
Labels: module: nn,triaged,oncall: pt2,module: sdpa

### 🐛 Describe the bug

I'm conducting an accuracy test for the `torch_multimodal_clip `model. I noticed that the graph breaks count is 0 when using a batch size of 1. However, when increasing the batch size to 4, the graph breaks count rises to 3. Upon printing the graph break details, I discovered the unsupported operator issue occurring with batch size 4. 


```shell
python benchmarks/dynamo/torchbench.py --accuracy --amp -dcpu  --inference -n50 --inductor --timeout 9000 --dynamic-shapes --dynamic-batch-only --freezing --only torch_multimodal_clip --print-graph-breaks --explain --batch-size 4
```
```
loading model: 0it [00:02, ?it/s]
cpu  eval  torch_multimodal_clip
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks] Graph break in user code at /workspace/pytorch/torch/nn/modules/activation.py:1313
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks] Reason: Unsupported: unsupported operator: aten._native_multi_head_attention.default (see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks] User code traceback:
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/benchmarks/dynamo/common.py", line 2782, in run_n_iterations
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     self.model_iter_fn(mod, inputs, collect_outputs=False)
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/benchmarks/dynamo/torchbench.py", line 444, in forward_pass
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     return mod(*inputs)
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/opt/conda/lib/python3.10/site-packages/torchmultimodal/models/clip/model.py", line 71, in forward
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     embeddings_a = self.encoder_a(features_a)
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/opt/conda/lib/python3.10/site-packages/torchmultimodal/models/clip/image_encoder.py", line 108, in forward
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     x = self.encoder(x)
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/torch/nn/modules/transformer.py", line 517, in forward
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     output = mod(
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/torch/nn/modules/transformer.py", line 913, in forward
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     x = x + self._sa_block(
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/torch/nn/modules/transformer.py", line 934, in _sa_block
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     x = self.self_attn(
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]   File "/workspace/pytorch/torch/nn/modules/activation.py", line 1313, in forward
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]     return torch._native_multi_head_attention(
V0123 16:00:42.112000 10589 torch/_dynamo/symbolic_convert.py:460] [0/0] [__graph_breaks]
V0123 16:00:42.211000 10589 torch/_dynamo/symbolic_convert.py:467] [1/0] [__graph_breaks] Graph break (details suppressed) in user code at /workspace/pytorch/torch/nn/modules/activation.py:1313
V0123 16:00:42.211000 10589 torch/_dynamo/symbolic_convert.py:467] [1/0] [__graph_breaks] Reason: Unsupported: unsupported operator: aten._native_multi_head_attention.default (see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)
V0123 16:00:42.466000 10589 torch/_dynamo/symbolic_convert.py:467] [2/0] [__graph_breaks] Graph break (details suppressed) in user code at /workspace/pytorch/torch/nn/modules/activation.py:1313
V0123 16:00:42.466000 10589 torch/_dynamo/symbolic_convert.py:467] [2/0] [__graph_breaks] Reason: Unsupported: unsupported operator: aten._native_multi_head_attention.default (see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)
V0123 16:00:42.569000 10589 torch/_dynamo/symbolic_convert.py:467] [3/0] [__graph_breaks] Graph break (details suppressed) in user code at /workspace/pytorch/torch/nn/modules/activation.py:1313
V0123 16:00:42.569000 10589 torch/_dynamo/symbolic_convert.py:467] [3/0] [__graph_breaks] Reason: Unsupported: unsupported operator: aten._native_multi_head_attention.default (see https://docs.google.com/document/d/1GgvOe7C8_NVOMLOCwDaYV1mXXyHMXY7ExoewHqooxrs/edit#heading=h.64r4npvq0w0 for how to fix)
pass
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
Dynamo produced 6 graphs covering 209 ops with 3 graph breaks (1 unique)
```

For reference, below is the log of batch size 1
```shell
python benchmarks/dynamo/torchbench.py --accuracy --amp -dcpu  --inference -n50 --inductor --timeout 9000 --dynamic-shapes --dynamic-batch-only --freezing --only torch_multimodal_clip --print-graph-breaks --explain --batch-size 1
```
```
loading model: 0it [00:02, ?it/s]
cpu  eval  torch_multimodal_clip
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
pass
WARNING:common:Trying to call the empty_gpu_cache for device: cpu, which is not in list [cuda, xpu]
Dynamo produced 1 graphs covering 744 ops with 0 graph breaks (0 unique)
```

### Versions

PyTorch version: 2.7.0a0+git9ae35b8
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.35

Python version: 3.10.16 | packaged by conda-forge | (main, Dec  5 2024, 14:16:10) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-130-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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:                        52 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               384
On-line CPU(s) list:                  0-383
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Xeon(R) 6972P
CPU family:                           6
Model:                                173
Thread(s) per core:                   2
Core(s) per socket:                   96
Socket(s):                            2
Stepping:                             1
CPU max MHz:                          3900.0000
CPU min MHz:                          800.0000
BogoMIPS:                             4800.00
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 art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq 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 cat_l2 cdp_l3 invpcid_single cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization:                       VT-x
L1d cache:                            9 MiB (192 instances)
L1i cache:                            12 MiB (192 instances)
L2 cache:                             384 MiB (192 instances)
L3 cache:                             960 MiB (2 instances)
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-95,192-287
NUMA node1 CPU(s):                    96-191,288-383
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   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; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS Not affected; BHI BHI_DIS_S
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] bert_pytorch==0.0.1a4
[pip3] functorch==1.14.0a0+b71aa0b
[pip3] mypy==1.14.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] onnx==1.17.0
[pip3] torch==2.7.0a0+git9ae35b8
[pip3] torch_geometric==2.4.0
[pip3] torchaudio==2.6.0a0+b6d4675
[pip3] torchdata==0.7.0a0+11bb5b8
[pip3] torchmultimodal==0.1.0b0
[pip3] torchtext==0.16.0a0+b0ebddc
[pip3] torchvision==0.19.0a0+d23a6e1
[conda] bert-pytorch              0.0.1a4                   dev_0    <develop>
[conda] functorch                 1.14.0a0+b71aa0b          pypi_0    pypi
[conda] mkl                       2025.0.0           h901ac74_941    conda-forge
[conda] mkl-include               2025.0.0           hf2ce2f3_941    conda-forge
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] torch                     2.7.0a0+git9ae35b8           dev_0    <develop>
[conda] torch-geometric           2.4.0                    pypi_0    pypi
[conda] torchaudio                2.6.0a0+b6d4675          pypi_0    pypi
[conda] torchdata                 0.7.0a0+11bb5b8          pypi_0    pypi
[conda] torchmultimodal           0.1.0b0                  pypi_0    pypi
[conda] torchtext                 0.16.0a0+b0ebddc          pypi_0    pypi
[conda] torchvision               0.19.0a0+d23a6e1          pypi_0    pypi

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @chauhang @penguinwu @cpuhrsch @bhosmer @drisspg @soulitzer @davidberard98 @YuqingJ