Random CUBLAS_STATUS_INTERNAL_ERROR crashes during training with RTX 4090

PWhiddy: <p>When training Karpathy’s <a href="https://github.com/karpathy/nanoGPT" rel="noopener nofollow ugc">nanoGPT</a>, after a random amount of time the program crashes with:</p>
<pre><code class="lang-auto">File "/home/pwhiddy/mambaforge-pypy3/envs/py10/lib/python3.10/site-packages/torch/_inductor/compile_fx.py", line 248, in run
    return model(new_inputs)
  File "/tmp/torchinductor_pwhiddy/tp/ctptmd3l7rcxgn4cq5ypmhw4xejaiwge6yp62t76vdurfsgxp4zw.py", line 1371, in call
    extern_kernels.mm(buf367, buf366, out=buf368)
RuntimeError: CUDA error: CUBLAS_STATUS_INTERNAL_ERROR when calling `cublasGemmEx( handle, opa, opb, m, n, k, &amp;falpha, a, CUDA_R_16BF, lda, b, CUDA_R_16BF, ldb, &amp;fbeta, c, CUDA_R_16BF, ldc, CUDA_R_32F, CUBLAS_GEMM_DFALT_TENSOR_OP)`
</code></pre>
<p>What is strange is that the model training loop runs fine, but this error only happens randomly any time from 10 minutes to 10 hours into training.</p>
<p>Running <code>dmesg</code> after the error shows Xid error 109:</p>
<pre><code class="lang-auto">NVRM: Xid (PCI:0000:01:00): 109, pid=4124, name=python, Ch 00000028, errorString CTX SWITCH TIMEOUT, Info 0x2c014
</code></pre>
<p>Besides the environment listed below, I have also tried running with the 525.89 driver and building pytorch from source using cuda 12.</p>
<p>This is a brand new machine but still tried to check for a potential hardware issue. I tried running with GPU power limited to 50%. I also tried reducing program memory usage by 50%. Neither of these prevented the issue. I also tried running <a href="https://github.com/wilicc/gpu-burn" rel="noopener nofollow ugc">gpu-burner</a> but that didn’t indicate any hardware issue either.</p>
<p>python -m torch.utils.collect_env</p>
<pre><code class="lang-auto">PyTorch version: 2.0.0.dev20230226+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.35

Python version: 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-5.19.0-32-generic-x86_64-with-glibc2.35
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 4090
Nvidia driver version: 520.56.06
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:                   39 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          32
On-line CPU(s) list:             0-31
Vendor ID:                       GenuineIntel
Model name:                      13th Gen Intel(R) Core(TM) i9-13900KF
CPU family:                      6
Model:                           183
Thread(s) per core:              2
Core(s) per socket:              24
Socket(s):                       1
Stepping:                        1
CPU max MHz:                     5800.0000
CPU min MHz:                     800.0000
BogoMIPS:                        5990.40
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 est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       896 KiB (24 instances)
L1i cache:                       1.3 MiB (24 instances)
L2 cache:                        32 MiB (12 instances)
L3 cache:                        36 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-31
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          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 IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.1
[pip3] pytorch-triton==2.0.0+b8b470bc59
[pip3] torch==2.0.0.dev20230226+cu118
[pip3] torchaudio==2.0.0.dev20230223+cu118
[pip3] torchvision==0.15.0.dev20230226+cu118
[conda] numpy                     1.24.1                   pypi_0    pypi
[conda] pytorch-triton            2.0.0+b8b470bc59          pypi_0    pypi
[conda] torch                     2.0.0.dev20230226+cu118          pypi_0    pypi
[conda] torchaudio                2.0.0.dev20230223+cu118          pypi_0    pypi
[conda] torchvision               0.15.0.dev20230226+cu118          pypi_0    pypi
</code></pre>
<p>Any insight on this issue would be greatly appreciated, thanks!</p>

PWhiddy: <p>I’m not 100% sure yet if this is the case, but it’s possible the issue has to do with pinned memory. I have not had the error since disabling in training a couple days ago.<br>
For anyone is experiencing this issue, try disabling pinned memory (and please share if this did or didn’t fix this for you).</p>