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

ID: pytorch/dataloader-worker-segfault-shared-memory

其他格式: JSON · Markdown 中文 · English
75%修复率
82%置信度
1证据数
2024-07-10首次发现

版本兼容性

版本状态引入弃用备注
pytorch>=1.10.0 active
linux active

根因分析

共享内存(/dev/shm)已满或太小,无法容纳 DataLoader 工作进程传输的数据,通常由于批量大小过大或高分辨率图像。

English

The shared memory (/dev/shm) is full or too small to accommodate the data being transferred from DataLoader workers, often due to large batch sizes or high-resolution images.

generic

官方文档

https://pytorch.org/docs/stable/data.html#multi-process-data-loading

解决方案

  1. 通过重新挂载增加 /dev/shm 的大小。在 Docker 中使用 --shm-size=8g。在裸机上编辑 /etc/fstab 或使用 mount -o remount,size=8G /dev/shm。
  2. 减少批量大小或在 DataLoader 中使用 pin_memory=False,避免将张量复制到固定内存,这使用共享内存。

无效尝试

常见但无效的做法:

  1. 40% 失败

    This is a workaround that changes behavior, but it doesn't fix the underlying shared memory limit.

  2. 90% 失败

    Larger batches increase shared memory usage, exacerbating the issue.

  3. 70% 失败

    Shared memory is recreated at boot, but the limit remains the same; it will fill up again.