Keras: Specify number of cores to be used with tensorflow

Created on 7 Nov 2016  路  4Comments  路  Source: keras-team/keras

I am using keras on grid. There are many cores available, however I can't use all of them at same time. Therefore I would like to specify number of cores keras (tensorflow) can use. I have been looking for solution for quite some time. Is it possible?

Most helpful comment

Of course I found the solution after posting the question...

config = tf.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1, \
                        allow_soft_placement=True, device_count = {'CPU': 1})
session = tf.Session(config=config)
K.set_session(session)

All 4 comments

Python's GIL locks it to a single core per process. I believe TF supports asynchronous computation. Try putting train ops on separate threads

Of course I found the solution after posting the question...

config = tf.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1, \
                        allow_soft_placement=True, device_count = {'CPU': 1})
session = tf.Session(config=config)
K.set_session(session)

Of course I found the solution after posting the question...

config = tf.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1, \
                        allow_soft_placement=True, device_count = {'CPU': 1})
session = tf.Session(config=config)
K.set_session(session)

So this tells keras to use only 1 core, right? I would like to know if you set device_count = {'GPU':0} what would happen; will it use all detected CPU cores?

Why allow_soft_placement=True is needed?

https://stackoverflow.com/questions/44873273/what-do-the-options-in-configproto-like-allow-soft-placement-and-log-device-plac

And maybe it's needed to set device_count={'GPU': 0} also?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phipleg picture phipleg  路  60Comments

lmoesch picture lmoesch  路  89Comments

xieximeng2008 picture xieximeng2008  路  74Comments

wx405557858 picture wx405557858  路  71Comments

trane293 picture trane293  路  90Comments