python - 哪些 tensorflow 操作会触发内存分配?

标签 python tensorflow machine-learning memory out-of-memory

阅读 TensorArray 的文档后类中,我遇到了这一行:

If True, the TensorArray will be colocated on the same device as the Tensor used on its first write (write operations include write, unstack, and split). If False, the TensorArray will be placed on the device determined by the device context available during its initialization.

这让我想知道是否只有某些操作才会触发实际的内存分配和读/写,以及是否有这些操作的列表。

我也想知道这一点,因为在创建暂时非常大的张量时,由于 OOM 错误而存在限制,但无论如何都会以批处理方式处理,因此程序不需要实际保存张量的所有数据- 类似于数据集 API 允许处理无限大型数据集,因为所有内容都是按需加载的。

最佳答案

从 Tensorflow-GPU 角度来看:没有列表。

TF 在 GPU 上运行有两种方式:

  • 没有 XLA
  • 与XLA

如果没有 XLA,一旦操作 A0 完成, tensorflow 将根据 A0 分配所有操作的内存:B0、B1、B2 等。一旦这些操作完成,TF 将释放不再需要的 A0 内存。如果您有卷积神经网络,您通常会保存所有前向路径激活,直到后向路径开始。

使用 XLA,可以将多个操作合并到 block 中。在 block 内,可以合并/拆分/复制操作以减少内存使用。 XLA 集群将有自己的内存管理例程,这取决于操作如何混合在一起。多个 XLA 集群将表现为多个非 XLA 操作:它们都会尽快启动,可能会导致次优峰值内存使用。

关于python - 哪些 tensorflow 操作会触发内存分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59841166/

相关文章:

tensorflow - TFRecords/TensorFlow 服务 : Converting TFRecords into (GRPC or RESTFul) TensorFlow Serving requests?

python - 尝试使用 conda 命令安装 tensorflow-gpu 时,当前 linux-64 channel 中缺少依赖项

python - 如何计算 tensorflow 中张量的形状

python - 对于我的数据,为什么基于树的学习算法的准确率只有50%左右?

python - 如何在 qt 应用程序上使用 cv2.waitKey 使用 'p' 键暂停和播放

python - 更新 ipython 后出现问题 (%matplotlib nbagg)

python - 为什么 esky 创建 2 个可执行文件?

python - 如何在保留填充的同时将填充的字符串转换为整数?

python - Pandas 数据框范围索引

python - Keras 中 RNN/LSTM 的 InvalidArgumentError