Segmentation fault torch::CudaIPCSentData::~CudaIPCSentData()

Quoding: <p>Hi,</p>
<p>I’ve been faced with a consistent segmentation fault which seems to depend on the wall-time length of a script I am running and possibly the number of workers. I have tried parallelizing my code with <code>torch.multiprocessing</code> invoking a Pool that is created at the beginning of my script and then <code>.close()</code>ed and <code>.join()</code>ed at the end of the script without fail. If I run with 1 worker, the program does not seem to crash (but since it might be wall-time depending, I am not certain multiprocessing is the issue).</p>
<p>However, it seems that I get a segmentation fault AT THE EXIT of my program:</p>
<pre data-code-wrap="python"><code class="lang-python">if __name__ == "__main__":
    main()
    print("dummy print to show i crash not in the main()") 
    # &lt;--- I crash here
</code></pre>
<p>I use Hydra (with or without sweepers and launcher, segfault occurs) to launch my jobs, but Hydra does not seem to be the problem.</p>
<p>I ran the script in gdb, this is the error I get thrown:</p>
<pre><code class="lang-auto">0x00007fff55e58cf1 in torch::CudaIPCSentData::~CudaIPCSentData() () from /home/quoding/.pyenv/versions/gfn_new/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so
</code></pre>
<p>Here is the backtrace from <code>gdb</code> (was too long, apparently, so I hosted it):<br>
<a href="https://paste.c-net.org/FelonUnpack" class="onebox" target="_blank" rel="noopener nofollow ugc">https://paste.c-net.org/FelonUnpack</a></p>
<p>Environment:</p>
<pre data-code-wrap="PyTorch"><code class="lang-PyTorch">Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 12 (bookworm) (x86_64)
GCC version: (Debian 12.2.0-14) 12.2.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.36

Python version: 3.11.9 (main, Jul 17 2024, 13:38:22) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-6.1.0-18-amd64-x86_64-with-glibc2.36
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4090
Nvidia driver version: 535.183.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:                      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(s) scaling MHz:                 51%
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 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb 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 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 Retbleed:             Not affected
Vulnerability Spec rstack overflow: 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==2.0.0
[pip3] torch==2.3.1+cu118
[pip3] torch_cluster==1.6.3+pt23cu118
[pip3] torch_geometric==2.5.3
[pip3] torch-graphgen==1.0.2
[pip3] torch_scatter==2.1.2+pt23cu118
[pip3] torch_sparse==0.6.18+pt23cu118
[pip3] torch_spline_conv==1.2.2+pt23cu118
[pip3] torchaudio==2.3.1+cu118
[pip3] torchvision==0.18.1+cu118
[pip3] triton==2.3.1
[conda] Could not collect
</code></pre>
<p>It seems to me that the segmentation fault happens because something that does not exist is trying to get deallocated by a piece of code withing <code>torch</code>.</p>
<p>This happens on Debian 12 Bookworm (Kernel: 6.1.0-18-amd64), running an RTX 4090.</p>
<p>Any help would be greatly appreciated. If you need more info, tell me what to retrieve and I will get it.</p>
<p>Thanks,<br>
Quoding</p>