# How to train more models on 2 GPUs with Keras?

I got 2 GPUs of type NVIDIA GTX 1070 Ti. I would like to train more models on them in such a way that half of the models are trained on one GPU only, and half on the other, at the same time. So as training goes, one model goes to GPU1, the next model goes to GPU2, ... I don't want to train one model on the two GPUs. I use Keras - Python with TensorFlow back-end. Can you please recommend resources where I can see how to do this? Most examples/articles online cover the case only if you want to distribute one model on the two GPUs. Thank you.

I would just create two separate scripts with one set of models that target one gpu and the other set of models target the other gpu. Then run the scripts as separate processes.That would easily get around Python's GIL.

• I just saw you edited your response, as I was writing :) so the second approach with for loop in one notebook / file only is not possible?
– user68541
Mar 13 '19 at 1:06
• I thought about it... the training for the first model will have to finish before the second model starts. Python executes commands in order and typically waits for the command to finish before continuing. Mar 13 '19 at 12:29

I believe new-Tensorflow 2.0 alpha, released last week has this feature

https://www.tensorflow.org/guide/using_gpu

On a typical system, there are multiple computing devices. In TensorFlow, the supported device types are CPU and GPU. They are represented as strings. For example:

"/cpu:0": The CPU of your machine.
"/device:GPU:0": The GPU of your machine, if you have one.
"/device:GPU:1": The second GPU of your machine, etc.