Skip to content

[Inductor][AO] Flex Attention with AO hit the recompile limit on v2.9.0 #166153

@hoshibara

Description

@hoshibara

🐛 Describe the bug

On v2.9.0 tag, models using flex attention with ao hit the recompile_limit.
It prevents flex attention from being properly fused.
As a result, the prefill e2e performance drops to about 35% of the main branch.
The log when this issue occurs is as follows:

W1021 16:19:11.680000 2300716 /pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/_dynamo/convert_frame.py:1364] [13/8] torch._dynamo hit config.recompile_limit (8)
W1021 16:19:11.680000 2300716 /pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/_dynamo/convert_frame.py:1364] [13/8]    function: 'flex_attention' (/pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/nn/attention/flex_attention.py:1440)
W1021 16:19:11.680000 2300716 /pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/_dynamo/convert_frame.py:1364] [13/8]    last reason: 13/7: ___check_obj_id(key, 123962271811680)                    # if query.dtype != key.dtype or query.dtype != value.dtype:  # nn/attention/_utils.py:44 in _validate_sdpa_input
W1021 16:19:11.680000 2300716 /pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/_dynamo/convert_frame.py:1364] [13/8] To log all recompilation reasons, use TORCH_LOGS="recompiles".
W1021 16:19:11.680000 2300716 /pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/_dynamo/convert_frame.py:1364] [13/8] To diagnose recompilation issues, see https://pytorch.org/docs/main/torch.compiler_troubleshooting.html
/pytorch/xingyuan/projects/20251020-pytorch28-validate/pytorch/torch/nn/attention/flex_attention.py:1678: UserWarning: flex_attention called without torch.compile() - this will use an unfused implementation that materializes the full scores matrix instead of generating a fused kernel.

After investigation, we found that this bug has been fixed in commit 75de5b6.

Additionally, we tried to cherry-pick 75de5b6 on v2.9.0, and this issue was successfully resolved.

Versions

Collecting environment information...
PyTorch version: 2.10.0a0+git75de5b6
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.3 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 4.1.0
Libc version: glibc-2.39

Python version: 3.10.19 | packaged by conda-forge | (main, Oct 13 2025, 14:08:27) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.16.0-rc7+prerelease10+-x86_64-with-glibc2.39
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
Is XPU available: True
XPU used to build PyTorch: 20250201
Intel GPU driver version:
* libze1:	1.24.1-1~24.04~ppa1
* intel-opencl-icd:	25.35.35096.9-1~24.04~ppa3
Intel GPU models onboard:
* Intel(R) Arc(TM) B580 Graphics
* Intel(R) Arc(TM) B580 Graphics
* Intel(R) Arc(TM) B580 Graphics
* Intel(R) Arc(TM) B580 Graphics
Intel GPU models detected:
* [0] _XpuDeviceProperties(name='Intel(R) Arc(TM) B580 Graphics', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xE20B, uuid=86800be2-0000-0000-1800-000000000000, driver_version='1.6.35096+9', total_memory=11605MB, max_compute_units=160, gpu_eu_count=160, gpu_subslice_count=20, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
* [1] _XpuDeviceProperties(name='Intel(R) Arc(TM) B580 Graphics', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xE20B, uuid=86800be2-0000-0000-3a00-000000000000, driver_version='1.6.35096+9', total_memory=11605MB, max_compute_units=160, gpu_eu_count=160, gpu_subslice_count=20, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
* [2] _XpuDeviceProperties(name='Intel(R) Arc(TM) B580 Graphics', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xE20B, uuid=86800be2-0000-0000-9a00-000000000000, driver_version='1.6.35096+9', total_memory=11605MB, max_compute_units=160, gpu_eu_count=160, gpu_subslice_count=20, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
* [3] _XpuDeviceProperties(name='Intel(R) Arc(TM) B580 Graphics', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xE20B, uuid=86800be2-0000-0000-aa00-000000000000, driver_version='1.6.35096+9', total_memory=11605MB, max_compute_units=160, gpu_eu_count=160, gpu_subslice_count=20, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
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):                                  256
On-line CPU(s) list:                     0-255
Vendor ID:                               GenuineIntel
Model name:                              Genuine Intel(R) 0000
CPU family:                              6
Model:                                   207
Thread(s) per core:                      2
Core(s) per socket:                      64
Socket(s):                               2
Stepping:                                1
CPU(s) scaling MHz:                      24%
CPU max MHz:                             4000.0000
CPU min MHz:                             800.0000
BogoMIPS:                                3400.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 intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow 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 user_shstk avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req hfi vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               6 MiB (128 instances)
L1i cache:                               4 MiB (128 instances)
L2 cache:                                256 MiB (128 instances)
L3 cache:                                640 MiB (2 instances)
NUMA node(s):                            4
NUMA node0 CPU(s):                       0-31,128-159
NUMA node1 CPU(s):                       32-63,160-191
NUMA node2 CPU(s):                       64-95,192-223
NUMA node3 CPU(s):                       96-127,224-255
Vulnerability Gather data sampling:      Not affected
Vulnerability Ghostwrite:                Not affected
Vulnerability Indirect target selection: 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 Old microcode:             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
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.6
[pip3] optree==0.17.0
[pip3] pytorch-triton-xpu==3.5.0+git1b0418a9
[pip3] torch==2.10.0a0+git75de5b6
[pip3] torchao==0.15.0.dev20251012+xpu
[pip3] torchaudio==2.9.0+xpu
[pip3] torchvision==0.24.0+xpu
[conda] numpy                     2.2.6                    pypi_0    pypi
[conda] optree                    0.17.0                   pypi_0    pypi
[conda] pytorch-triton-xpu        3.5.0+git1b0418a9          pypi_0    pypi
[conda] torch                     2.10.0a0+git75de5b6          pypi_0    pypi
[conda] torchao                   0.15.0.dev20251012+xpu          pypi_0    pypi
[conda] torchaudio                2.9.0+xpu                pypi_0    pypi
[conda] torchvision               0.24.0+xpu               pypi_0    pypi


$ pip list | grep transformers

transformers       4.55.4                 /pytorch/xingyuan/projects/20251020-pytorch28-validate/transformers/src


$ dpkg -l | grep igc

ii  libigc2                              2.18.5-1188~24.04                 amd64        Core libraries for Intel(R) Graphics Compiler for OpenCL(TM)


$ dpkg -l | grep dkms

Done collecting environment info.

cc @chauhang @penguinwu @Chillee @drisspg @yanboliang @BoyuanFeng

Metadata

Metadata

Assignees

Labels

module: flex attentiononcall: pt2triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions