简体   繁体   English

限制 Tensorflow CPU 和内存使用

[英]Limit Tensorflow CPU and Memory usage

I've seen several questions about GPU Memory with Tensorflow but I've installed it on a Pine64 with no GPU support.我已经看到了几个关于带有 Tensorflow 的 GPU 内存的问题,但我已经将它安装在没有 GPU 支持的 Pine64 上。

That means I'm running it with very limited resources (CPU and RAM only) and Tensorflow seems to want it all, completely freezing my machine.这意味着我使用非常有限的资源(仅限 CPU 和 RAM)运行它,而 Tensorflow 似乎想要这一切,完全冻结了我的机器。


Is there a way to limit the amount of processing power and memory allocated to Tensorflow?有没有办法限制分配给 Tensorflow 的处理能力和内存量? Something similar to bazel's own --local_resources flag?类似于 bazel 自己的--local_resources标志?

This will create a session that runs one op at a time, and only one thread per op这将创建一个一次运行一个操作的会话,并且每个操作只有一个线程

sess = tf.Session(config=
    tf.ConfigProto(inter_op_parallelism_threads=1,
                   intra_op_parallelism_threads=1))

Not sure about limiting memory, it seems to be allocated on demand, I've had TensorFlow freeze my machine when my network wanted 100GB of RAM, so my solution was to make networks that need less RAM不确定是否限制内存,它似乎是按需分配的,当我的网络需要 100GB 的 RAM 时,我让 TensorFlow 冻结了我的机器,所以我的解决方案是使网络需要更少的 RAM

For TensorFlow 2.x this has been answered in the following thread :对于 TensorFlow 2.x,这已在以下线程中得到解答:

In Tensorflow 2.x, there is no session anymore.在 Tensorflow 2.x 中,不再有会话。 Directly use the config API to set the parallelism at the start of the program.在程序开始时直接使用 config API 设置并行度。

import tensorflow as tf

tf.config.threading.set_intra_op_parallelism_threads(2)
tf.config.threading.set_inter_op_parallelism_threads(2)
with tf.device('/CPU:0'):
    model = tf.keras.models.Sequential([...

https://www.tensorflow.org/api_docs/python/tf/config/threading https://www.tensorflow.org/api_docs/python/tf/config/threading

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM