Keras/TF CPU creating too many threads

﹥>﹥吖頭↗ 提交于 2021-01-01 04:21:55

问题


Even after setting tf.config.threading.set_inter_op_parallelism_threads(1) and tf.config.threading.set_intra_op_parallelism_threads(1) Keras with Tensorflow CPU (running a simple CNN model fit) on a linux machine is creating too many threads. Whatever I try it seems to be creating 94 threads while going through the fitting epochs. Have tried playing with tf.compat.v1.ConfigProto settings but nothing helps. How do I limit the number of threads?


回答1:


This is why tensorflow created many threads.

Using the mentioned 2 types of parallelism (inter and intra) you have limited control over the number of threads generated by TensorFlow. The minimum number of threads that you can get by setting these two variables is N, where N is the number of cores on your cpu (I don't know if you use gpu).

intra_op_parallelism_threads = 1
inter_op_parallelism_threads = 1

Even by setting the environment variables OMP_NUM_THREADS and MKL_NUM_THREADS can't help in further reducing the number of threads.

The following discussions suggest that without changing the source code of TensorFlow, it is not possible to reduce the number threads below N.

  • How can I confine TensorFlow C API to use one and only one thread in total
  • How to disable Tensorflow's multi-threading?
  • How to stop TensorFlow from multi-threading
  • https://github.com/tensorflow/tensorflow/issues/42510
  • https://github.com/tensorflow/tensorflow/issues/33627


来源:https://stackoverflow.com/questions/62141945/keras-tf-cpu-creating-too-many-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!