pytorch
resource_error
ai_generated
true
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
80%Fix Rate
85%Confidence
1Evidence
2023-09-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.10 | active | — | — | — |
| 1.11 | active | — | — | — |
| 1.12 | active | — | — | — |
| 1.13 | active | — | — | — |
| 2.0 | active | — | — | — |
| 2.1 | active | — | — | — |
| 2.2 | active | — | — | — |
| 2.3 | active | — | — | — |
Root Cause
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中文
DataLoader 工作进程数量过多且每个样本内存使用量高,导致系统 OOM killer 终止进程,尤其在使用大数据集或高分辨率图像时。
Official Documentation
https://pytorch.org/docs/stable/data.html#multi-process-data-loadingWorkarounds
-
90% success 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.
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.
-
75% success Use prefetch_factor to limit the number of batches prefetched per worker, reducing peak memory usage.
Use prefetch_factor to limit the number of batches prefetched per worker, reducing peak memory usage.
中文步骤
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.
Use prefetch_factor to limit the number of batches prefetched per worker, reducing peak memory usage.
Dead Ends
Common approaches that don't work:
-
70% fail
Increasing workers exacerbates memory pressure, causing more frequent OOM kills.
-
50% fail
This doesn't reduce per-worker memory; it just changes how data is split.