Repository: pytorch
Issue: `RuntimeError: MKL FFT error: Intel oneMKL DFTI ERROR: Inconsistent configuration parameters`  in `TestJitCPU.test_variant_consistency_jit_fft_fft2_cpu_complex64` against mkl 2024*
Labels: triaged,module: mkl,module: linear algebra,module: intel

### 🐛 Describe the bug

While working on conda-forge packages for PyTorch, I've hit a suspicious test failure. I've been able to reproduce it with PyTorch 2.5.1 (from conda-forge and from pip) and nightly (from pip). When building for conda-forge, I've confirmed that it happens with mkl 2024.1.0 through 2024.2.2; 2024.0.0 failed for other reasons. So the last working version is mkl 2023.2.0.

Output / reproducer;

```
$ pip install -q --pre torch --index-url https://download.pytorch.org/whl/nightly/cu118
$ pip install -q hypothesis expecttest pytest-flakefinder pytest-xdist numpy pytest-flakefinder
$ PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=0 python test/test_ops_jit.py TestJitCPU.test_variant_consistency_jit_fft_fft2_cpu_complex64
E
======================================================================
ERROR: test_variant_consistency_jit_fft_fft2_cpu_complex64 (__main__.TestJitCPU.test_variant_consistency_jit_fft_fft2_cpu_complex64)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/test/test_ops_jit.py", line 109, in test_variant_consistency_jit
    self.indiv_variant_test_jit(
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/test/test_ops_jit.py", line 156, in indiv_variant_test_jit
    check_against_reference(
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_jit.py", line 108, in check_against_reference
    grads = torch.autograd.grad(allSum(outputs), recording_tensors,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/autograd/__init__.py", line 496, in grad
    result = _engine_run_backward(
             ^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/autograd/graph.py", line 823, in _engine_run_backward
    return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: MKL FFT error: Intel oneMKL DFTI ERROR: Inconsistent configuration parameters

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_device_type.py", line 1162, in test_wrapper
    return test(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/test/test_ops_jit.py", line 120, in test_variant_consistency_jit
    raise Exception(variant_error_info) from e  # noqa: TRY002
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: 
                 Error testing fft.fft2 function variant
                 with dtype: torch.complex64
                 with inputs SampleInput(input=tensor([[[ 0.4519-1.6687j, -1.3497+3.1941j, -8.9264-4.0518j,  3.6276-6.9550j,
   -8.5880-5.2066j, -2.2049-4.3718j,  6.0923-0.6148j],
  [ 0.8153-1.4545j, -5.3751+2.8520j, -2.8915-7.5140j,  0.1147+3.8840j,
   -7.9774-5.3941j, -4.7232+6.2016j, -7.0199-1.3300j],
  [ 0.6387-2.9121j,  4.9206-4.0014j,  6.7648-2.2684j, -4.0965-2.3907j,
    2.3617+8.0499j, -0.9205-1.8945j,  3.0848-3.1877j],
  [ 1.0688-2.7264j, -3.7338+2.4207j, -5.2879+7.2414j, -0.4194+2.7186j,
    1.6498-7.2553j, -5.6285+0.5283j,  6.1463+6.6689j],
  [ 4.5116+5.5040j, -4.5468+3.8238j,  2.0432-4.0802j,  7.7975+3.6276j,
   -3.9898+6.4498j, -2.0038-1.4510j, -5.5658-4.9406j],
  [ 0.9235-6.0854j,  7.3032-4.9497j,  3.0275+2.7930j, -7.1406+7.8375j,
   -2.5508+3.3611j, -7.5744-7.7703j,  3.0497+6.1885j]],

 [[ 2.7347+1.4139j, -5.8085-1.2180j,  2.9595+6.3969j, -3.0274+5.5602j,
   -4.6561-4.1872j,  6.7226-3.6585j, -5.0018+4.3699j],
  [-3.6242-3.0665j, -2.2476+7.2501j,  7.5155-6.1942j, -7.7748-8.6985j,
   -8.6626+5.4833j, -7.7189+6.7175j,  5.9785-0.3973j],
  [-1.6851-5.0840j,  4.2354+4.9089j,  4.1848-5.6581j,  3.4160+3.6999j,
    6.0055+5.5249j,  2.4432-0.0450j,  8.8184-4.5192j],
  [ 1.4375-8.2578j, -8.9884-5.9804j,  8.3846+0.4880j, -2.7509-3.0532j,
   -0.4755-1.3543j, -7.5389+2.9812j, -4.2917-0.3567j],
  [-1.4569+5.7937j,  1.2211-8.2981j,  8.7474-8.8791j,  5.8483+6.9294j,
   -4.9306-1.6164j,  3.1223+5.1523j,  7.7248-4.4619j],
  [ 7.0505+1.2090j, -4.5486+5.1965j,  8.9690-6.1245j, -4.6085-2.7860j,
   -4.8467-5.9044j,  4.2504-6.3633j, -3.9363+3.5810j]],

 [[ 1.4855+2.6930j, -1.9112+3.1822j, -1.2487+8.1739j,  0.1605+6.7395j,
    4.7378+5.3385j, -5.9193+4.2485j,  0.5862-1.5016j],
  [-6.4440+8.0353j,  2.8137-6.1565j, -6.3559+2.8448j, -2.9265+2.0644j,
    3.1701-8.6227j, -1.3536+7.4368j,  5.7509+7.1081j],
  [-1.3466+7.0001j, -2.8740+3.2901j, -3.5271-7.2450j, -2.2556-8.7708j,
   -8.8105+1.7250j, -0.5918+4.0027j,  7.7862-3.4462j],
  [ 5.5815+6.4713j, -6.9697+7.0167j,  8.0875-0.2620j, -3.6310+4.7267j,
    6.0261+4.6868j,  0.7755+0.4853j, -1.8758+4.8651j],
  [ 0.8443-4.4743j, -6.6609+2.1552j,  1.0760+8.3737j,  0.9953+8.9865j,
   -3.5583-6.3304j, -1.1792-3.2809j, -1.4970-2.7631j],
  [ 8.2300+3.9946j,  1.4586-0.1478j,  8.5900+3.9895j, -2.2568-8.6140j,
   -8.6059-3.3950j,  1.5673+1.5325j,  4.2586+4.0916j]],

 [[-3.8467+4.3392j,  4.9000+2.3846j,  7.2577-6.4897j,  1.4237-1.9427j,
    8.1282-7.0420j,  2.9550-6.4592j, -6.0499-8.1850j],
  [ 1.8745+8.2029j, -4.5403+0.6454j, -7.3490-6.4714j,  3.5490-1.2901j,
   -1.4631-5.0934j,  5.5921-6.8921j, -4.1412+5.8519j],
  [ 3.9626-8.2865j, -8.7425-5.2016j, -8.6528+6.3069j, -4.3739+3.5793j,
   -7.3106+2.2135j,  8.3889+5.8287j,  8.0646-1.9299j],
  [-1.2084-7.4524j, -3.8084-5.4723j, -0.3318+0.4794j, -2.2864-3.7192j,
    8.7766+1.1045j, -8.1575-3.2041j,  4.9697-8.4564j],
  [ 8.3740-0.9771j,  3.4598-2.1305j, -5.8572+4.8399j,  2.7278-4.8294j,
    3.6917-4.7133j, -6.6076-8.8687j,  6.6301+7.2904j],
  [ 6.2127+6.2237j,  8.2466+0.1138j, -8.3478-5.6941j,  5.3688-7.1158j,
   -1.1510-0.6876j, -0.2579-8.1676j,  7.4570-1.4829j]],

 [[-1.9497-3.2609j, -1.6071-1.4398j, -5.0406+7.4493j,  1.4543+1.0708j,
   -6.3619+8.9065j, -2.7798+5.7593j, -4.9274-1.1785j],
  [ 0.3750+0.5040j, -1.0892-2.0268j, -5.2186-2.7966j, -6.8724+6.9988j,
   -3.4293+0.1416j, -7.5392-6.6634j, -5.8855+3.4055j],
  [ 8.3858+0.0659j,  6.9550-8.3678j, -8.9337+3.4571j, -4.9290-4.6410j,
    7.1276-0.1551j,  5.7600-3.2788j,  1.0814+8.6245j],
  [ 0.7012+5.1418j,  8.0857+7.2150j,  7.5094-4.5757j,  3.3091-0.2827j,
   -4.1042-5.0177j,  3.9241+4.4959j,  0.9279+7.5567j],
  [ 2.9002+7.3141j,  4.6324-1.4293j, -3.2982-7.4901j,  8.9872-2.4968j,
    3.5917+5.0777j, -6.2488+4.3580j,  5.5003-4.6500j],
  [-3.4046+1.7749j,  7.6435+8.2865j, -1.8083-4.3086j,  4.2663-1.5021j,
    1.4435-7.2924j,  1.0314+2.2837j, -3.1866+1.4575j]]],
requires_grad=True), args=(), kwargs={'s': (3, 10), 'dim': (1, 2), 'norm': 'ortho'}, broadcasts_input=False, name=''):


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_utils.py", line 3108, in wrapper
    method(*args, **kwargs)
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_device_type.py", line 460, in instantiated_test
    result = test(self, **param_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_device_type.py", line 1242, in dep_fn
    return fn(slf, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_utils.py", line 1621, in wrapper
    fn(*args, **kwargs)
  File "/var/tmp/conda-bld/work_moved_libtorch-2.5.1-cpu_mkl_h5f89428_106_linux-64/.venv/lib/python3.12/site-packages/torch/testing/_internal/common_device_type.py", line 1174, in test_wrapper
    raise e_tracked from e
Exception: Caused by sample input at index 0: SampleInput(input=Tensor[size=(5, 6, 7), device="cpu", dtype=torch.complex64], args=(), kwargs={'s': '(3,10)', 'dim': '(1,2)', 'norm': "'ortho'"}, broadcasts_input=False, name='')

To execute this test, run the following from the base repo dir:
    PYTORCH_OPINFO_SAMPLE_INPUT_INDEX=0 python test/test_ops_jit.py TestJitCPU.test_variant_consistency_jit_fft_fft2_cpu_complex64

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

----------------------------------------------------------------------
Ran 1 test in 0.078s

FAILED (errors=1)
```

### Versions

```
Collecting environment information...
PyTorch version: 2.6.0.dev20241210+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Gentoo Linux (x86_64)
GCC version: (Gentoo 14.2.1_p20241116 p3) 14.2.1 20241116
Clang version: 20.0.0git32f7f001
CMake version: version 3.31.2
Libc version: glibc-2.40

Python version: 3.12.7 (main, Oct 19 2024, 06:58:55) [GCC 14.2.1 20240921] (64-bit runtime)
Python platform: Linux-6.12.4-gentoo-dist-x86_64-AMD_Ryzen_5_3600_6-Core_Processor-with-glibc2.40
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:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               12
On-line CPU(s) list:                  0-11
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 5 3600 6-Core Processor
CPU family:                           23
Model:                                113
Thread(s) per core:                   2
Core(s) per socket:                   6
Socket(s):                            1
Stepping:                             0
Frequency boost:                      enabled
CPU(s) scaling MHz:                   98%
CPU max MHz:                          4208,0000
CPU min MHz:                          550,0000
BogoMIPS:                             7189,90
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 xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
Virtualization:                       AMD-V
L1d cache:                            192 KiB (6 instances)
L1i cache:                            192 KiB (6 instances)
L2 cache:                             3 MiB (6 instances)
L3 cache:                             32 MiB (2 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-11
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:               Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
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; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.0
[pip3] nvidia-cublas-cu11==11.11.3.6
[pip3] nvidia-cuda-cupti-cu11==11.8.87
[pip3] nvidia-cuda-nvrtc-cu11==11.8.89
[pip3] nvidia-cuda-runtime-cu11==11.8.89
[pip3] nvidia-cudnn-cu11==9.1.0.70
[pip3] nvidia-cufft-cu11==10.9.0.58
[pip3] nvidia-curand-cu11==10.3.0.86
[pip3] nvidia-cusolver-cu11==11.4.1.48
[pip3] nvidia-cusparse-cu11==11.7.5.86
[pip3] nvidia-nccl-cu11==2.21.5
[pip3] nvidia-nvtx-cu11==11.8.86
[pip3] pytorch-triton==3.2.0+git35c6c7c6
[pip3] torch==2.6.0.dev20241210+cu118
[conda] Could not collect
```

cc @jianyuh @nikitaved @pearu @mruberry @walterddr @xwang233 @Lezcano @frank-wei @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10