Repository: pytorch
Issue: cuDNN dBias error starting on 10/2 nightly
Labels: high priority,module: cudnn,triaged,module: regression,module: sdpa

### 🐛 Describe the bug

We are seeing the following error during backward on torchtune's Llama 3.2 Vision models starting with the 10/2 nightly:

```
RuntimeError: cuDNN Frontend error: For cuDNN version below 9.5.0, dBias not support s_q/s_kv which aren't multiple of 64
```

A minimal repro is given by 

```python
import torch
from torch import nn

class DummySDPA(nn.Module):
    def __init__(self):
        super().__init__()
        self.q = nn.Parameter(torch.randn(2, 32, 157, 128).to(device="cuda", dtype=torch.bfloat16))
        self.k = nn.Parameter(torch.randn(2, 32, 6404, 128).to(device="cuda", dtype=torch.torch.bfloat16))
        self.v = nn.Parameter(torch.randn(2, 32, 6404, 128).to(device="cuda", dtype=torch.bfloat16))

    def forward(self, mask):
        return nn.functional.scaled_dot_product_attention(
            self.q,
            self.k,
            self.v,
            attn_mask=mask,
            dropout_p=0.0,
            is_causal=False,
        )

def main():
    mask = torch.randint(0, 2, (2, 1, 157, 6404)).to(device="cuda", dtype=torch.bool)
    model = DummySDPA()
    out = model(mask)
    loss = out.sum()
    loss.backward()

if __name__ == "__main__":
    main()
```

This script passes on 10/1 nightlies and fails on 10/2 nightlies. Looks like #136920 updated the cuDNN frontend to a version that added this check ([ref](https://github.com/NVIDIA/cudnn-frontend/blame/de355c7094af70467f2b264f531ab5c5f4401c42/include/cudnn_frontend/node/scaled_dot_product_flash_attention.h#L873-L875)). It was pointed out by @pbontrager that the dimension `s_q` and `s_kv` is referring to is the sequence length dimension. In general I'm not sure why we would constrain that to be a multiple of 64.

### Versions

Collecting environment information...
PyTorch version: 2.6.0.dev20241002+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: CentOS Stream 9 (x86_64)
GCC version: (GCC) 11.5.0 20240719 (Red Hat 11.5.0-2)
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.34

Python version: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.12.0-0_fbk7_zion_6511_gd766966f605a-x86_64-with-glibc2.34
Is CUDA available: True
CUDA runtime version: 12.0.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA PG509-210
GPU 1: NVIDIA PG509-210
GPU 2: NVIDIA PG509-210
GPU 3: NVIDIA PG509-210
GPU 4: NVIDIA PG509-210
GPU 5: NVIDIA PG509-210
GPU 6: NVIDIA PG509-210
GPU 7: NVIDIA PG509-210

Nvidia driver version: 525.105.17
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):                          192
On-line CPU(s) list:             0-191
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) Platinum 8339HC CPU @ 1.80GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              2
Core(s) per socket:              24
Socket(s):                       4
Stepping:                        11
Frequency boost:                 enabled
CPU(s) scaling MHz:              99%
CPU max MHz:                     1801.0000
CPU min MHz:                     800.0000
BogoMIPS:                        3600.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 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 intel_ppin 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 mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       3 MiB (96 instances)
L1i cache:                       3 MiB (96 instances)
L2 cache:                        96 MiB (96 instances)
L3 cache:                        132 MiB (4 instances)
NUMA node(s):                    4
NUMA node0 CPU(s):               0-23,96-119
NUMA node1 CPU(s):               24-47,120-143
NUMA node2 CPU(s):               48-71,144-167
NUMA node3 CPU(s):               72-95,168-191
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          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 IBRS, IBPB conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] pytorch-triton==3.1.0+cf34004b8a
[pip3] torch==2.6.0.dev20241002+cu124
[conda] pytorch-triton            3.1.0+cf34004b8a          pypi_0    pypi
[conda] torch                     2.6.0.dev20241002+cu124          pypi_0    pypi

cc @ezyang @gchanan @zou3519 @kadeng @msaroufim @csarofeen @ptrblck @xwang233 @eqy @jbschlosser @bhosmer @cpuhrsch @erichan1 @drisspg @mikaylagawarecki