CUDA errors with CUDA 11.7 + dual RTX 3090 Ti

yoshitomo-matsubara: <p>I’m asking for help here as well because I feel that the CUDA errors (see below) occurred with multiple scripts that were working on a machine with NVIDIA RTX 3090 x2 and may be more like issues from PyTorch, CUDA, other dependencies, or NVIDIA RTX 3090 Ti.</p>
<p>I built my own dual GPU machine and wanted to train some random model (resnet152), using torchvision, to make sure the machine is ready for running experiments with PyTorch.</p>
<p>However, <a href="https://github.com/pytorch/vision/blob/main/references/classification/train.py" rel="noopener nofollow ugc"><code>vision/references/classification/train.py</code></a> did not complete the training sessions due to various CUDA errors.<br>
(Note that I did not modify any code in the repository,  and the commit version is beb4bb706b5e13009cb5d5586505c6d2896d184a)</p>
<h1>
<a name="errors-1" class="anchor" href="#errors-1"></a>Errors</h1>
<p>Using <code>vision/references/classification/train.py</code>, I attempted to train a model in three different ways, which all turned out to fail.<br>
<code>torchrun</code> didn’t help me identify at which line of train.py the training failed, but the last two attempts show it failed at <code>loss.backward()</code> with different types of errors.</p>
<h2>
<a name="h-1-distributed-training-mode-with-torchrun-2" class="anchor" href="#h-1-distributed-training-mode-with-torchrun-2"></a>1. Distributed training mode (with torchrun)</h2>
<p>This is the first attempt:</p>
<pre data-code-wrap="shell"><code class="lang-plaintext">torchrun --nproc_per_node=2 train.py --model='resnet152' --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
</code></pre>
<p>After a few minutes, it failed and returned “Signal 11 (SIGSEGV) received by PID 74466”</p>
<pre><code class="lang-auto">WARNING:torch.distributed.run:
*****************************************
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed. 
*****************************************
| distributed init (rank 0): env://
| distributed init (rank 1): env://
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=2, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, rank=0, gpu=0, distributed=True, dist_backend='nccl')
Loading data
Loading training data
Took 1.1964967250823975
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/20019]  eta: 13:36:49  lr: 0.1  img/s: 19.59049709064079  loss: 7.1077 (7.1077)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 2.4482  data: 0.8147  max mem: 8343
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 74467 closing signal SIGTERM
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: -11) local_rank: 0 (pid: 74466) of binary: /home/yoshitomo/anaconda3/bin/python
Traceback (most recent call last):
  File "/home/yoshitomo/anaconda3/bin/torchrun", line 33, in &lt;module&gt;
    sys.exit(load_entry_point('torch==1.13.1', 'console_scripts', 'torchrun')())
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 346, in wrapper
    return f(*args, **kwargs)
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/run.py", line 762, in main
    run(args)
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/run.py", line 753, in run
    elastic_launch(
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 132, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 246, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
=======================================================
train.py FAILED
-------------------------------------------------------
Failures:
  &lt;NO_OTHER_FAILURES&gt;
-------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2023-03-06_22:42:17
  host      : my_pc
  rank      : 0 (local_rank: 0)
  exitcode  : -11 (pid: 74466)
  error_file: &lt;N/A&gt;
  traceback : Signal 11 (SIGSEGV) received by PID 74466
=======================================================
</code></pre>
<hr>
<h2>
<a name="h-2-distributed-training-mode-without-torchrun-3" class="anchor" href="#h-2-distributed-training-mode-without-torchrun-3"></a>2. Distributed training mode (without torchrun)</h2>
<p>I gave it another try, but without torchrun:</p>
<pre data-code-wrap="shell"><code class="lang-plaintext">python3 -m torch.distributed.launch --nproc_per_node=2 --use_env train.py --world-size 2 --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 1000
</code></pre>
<p>This time it returned “Signal 6 (SIGABRT) received by PID 75526”</p>
<pre><code class="lang-auto">/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launch.py:180: FutureWarning: The module torch.distributed.launch is deprecated                                                    
and will be removed in future. Use torchrun.                                                                                                                                                               
Note that --use_env is set by default in torchrun.                                                                                                                                                         
If your script expects `--local_rank` argument to be set, please                                                                                                                                           
change it to read from `os.environ['LOCAL_RANK']` instead. See                                                                                                                                             
https://pytorch.org/docs/stable/distributed.html#launch-utility for                                                                                                                                        
further instructions                                                                                                                                                                                       
                                                                                                                                                                                                           
  warnings.warn(                                                                                                                                                                                           
WARNING:torch.distributed.run:                                                                                                                                                                             
*****************************************                                                                                                                                                                  
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as ne
eded.                                                                                                                                                                                                      
*****************************************                                                                                                                                                                  
| distributed init (rank 1): env://                                                                                                                                                                        
| distributed init (rank 0): env://
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=1000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=2, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, rank=0, gpu=0, distributed=True, dist_backend='nccl')
Loading data
Loading training data
Took 1.1878349781036377
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/20019]  eta: 13:32:42  lr: 0.1  img/s: 19.396707388591327  loss: 7.1465 (7.1465)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 2.4358  data: 0.7860  max mem: 8343
Epoch: [0]  [ 1000/20019]  eta: 0:58:49  lr: 0.1  img/s: 173.86594400494326  loss: 6.8894 (6.9586)  acc1: 0.0000 (0.1467)  acc5: 0.0000 (0.6119)  time: 0.1842  data: 0.0000  max mem: 8343
Epoch: [0]  [ 2000/20019]  eta: 0:55:36  lr: 0.1  img/s: 173.47313783347485  loss: 6.7749 (6.9015)  acc1: 0.0000 (0.1515)  acc5: 0.0000 (0.8027)  time: 0.1854  data: 0.0000  max mem: 8343
Traceback (most recent call last):
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 515, in &lt;module&gt;
    main(args)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 357, in main
    train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema, scaler)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 42, in train_one_epoch
    loss.backward()
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/_tensor.py", line 488, in backward
    torch.autograd.backward(
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/autograd/__init__.py", line 197, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: cuDNN error: CUDNN_STATUS_MAPPING_ERROR
[W CUDAGuardImpl.h:124] Warning: CUDA warning: unspecified launch failure (function destroyEvent)
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 75527 closing signal SIGTERM
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: -6) local_rank: 0 (pid: 75526) of binary: /home/yoshitomo/anaconda3/bin/python3
Traceback (most recent call last):
  File "/home/yoshitomo/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/yoshitomo/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launch.py", line 195, in &lt;module&gt;
    main()
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launch.py", line 191, in main
    launch(args)
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launch.py", line 176, in launch
    run(args)
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/run.py", line 753, in run
    elastic_launch(
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 132, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 246, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
======================================================
train.py FAILED
------------------------------------------------------
Failures:
  &lt;NO_OTHER_FAILURES&gt;
------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2023-03-06_23:03:47
  host      : my_pc
  rank      : 0 (local_rank: 0)
  exitcode  : -6 (pid: 75526)
  error_file: &lt;N/A&gt;
  traceback : Signal 6 (SIGABRT) received by PID 75526
======================================================

</code></pre>
<hr>
<h2>
<a name="h-3-non-distributed-training-mode-4" class="anchor" href="#h-3-non-distributed-training-mode-4"></a>3. Non-distributed training mode</h2>
<p>I also tried to train the same model, using only one GPU</p>
<pre data-code-wrap="shell"><code class="lang-plaintext">CUDA_VISIBLE_DEVICES=0 python3 train.py --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
</code></pre>
<p>, but it still returns <code>RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED </code></p>
<pre><code class="lang-auto">Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 1.1773681640625
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 21:54:13  lr: 0.1  img/s: 22.003122653665447  loss: 7.0583 (7.0583)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.9695  data: 0.5152  max mem: 8113
Traceback (most recent call last):
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 515, in &lt;module&gt;
    main(args)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 357, in main
    train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema, scaler)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 42, in train_one_epoch
    loss.backward()
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/_tensor.py", line 488, in backward
    torch.autograd.backward(
  File "/home/yoshitomo/anaconda3/lib/python3.9/site-packages/torch/autograd/__init__.py", line 197, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &amp;alpha, a, lda, b, ldb, &amp;beta, c, ldc)`
</code></pre>
<h3>
<a name="versions-5" class="anchor" href="#versions-5"></a>Versions</h3>
<h1>
<a name="environment-6" class="anchor" href="#environment-6"></a>Environment</h1>
<ul>
<li>NVIDIA RTX 3090 Ti x2</li>
<li>Ubuntu 22 LTS</li>
<li>NVIDIA-SMI 515.86.01</li>
<li>Driver Version: 515.86.01</li>
<li>CUDA Version: 11.7</li>
</ul>
<p>I installed torch and torchvision with the following command:</p>
<pre data-code-wrap="shell"><code class="lang-plaintext">conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
</code></pre>
<h2>
<a name="versions-7" class="anchor" href="#versions-7"></a>Versions</h2>
<p>Here is the output of <code>python3 collect_env.py</code></p>
<pre><code class="lang-auto">Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: 11.7
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: Could not collect
Libc version: glibc-2.35

Python version: 3.9.16 (main, Mar  1 2023, 18:22:10)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-35-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090 Ti
GPU 1: NVIDIA GeForce RTX 3090 Ti

Nvidia driver version: 515.86.01
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):                          24
On-line CPU(s) list:             0-23
Vendor ID:                       GenuineIntel
Model name:                      12th Gen Intel(R) Core(TM) i9-12900KS
CPU family:                      6
Model:                           151
Thread(s) per core:              2
Core(s) per socket:              16
Socket(s):                       1
Stepping:                        2
CPU max MHz:                     5300.0000
CPU min MHz:                     800.0000
BogoMIPS:                        6835.20
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 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 tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       640 KiB (16 instances)
L1i cache:                       768 KiB (16 instances)
L2 cache:                        14 MiB (10 instances)
L3 cache:                        30 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-23
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] mypy-extensions==0.4.3
[pip3] numpy==1.23.5
[pip3] numpydoc==1.5.0
[pip3] torch==1.13.1
[pip3] torchaudio==0.13.1
[pip3] torchvision==0.14.1
[conda] blas                      1.0                         mkl  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py39h7f8727e_0  
[conda] mkl_fft                   1.3.1            py39hd3c417c_0  
[conda] mkl_random                1.2.2            py39h51133e4_0  
[conda] numpy                     1.23.5           py39h14f4228_0  
[conda] numpy-base                1.23.5           py39h31eccc5_0  
[conda] numpydoc                  1.5.0            py39h06a4308_0  
[conda] pytorch                   1.13.1          py3.9_cuda11.7_cudnn8.5.0_0    pytorch
[conda] pytorch-cuda              11.7                 h67b0de4_1    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                0.13.1               py39_cu117    pytorch
[conda] torchvision               0.14.1               py39_cu117    pytorch
</code></pre>
<p>I also tried different NVIDIA drivers available as “Additional Drivers” and corresponding CUDA versions, but it didn’t resolve the issue.</p>
<p>Thank you for your help</p>

ptrblck: <p>Are you seeing the same error using a single GPU run on device 1?<br>
Also, do you have any system-wide CUDA installation and could verify that the shipped CUDA (math) libs from the conda binaries are used via rerunning your code with <code>LD_DEBUG=libs</code> or <code>LD_DEBUG=files</code>?</p>

yoshitomo-matsubara: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<p>Thank you for the response. For the additional runs, I created a separate, clean conda environment with Python 3.10 and <code>conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia</code></p>
<hr>
<blockquote>
<p>Are you seeing the same error using a single GPU run on device 1?</p>
</blockquote>
<p>I confirmed a similar error at <code>loss.backward()</code> when using another GPU on device 1, and here is the result, but the types of error I confirmed are very random (see below)</p>
<h3><a name="h-1st-attempt-1" class="anchor" href="#h-1st-attempt-1"></a>1st attempt</h3>
<pre data-code-wrap="shell"><code class="lang-shell">CUDA_VISIBLE_DEVICES=1 python3 train.py --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
</code></pre>
<pre><code class="lang-auto">Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 2.1175811290740967
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 22:26:56  lr: 0.1  img/s: 20.520931643439184  loss: 7.0542 (7.0542)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 2.0186  data: 0.4592  max mem: 8113
Traceback (most recent call last):
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 515, in &lt;module&gt;
    main(args)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 357, in main
    train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema, scaler)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 42, in train_one_epoch
    loss.backward()
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/_tensor.py", line 488, in backward
    torch.autograd.backward(
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/autograd/__init__.py", line 197, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: cuDNN error: CUDNN_STATUS_MAPPING_ERROR

</code></pre>
<h3><a name="h-2nd-attempt-the-same-command-as-the-1st-attempt-2" class="anchor" href="#h-2nd-attempt-the-same-command-as-the-1st-attempt-2"></a>2nd attempt (the same command as the 1st attempt)</h3>
<pre><code class="lang-auto">Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 1.1169238090515137
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 20:55:42  lr: 0.1  img/s: 24.125677096917588  loss: 7.0786 (7.0786)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.8818  data: 0.5554  max mem: 8113
ERROR: Unexpected segmentation fault encountered in worker.
Traceback (most recent call last):
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1120, in _try_get_data
    data = self._data_queue.get(timeout=timeout)
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/queue.py", line 180, in get
    self.not_empty.wait(remaining)
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/threading.py", line 324, in wait
    gotit = waiter.acquire(True, timeout)
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/_utils/signal_handling.py", line 66, in handler
    _error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 21853) is killed by signal: Segmentation fault. 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 515, in &lt;module&gt;
    main(args)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 357, in main
    train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema, scaler)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 25, in train_one_epoch
    for i, (image, target) in enumerate(metric_logger.log_every(data_loader, args.print_freq, header)):
  File "/home/yoshitomo/workspace/vision/references/classification/utils.py", line 127, in log_every
    for obj in iterable:
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 628, in __next__
    data = self._next_data()
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1316, in _next_data
    idx, data = self._get_data()
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1272, in _get_data
    success, data = self._try_get_data()
  File "/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1133, in _try_get_data
    raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e
RuntimeError: DataLoader worker (pid(s) 21853) exited unexpectedly
</code></pre>
<h3><a name="h-3rd-attempt-the-same-command-as-the-1st-attempt-3" class="anchor" href="#h-3rd-attempt-the-same-command-as-the-1st-attempt-3"></a>3rd attempt (the same command as the 1st attempt)</h3>
<pre><code class="lang-auto">Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 1.1333832740783691
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 20:50:47  lr: 0.1  img/s: 23.016705314304588  loss: 7.1780 (7.1780)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.8745  data: 0.4842  max mem: 8113
Segmentation fault (core dumped)
</code></pre>
<h3><a name="h-4th-attempt-the-same-command-as-the-1st-attempt-4" class="anchor" href="#h-4th-attempt-the-same-command-as-the-1st-attempt-4"></a>4th attempt (the same command as the 1st attempt)</h3>
<pre><code class="lang-auto">Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 1.1250081062316895
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 21:04:39  lr: 0.1  img/s: 22.555012256576262  loss: 7.0077 (7.0077)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.8952  data: 0.4765  max mem: 8113
Traceback (most recent call last):
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 515, in &lt;module&gt;
    main(args)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 357, in main
    train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema, scaler)
  File "/home/yoshitomo/workspace/vision/references/classification/train.py", line 53, in train_one_epoch
    acc1, acc5 = utils.accuracy(output, target, topk=(1, 5))
  File "/home/yoshitomo/workspace/vision/references/classification/utils.py", line 181, in accuracy
    _, pred = output.topk(maxk, 1, True, True)
RuntimeError: CUDA error: unspecified launch failure
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
</code></pre>
<hr>
<blockquote>
<p>Also, do you have any system-wide CUDA installation and could verify that the shipped CUDA (math) libs from the conda binaries are used via rerunning your code with <code>LD_DEBUG=libs</code> or <code>LD_DEBUG=files</code> ?</p>
</blockquote>
<p>I installed the following CUDA and NVIDIA packages before conda</p>
<ul>
<li>NVIDIA-SMI 515.86.01</li>
<li>Driver Version: 515.86.01</li>
<li>CUDA Version: 11.7</li>
</ul>
<p>Here are the results I got using <code>LD_DEBUG=libs</code> and <code>LD_DEBUG=files</code> when running the same script using device 1.</p>
<h3><a name="ld_debuglibs-5" class="anchor" href="#ld_debuglibs-5"></a>LD_DEBUG=libs</h3>
<pre data-code-wrap="shell"><code class="lang-shell">LD_DEBUG=libs CUDA_VISIBLE_DEVICES=1 python3 train.py --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
</code></pre>
<p>Last 10 lines (too long to share the entire log as it reaches maximum char limit)</p>
<pre><code class="lang-auto">      7199:	
      7199:	find library=libcudnn_cnn_train.so.8 [0]; searching
      7199:	 search path=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib:/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../..		(RPATH from file /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libtorch_global_deps.so)
      7199:	  trying file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_train.so.8
      7199:	
      7199:	
      7199:	calling init: /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_train.so.8
      7199:	
Epoch: [0]  [    0/40037]  eta: 21:45:00  lr: 0.1  img/s: 23.317420051096974  loss: 7.1894 (7.1894)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.9557  data: 0.5833  max mem: 8113
Segmentation fault (core dumped)
</code></pre>
<h3><a name="ld_debugfiles-6" class="anchor" href="#ld_debugfiles-6"></a>LD_DEBUG=files</h3>
<pre data-code-wrap="shell"><code class="lang-shell">LD_DEBUG=files CUDA_VISIBLE_DEVICES=1 python3 train.py --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
</code></pre>
<p>Last 10 lines (too long to share the entire log as it reaches maximum char limit)</p>
<pre><code class="lang-auto">     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_train.so.8 [0]; direct_opencount=1
     10025:	
     10025:	opening file=/lib/x86_64-linux-gnu/libcuda.so.1 [0]; direct_opencount=11
     10025:	
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_train.so.8 [0]; direct_opencount=2
     10025:	
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_train.so.8 [0]; direct_opencount=3
     10025:	
Epoch: [0]  [    0/40037]  eta: 21:45:00  lr: 0.1  img/s: 23.317420051096974  loss: 7.1894 (7.1894)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 1.9557  data: 0.5833  max mem: 8113
Segmentation fault (core dumped)
</code></pre>

ptrblck: <p>Thank you very much for the outputs! The cuDNN location looks correct and uses the library shipped with PyTorch. Could you <code>grep</code> both debug outputs for <code>libcublas</code> and check which paths are used, please?</p>

yoshitomo-matsubara: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<p>Sure, of course.</p>
<p>grep libcublas for the log with LD_DEBUG=libs</p>
<pre><code class="lang-auto">      7199:	find library=libcublas.so.11 [0]; searching
      7199:	  trying file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libcublas.so.11
      7199:	  trying file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11
      7199:	find library=libcublasLt.so.11 [0]; searching
      7199:	  trying file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11
      7199:	calling init: /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11
      7199:	calling init: /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11
</code></pre>
<hr>
<p>grep libcublas for the log with LD_DEBUG=files</p>
<pre><code class="lang-auto">     10025:	file=libcublas.so.11 [0];  needed by /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libtorch_global_deps.so [0]
     10025:	file=libcublas.so.11 [0];  generating link map
     10025:	file=libcublasLt.so.11 [0];  needed by /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]
     10025:	file=libcublasLt.so.11 [0];  generating link map
     10025:	calling init: /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11
     10025:	file=libcuda.so.1 [0];  dynamically loaded by /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]
     10025:	calling init: /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11
     10025:	file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0];  needed by /home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/libtorch_cuda_cu.so [0] (relocation dependency)
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=1
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]; direct_opencount=1
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]; direct_opencount=2
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]; direct_opencount=3
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=2
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=3
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=4
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=5
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=6
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=7
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=8
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]; direct_opencount=4
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublas.so.11 [0]; direct_opencount=5
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=9
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=10
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=11
     10025:	opening file=/home/yoshitomo/anaconda3/envs/latest_torch/lib/python3.10/site-packages/torch/lib/../../../../libcublasLt.so.11 [0]; direct_opencount=12
</code></pre>

yoshitomo-matsubara: <p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
Did the above logs give you any clues?</p>
<p>I also reinstalled the OS (Ubuntu 22 LTS) and installed PyTorch 2.0, but the behavior looks similar to the previous one</p>
<pre><code class="lang-auto">CUDA_VISIBLE_DEVICES=0 python3 train.py --model resnet152 --data-path /home/yoshitomo/datasets/ilsvrc2012/ --print-freq 10000
Not using distributed mode
Namespace(data_path='/home/yoshitomo/datasets/ilsvrc2012/', model='resnet152', device='cuda', batch_size=32, epochs=90, workers=16, opt='sgd', lr=0.1, momentum=0.9, weight_decay=0.0001, norm_weight_decay=None, bias_weight_decay=None, transformer_embedding_decay=None, label_smoothing=0.0, mixup_alpha=0.0, cutmix_alpha=0.0, lr_scheduler='steplr', lr_warmup_epochs=0, lr_warmup_method='constant', lr_warmup_decay=0.01, lr_step_size=30, lr_gamma=0.1, lr_min=0.0, print_freq=10000, output_dir='.', resume='', start_epoch=0, cache_dataset=False, sync_bn=False, test_only=False, auto_augment=None, ra_magnitude=9, augmix_severity=3, random_erase=0.0, amp=False, world_size=1, dist_url='env://', model_ema=False, model_ema_steps=32, model_ema_decay=0.99998, use_deterministic_algorithms=False, interpolation='bilinear', val_resize_size=256, val_crop_size=224, train_crop_size=224, clip_grad_norm=None, ra_sampler=False, ra_reps=3, weights=None, distributed=False)
Loading data
Loading training data
Took 1.1291546821594238
Loading validation data
Creating data loaders
Creating model
Start training
Epoch: [0]  [    0/40037]  eta: 1 day, 10:38:15  lr: 0.1  img/s: 12.599543003028279  loss: 7.0343 (7.0343)  acc1: 0.0000 (0.0000)  acc5: 0.0000 (0.0000)  time: 3.1145  data: 0.5747  max mem: 10383
double free or corruption (out)
Aborted (core dumped)
</code></pre>

yoshitomo-matsubara: <p>I resolved the problem by</p>
<ol>
<li>installing Ubuntu 23.04 instead of Ubuntu 22</li>
<li>using the following CUDA and NVIDIA packages</li>
</ol>
<ul>
<li>NVIDIA-SMI 515</li>
<li>Driver Version: 515</li>
<li>CUDA Version: 11.7</li>
</ul>
<ol start="3">
<li>most importantly, tuning BIOS configs (enabling VT-d in BIOS was key for my machine)</li>
</ol>
<p>Only applying 1 and 2 to my machine didn’t resolve the issue.</p>

ZhuXY: <p>Hell, yoshitomo. I meet the same issues, but I am a user and can not to reinstall the OS and tune the BIOS. The issues will occur after a few epochs, so do you have another way to solve the problem?</p>

yoshitomo-matsubara: <p>Hello <a class="mention" href="/u/zhuxy">@ZhuXY</a> , Unfortunately, I don’t know any other solutions</p>