pytorch
system_error
ai_generated
partial
运行时错误:DataLoader工作进程(pid 12345)收到信号11(段错误)。可能原因:共享内存耗尽或数据集内存损坏
RuntimeError: DataLoader worker (pid 12345) received signal 11 (Segmentation fault). Possible causes: shared memory exhausted or dataset memory corruption
ID: pytorch/dataloader-worker-segfault
85%修复率
82%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pytorch>=1.13 | active | — | — | — |
| torchvision>=0.14 | active | — | — | — |
| cuda>=11.7 | active | — | — | — |
| python>=3.8 | active | — | — | — |
根因分析
DataLoader工作进程因段错误崩溃,通常由于共享内存不足(Linux上/dev/shm太小)或数据集存在内存损坏错误(例如使用不可pickle对象的不安全多进程)。
English
A DataLoader worker process crashed with a segmentation fault, typically due to insufficient shared memory (on Linux, /dev/shm is too small) or a buggy dataset that corrupts memory (e.g., unsafe multiprocessing with non-picklable objects).
官方文档
https://pytorch.org/docs/stable/data.html#multi-process-data-loading解决方案
-
Increase shared memory size: In Docker, add --shm-size=8g; on bare metal, remount /dev/shm with larger size: sudo mount -o remount,size=8G /dev/shm
-
Reduce num_workers to 0 or 1 to avoid multiprocessing issues: DataLoader(..., num_workers=0)
-
Switch multiprocessing context to 'spawn' (instead of 'fork'): torch.multiprocessing.set_start_method('spawn', force=True)
无效尝试
常见但无效的做法:
-
Increasing num_workers to speed up data loading
90% 失败
More workers consume more shared memory, making the segfault more likely.
-
Using pin_memory=True without increasing shared memory
85% 失败
Pin memory also uses shared memory, exacerbating the exhaustion.