pytorch resource_error ai_generated true

RuntimeError: DataLoader 工作进程 (pid 12345) 收到信号 9 (SIGKILL)。可能原因:内存不足或达到系统限制。

RuntimeError: DataLoader worker (pid 12345) received signal 9 (SIGKILL). Possible causes: out of memory or system limit reached.

ID: pytorch/dataloader-num-workers-memory-leak

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
1证据数
2023-09-05首次发现

版本兼容性

版本状态引入弃用备注
1.10 active
1.11 active
1.12 active
1.13 active
2.0 active
2.1 active
2.2 active
2.3 active

根因分析

DataLoader 工作进程数量过多且每个样本内存使用量高,导致系统 OOM killer 终止进程,尤其在使用大数据集或高分辨率图像时。

English

Too many DataLoader workers with high memory usage per sample cause the system OOM killer to terminate workers, especially when using large datasets or high-resolution images.

generic

官方文档

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

解决方案

  1. Reduce num_workers to a lower value, e.g., 2 or 4, or set to 0 for single-process loading to eliminate worker memory overhead.
  2. Use prefetch_factor to limit the number of batches prefetched per worker, reducing peak memory usage.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Increasing workers exacerbates memory pressure, causing more frequent OOM kills.

  2. 50% 失败

    This doesn't reduce per-worker memory; it just changes how data is split.