"RuntimeError: (*bias): last dimension must be contiguous" with F.scaled_dot_product_attention + torch.compile
Labels: triaged, oncall: pt2, module: inductor

### 🐛 Describe the bug

My code is giving a RuntimeError when I try to use `F.scaled_dot_product_attention()` together with `torch.compile()`, please see the minimal example below. This is on the latest nightly version

### Error logs

```
Traceback (most recent call last):
  File "/mnt/c/sw/plb_hpc/src/bug.py", line 54, in <module>
    static(query, key, value, bias, weights)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 406, in _fn
    return fn(*args, **kwargs)
  File "/mnt/c/sw/plb_hpc/src/bug.py", line 12, in fn
    def fn(q, k, v, b, w):
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 406, in _fn
    return fn(*args, **kwargs)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
    return fn(*args, **kwargs)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 3905, in forward
    return compiled_fn(full_args)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 1482, in g
    return f(*args)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 2533, in runtime_wrapper
    all_outs = call_func_with_args(
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 1506, in call_func_with_args
    out = normalize_as_list(f(args))
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py", line 1594, in rng_functionalization_wrapper
    return compiled_fw(args)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_inductor/codecache.py", line 396, in __call__
    return self.get_current_callable()(inputs)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_inductor/compile_fx.py", line 616, in run
    return model(new_inputs)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_inductor/codecache.py", line 423, in _run_from_cache
    return compiled_graph.compiled_artifact(inputs)
  File "/tmp/torchinductor_caleb/zb/czb6rbgh2vvegcwcj2yimlnpwwzdkqfw3k727aos2kyyabox2th3.py", line 75, in call
    buf2 = aten._scaled_dot_product_efficient_attention(arg0_1, arg1_1, arg2_1, buf1, False)
  File "/home/caleb/miniconda3/envs/debug/lib/python3.10/site-packages/torch/_ops.py", line 692, in __call__
    return self._op(*args, **kwargs or {})
RuntimeError: (*bias): last dimension must be contiguous
```

### Minified repro

```python
import torch
import torch.nn.functional as F
from einops import rearrange


def fn(q, k, v, b, w):

    # apply linear layer to bias
    b = rearrange(b @ w, "B Q K H -> B H Q K")

    # if you comment out this line, the error goes away
    b = b.contiguous()

    # attention
    return F.scaled_dot_product_attention(
        query=q,
        key=k,
        value=v,
        attn_mask=b,
    )


if __name__ == "__main__":

    # setup
    DEVICE = torch.device("cuda:0")
    DTYPE = torch.float16
    torch.manual_seed(999)
    B = 3
    H = 8
    Q = 99
    K = 80
    D = 32
    C_bias = 128

    # inputs
    query = torch.randn((B, H, Q, D), device=DEVICE, dtype=DTYPE)
    key = torch.randn((B, H, K, D), device=DEVICE, dtype=DTYPE)
    value = torch.randn((B, H, K, D), device=DEVICE, dtype=DTYPE)
    bias = torch.randn((B, Q, K, C_bias), device=DEVICE, dtype=DTYPE)
    weights = torch.randn((C_bias, H), device=DEVICE, dtype=DTYPE)

    # eager version is okay
    fn(query, key, value, bias, weights)

    # compiled version causes error
    static = torch.compile(fn)
    static(query, key, value, bias, weights)
```

### Versions

```
PyTorch version: 2.2.0.dev20230918
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060
Nvidia driver version: 536.23
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
Byte Order:                      Little Endian
Address sizes:                   48 bits physical, 48 bits virtual
CPU(s):                          10
On-line CPU(s) list:             0-9
Thread(s) per core:              2
Core(s) per socket:              5
Socket(s):                       1
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model:                           113
Model name:                      AMD Ryzen 5 3600 6-Core Processor
Stepping:                        0
CPU MHz:                         3593.258
BogoMIPS:                        7186.51
Hypervisor vendor:               Microsoft
Virtualization type:             full
L1d cache:                       160 KiB
L1i cache:                       160 KiB
L2 cache:                        2.5 MiB
L3 cache:                        16 MiB
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; Full AMD retpoline, IBPB conditional, STIBP conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpuid extd_apicid pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ssbd ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr virt_ssbd arat umip rdpid

Versions of relevant libraries:
[pip3] numpy==1.25.2
[pip3] torch==2.2.0.dev20230918
[pip3] triton==2.1.0
[conda] blas                      1.0                         mkl    conda-forge
[conda] libblas                   3.9.0            16_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            16_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            16_linux64_mkl    conda-forge
[conda] mkl                       2022.1.0           hc2b9512_224  
[conda] numpy                     1.25.2          py310ha4c1d20_0    conda-forge
[conda] pytorch                   2.2.0.dev20230918 py3.10_cuda11.8_cudnn8.7.0_0    pytorch-nightly
[conda] pytorch-cuda              11.8                 h7e8668a_5    pytorch-nightly
[conda] pytorch-mutex             1.0                        cuda    pytorch-nightly
[conda] torchtriton               2.1.0+6e4932cda8           py310    pytorch-nightly
```

cc @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov