PRF
tensorflow
resource_error
ai_generated
partial
资源耗尽错误:无法为预取队列分配内存
ResourceExhaustedError: Failed to allocate memory for prefetch queue
ID: tensorflow/resource-exhausted-dataset-prefetch
80%修复率
84%置信度
1证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| tensorflow 2.14.0 | active | — | — | — |
| tensorflow 2.16.0 | active | — | — | — |
根因分析
tf.data管道的预取缓冲区消耗过多内存,通常是由于数据集元素过大或预取大小过大。
English
The tf.data pipeline's prefetch buffer consumes too much memory, often due to large dataset elements or excessive prefetch size.
官方文档
https://www.tensorflow.org/guide/data_performance解决方案
-
Reduce prefetch buffer size: dataset = dataset.prefetch(buffer_size=tf.data.AUTOTUNE) or set a fixed small value like 1.
-
Use dataset.cache() to store processed elements on disk instead of memory.
-
Reduce element size by batching smaller or using lower-resolution images.
无效尝试
常见但无效的做法:
-
70% 失败
Increasing overall GPU memory limit doesn't target prefetch buffer specifically.
-
50% 失败
Using more CPU cores for mapping can increase memory usage.