Error: torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate more than 1EB memory

username: nero1
cooked: <p>I’m using pytorch lighting DDP training with batch size = 16, 8 (gpu per node) * 2 (2 nodes) = 16 total gpus. However, I got the following<br>
error, which happens in ModelCheckpoint callback. There seems to be an error during synchronization between nodes when saving the model checkpoint. And I decreased the batch size to 4 and this error disappeared. Can anyone help me?</p>
<pre><code class="lang-auto">    callbacks:
      - type: ModelCheckpoint
        every_n_train_steps: 2000
        save_top_k: 30
        monitor: "step"
        filename: "checkpoint_{epoch}-{step}"
</code></pre>
<p>Stack:</p>
<pre><code class="lang-auto">[rank2]: Traceback (most recent call last):
[rank2]:   File "/workspace/weiyh2@xiaopeng.com/xpilot_vision/ai_foundation/projects/e2e_aeb/main.py", line 130, in &lt;module&gt;
[rank2]:     main()
[rank2]:   File "/workspace/weiyh2@xiaopeng.com/xpilot_vision/ai_foundation/projects/e2e_aeb/main.py", line 121, in main
[rank2]:     runner.train(resume_from=ckpt_path)
[rank2]:   File "/workspace/weiyh2@xiaopeng.com/xpilot_vision/ai_foundation/projects/e2e_aeb/flow/runner/xflow_runner.py", line 38, in train
[rank2]:     self.trainer.fit(
[rank2]:   File "/workspace/weiyh2@xiaopeng.com/xpilot_vision/ai_foundation/xflow/xflow/lightning/trainer/xflow_trainer.py", line 356, in fit
[rank2]:     super().fit(
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/trainer.py", line 543, in fit
[rank2]:     call._call_and_handle_interrupt(
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/call.py", line 43, in _call_and_handle_interrupt
[rank2]:     return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/strategies/launchers/subprocess_script.py", line 105, in launch
[rank2]:     return function(*args, **kwargs)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/trainer.py", line 579, in _fit_impl
[rank2]:     self._run(model, ckpt_path=ckpt_path)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/trainer.py", line 986, in _run
[rank2]:     results = self._run_stage()
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/trainer.py", line 1030, in _run_stage
[rank2]:     self.fit_loop.run()
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/loops/fit_loop.py", line 206, in run
[rank2]:     self.on_advance_end()
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/loops/fit_loop.py", line 378, in on_advance_end
[rank2]:     call._call_callback_hooks(trainer, "on_train_epoch_end", monitoring_callbacks=True)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/trainer/call.py", line 210, in _call_callback_hooks
[rank2]:     fn(trainer, trainer.lightning_module, *args, **kwargs)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 323, in on_train_epoch_end
[rank2]:     self._save_topk_checkpoint(trainer, monitor_candidates)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 383, in _save_topk_checkpoint
[rank2]:     self._save_monitor_checkpoint(trainer, monitor_candidates)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 703, in _save_monitor_checkpoint
[rank2]:     self._update_best_and_save(current, trainer, monitor_candidates)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 732, in _update_best_and_save
[rank2]:     filepath = self._get_metric_interpolated_filepath_name(monitor_candidates, trainer, del_filepath)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 661, in _get_metric_interpolated_filepath_name
[rank2]:     while self.file_exists(filepath, trainer) and filepath != del_filepath:
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 774, in file_exists
[rank2]:     return trainer.strategy.broadcast(exists)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/lightning/pytorch/strategies/ddp.py", line 307, in broadcast
[rank2]:     torch.distributed.broadcast_object_list(obj, src, group=_group.WORLD)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/torch/distributed/c10d_logger.py", line 75, in wrapper
[rank2]:     return func(*args, **kwargs)
[rank2]:   File "/usr/local/lib/python3.10/dist-packages/torch/distributed/distributed_c10d.py", line 2636, in broadcast_object_list
[rank2]:     object_tensor = torch.empty(  # type: ignore[call-overload]
[rank2]: torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate more than 1EB memory.
</code></pre>

username: ptrblck
cooked: <p>Which PyTorch release are you using?</p>

username: nero1
cooked: <h3><a name="p-463839-versions-1" class="anchor" href="#p-463839-versions-1"></a>Versions</h3>
<p>PyTorch version: 2.3.0a0+6ddf5cf85e.nv24.04<br>
Is debug build: False<br>
CUDA used to build PyTorch: 12.4<br>
ROCM used to build PyTorch: N/A</p>
<p>OS: Ubuntu 22.04.4 LTS (x86_64)<br>
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0<br>
Clang version: 14.0.0-1ubuntu1.1<br>
CMake version: version 3.29.0<br>
Libc version: glibc-2.35</p>
<p>Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime)<br>
Python platform: Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.35<br>
Is CUDA available: True<br>
CUDA runtime version: 12.4.131<br>
CUDA_MODULE_LOADING set to: LAZY<br>
GPU models and configuration: GPU 0: NVIDIA A800-SXM4-80GB<br>
Nvidia driver version: 470.199.02<br>
cuDNN version: Probably one of the following:<br>
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.1.0<br>
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.1.0<br>
HIP runtime version: N/A<br>
MIOpen runtime version: N/A<br>
Is XNNPACK available: True</p>
<p>CPU:<br>
Architecture: x86_64<br>
CPU op-mode(s): 32-bit, 64-bit<br>
Address sizes: 46 bits physical, 57 bits virtual<br>
Byte Order: Little Endian<br>
CPU(s): 128<br>
On-line CPU(s) list: 0-127<br>
Vendor ID: GenuineIntel<br>
Model name: Intel(R) Xeon(R) Platinum 8369B CPU @ 2.90GHz<br>
CPU family: 6<br>
Model: 106<br>
Thread(s) per core: 2<br>
Core(s) per socket: 32<br>
Socket(s): 2<br>
Stepping: 6<br>
CPU max MHz: 3500.0000<br>
CPU min MHz: 800.0000<br>
BogoMIPS: 5800.00<br>
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 aperfmperf eagerfpu 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 epb cat_l3 invpcid_single intel_pt ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq md_clear pconfig spec_ctrl intel_stibp flush_l1d arch_capabilities<br>
Virtualization: VT-x<br>
L1d cache: 3 MiB (64 instances)<br>
L1i cache: 2 MiB (64 instances)<br>
L2 cache: 80 MiB (64 instances)<br>
L3 cache: 96 MiB (2 instances)<br>
NUMA node(s): 2<br>
NUMA node0 CPU(s): 0-31,64-95<br>
NUMA node1 CPU(s): 32-63,96-127<br>
Vulnerability Itlb multihit: Not affected<br>
Vulnerability L1tf: Not affected<br>
Vulnerability Mds: Not affected<br>
Vulnerability Meltdown: Not affected<br>
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp<br>
Vulnerability Spectre v1: Mitigation; Load fences, usercopy/swapgs barriers and __user pointer sanitization<br>
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB<br>
Vulnerability Srbds: Not affected<br>
Vulnerability Tsx async abort: Not affected</p>
<p>Versions of relevant libraries:<br>
[pip3] cudnn==1.1.2<br>
[pip3] efficientnet-pytorch==0.7.1<br>
[pip3] mypy-extensions==1.0.0<br>
[pip3] numpy==1.24.4<br>
[pip3] nvtx==0.2.5<br>
[pip3] onnx==1.16.0<br>
[pip3] onnxruntime==1.16.0<br>
[pip3] optree==0.11.0<br>
[pip3] pynvjitlink==0.1.13<br>
[pip3] pytorch-lightning==2.4.0<br>
[pip3] pytorch-quantization==2.1.2<br>
[pip3] pytorch-triton==3.0.0+a9bc1a364<br>
[pip3] torch==2.3.0a0+6ddf5cf85e.nv24.4<br>
[pip3] torch-scatter==2.1.2<br>
[pip3] torch-tensorrt==2.3.0a0<br>
[pip3] torchdata==0.7.1a0<br>
[pip3] torchmetrics==1.4.2<br>
[pip3] torchtext==0.17.0a0<br>
[pip3] torchvision==0.18.0a0<br>
[conda] Could not collect</p>