Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying CPUs for use in Keras Tensorflow Model Inference

Alright. I know that we can limit the number of cores used by a Keras (TF backend) model by using the following method:

 K.set_session(K.tf.Session(config=K.tf.ConfigProto(intra_op_parallelism_threads=2, inter_op_parallelism_threads=2,  device_count = {'CPU': 2})))

And we can specify individual tensor operations like this:

with tf.device('/cpu:0'):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')

But what if we want to specify a list of individual CPUs to be used by the Keras model?

like image 455
Steven Avatar asked Dec 14 '18 19:12

Steven


1 Answers

I don't think you can change processor affinity in Tensorflow, that's the level of operating system.

However, Linux has an useful tool taskset to help you.

For example,

taskset --cpu-list 0,1 python3 main.py

will assign core 0 and core 1 to the process that runs python3 main.py.

You can verify that with htop.

like image 200
Tay2510 Avatar answered Oct 31 '22 01:10

Tay2510