Keras: How to specify the number of CPU cores used?

Created on 7 Jun 2015  路  6Comments  路  Source: keras-team/keras

I ran the otto example with CPU. It seems that keras (or theano?) uses all the CPU cores. Is there a way the specify the number of CPU cores used?

Most helpful comment

@tleeuwenburg, the latter. I set OMP_NUM_THREADS following the link you pointed out, and it works. Thanks.
@patyork, though I would love to enable the full parallelism, I have to spare some resources for other computational tasks running on the same machine :(

All 6 comments

In a cursory search, I could find nothing in Theano about setting the core count, and I was not expecting to.

Theano, and deep learning, is all about parallelism: do everything you can do in parallel. Limiting yourself to a subset of the things you can do in parallel, intentionally, goes against everything we hold dear. Personally, I'd give a finger and three toes to be able to run everything I wanted to in parallel; unlimited money can buy replacement toes but not additional time.

Hi Chenglong ... Are you on a single-cpu system with multiple cores, or a multi-cpu-multi-core system?

This page talks about how to set the number of threads.... http://deeplearning.net/software/theano/tutorial/multi_cores.html

I would presume one of those would get you where you need to be.

@tleeuwenburg, the latter. I set OMP_NUM_THREADS following the link you pointed out, and it works. Thanks.
@patyork, though I would love to enable the full parallelism, I have to spare some resources for other computational tasks running on the same machine :(

@patyork It's great that keras uses all available CPUs out of the box, but some of us who run on shared systems can't (or more correctly, aren't supposed to) grab all the available cores. Let's say you get assigned 16 cores on a 64-core node. It's very bad etiquette to launch a 64-core process, even though many scheduling systems will allow you to do so.

A switch in keras would therefore be nice to have.

I am running Keras on FreeBSD. TensorFlow was compiled following these instructions. Keras does not use all the cores and prints the message.

tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
can't determine number of CPU cores: assuming 4

This stackoverflow solution worked for me for putting CPU limits on Keras with TensorFlow backend

Was this page helpful?
0 / 5 - 0 ratings