Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Keras on multiple cores?

I'm using Keras with Tensorflow backend on a cluster (creating neural networks). How can I run it in a multi-threaded way on the cluster (on several cores) or is this done automatically by Keras? For example in Java one can create several threads, each thread running on a core.

If possible, how many cores should be used?

like image 860
BlackHawk Avatar asked Jan 11 '17 10:01

BlackHawk


People also ask

Can one process run on multiple cores?

Yes, a single process can run multiple threads on different cores. Caching is specific to the hardware. Many modern Intel processors have three layers of caching, where the last level cache is shared across cores.

Can TensorFlow use multiple CPUs?

Running TensorFlow on multicore CPUs can be an attractive option, e.g., where a workflow is dominated by IO and faster computational hardware has less impact on runtime, or simply where no GPUs are available. This talk will discuss which TensorFlow package to choose, and how to optimise performance on multicore CPUs.

Can I run keras on CPU?

Via TensorFlow (or Theano, or CNTK), Keras is able to run seamlessly on both CPUs and GPUs.

Does multi threading use multiple cores?

Multithreading : The ability of a central processing unit (CPU) (or a single core in a multi-core processor) to provide multiple threads of execution concurrently, supported by the operating system [3]. Multiprocessing: The use of two or more CPUs within a single computer system [4][5].


1 Answers

Tensorflow automatically runs the computations on as many cores as are available on a single machine.

If you have a distributed cluster, be sure you follow the instructions at https://www.tensorflow.org/how_tos/distributed/ to configure the cluster. (e.g. create the tf.ClusterSpec correctly, etc.)

To help debug, you can use the log_device_placement configuration options on the session to have Tensorflow print out where the computations are actually placed. (Note: this works for both GPUs as well as distributed Tensorflow.)

# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

Note that while Tensorflow's computation placement algorithm works fine for small computational graphs, you might be able to get better performance on large computational graphs by manually placing the computations in specific devices. (e.g. using with tf.device(...): blocks.)

like image 69
saeta Avatar answered Sep 28 '22 13:09

saeta