faceswap icon indicating copy to clipboard operation
faceswap copied to clipboard

Multi-GPU training

Open BeatHarness opened this issue 8 years ago • 16 comments

I've read reports of people succesfully training on multiple GPU'S using the following code:

from keras.utils import multi_gpu_model  

autoencoder_A = multi_gpu_model( autoencoder_A ,2)  
autoencoder_B = multi_gpu_model( autoencoder_B ,2)  

https://keras.io/utils/#multi_gpu_model

I could add support for this but I can't test it as I only have a single GPU. Anyobe here with a multi-GPU setup that would like to have a go at this?

BeatHarness avatar Feb 08 '18 08:02 BeatHarness

What you can do is add it to a source file, and make a PR. So people with multi GPU will be able to try and give you feedback. I did that for #140 . Maybe the feedback will be slow as not everyone is checking pull requests, but at least it will be more practical to test and iterate over it

Clorr avatar Feb 08 '18 10:02 Clorr

You'd probably want to try a:

from tensorflow.python.client import device_lib
count_gpu = len([d for d in device_lib.list_local_devices() if d.device_type=='GPU' ] )

To check that count_gpu > 1 and use that number as the second parameter for multi_gpu_model before attempting to replace the autoencoders with wrapped versions.

dfaker avatar Feb 09 '18 13:02 dfaker

@IUsedToBeAPygmy It certainly works for me to use the above arguments, but you have to change "autoencoder" to "self.autoencoder" which may be fairly obvious to you guys who program all the time, but it took me a while to figure that out. Uses all 12 GB of video memory and splits the load between the two GPU's. Now the model.original file looks like this: at the top: from keras.utils import multi_gpu_model

self.autoencoder_A` = KerasModel(x, self.decoder_A(self.encoder(x)))
self.autoencoder_B = KerasModel(x, self.decoder_B(self.encoder(x))
self.autoencoder_A = multi_gpu_model( self.autoencoder_A ,2)
self.autoencoder_B = multi_gpu_model( self.autoencoder_B ,2)

The question is, what will this argument do if you just have one gpu? will it cause an error to include in as a general inclusion or should there be a model.multigpu file option to include? This is my first post on here, so hopefully not to lame.

kellurian avatar Feb 11 '18 17:02 kellurian

@kellurian For me when I tried this solution I had to dramatically drop my ENCODER_DIM number to not get an OOM error, is this expected?

kevin-shannon avatar Feb 15 '18 08:02 kevin-shannon

Not for me. I did not have to change any of the values for it to work. Don’t know if it mattered but I had already upgraded ther version of tensorflow to 1.5 before starting this, but I have also now gone to CUDA 9 without problems as well. What two GPU’s are you running?

kellurian avatar Feb 15 '18 13:02 kellurian

@kellurian I'm running on two 970's with tensorflow 1.4 and CUDA 8. I'll try upgrading. Running on 1 gpu my encoderdim was 512 but on two its 128.

kevin-shannon avatar Feb 15 '18 20:02 kevin-shannon

seems like updating fixed it.

kevin-shannon avatar Feb 16 '18 03:02 kevin-shannon

I just modified the model_original.py file as above and it works fine for me. The only issue I have had is that you can’t turn on the “allow growth” option which seems to bigger out and error when it’s enabled. Otherwise it seems to run on both cards equally and take up both vram per resource monitor

Sent from my iPhone

On Mar 1, 2018, at 3:01 AM, Ashwin [email protected] wrote:

@kellurian or anyone who has this implemented, Could you please advise which files need to be changed to implement training with multiple gpu's Do I need to make changes to the training script or does this change need to be made in keras? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

kellurian avatar Mar 01 '18 15:03 kellurian

@kellurian can you do a PR of that? it would be even more useful to users...

Clorr avatar Mar 01 '18 16:03 Clorr

Yeah I will try. I am quite new to this github thing but I’ll work on it tonight

Sean

Sent from my iPhone

On Mar 1, 2018, at 11:15 AM, Clorr [email protected] wrote:

@kellurian can you di a PR of that? it would be even more useful to users...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

kellurian avatar Mar 01 '18 17:03 kellurian

Bah on github, you can directly edit the file, it will make a PR

Clorr avatar Mar 01 '18 17:03 Clorr

@kellurian Cheers! I was slightly confused, as you said that you changed "model.original file" earlier but figured that you may have meant model_original. Also, I can confirm that it works.
I can test the modified file on a single gpu device and will let you know if it works or not.

nigh8w0lf avatar Mar 01 '18 22:03 nigh8w0lf

Yeah sorry. I am a complete neophyte at this. And I am about to leave for a conference. When I get to the hotel I will look over things on my laptop and try to make it clearer. Sorry.

Sent from my iPhone

On Mar 1, 2018, at 5:14 PM, Ashwin [email protected] wrote:

@kellurian Cheers! I was slightly confused, as you said that you changed "model.original file" earlier but figured that you may have meant model_original. Also, I can confirm that it works. I can test the modified file on a single gpu device and will let you know if it works or not.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

kellurian avatar Mar 01 '18 22:03 kellurian

@kellurian Naah All good mate, It's pretty clear now.

By the way I have tested with the changed model_original.py file on a single gpu machine and it came up with the below:

ValueError: To call multi_gpu_model with gpus=2, we expect the following devices to be available: ['/cpu:0', '/gpu:0', '/gpu:1']. However this machine only has: ['/cpu:0', '/gpu:0']. Try reducing gpus.

I think model_multigpu file option would be the way to go.

nigh8w0lf avatar Mar 02 '18 02:03 nigh8w0lf

I think that would be the way to go as well, such as a plug-in option like the low mem or gan and selectable at the command line?

Sent from my iPhone

On Mar 1, 2018, at 9:00 PM, Ashwin [email protected] wrote:

Naah All good mate, It's pretty clear now.

By the way I have tested with the changed model_original.py file on a single gpu machine and it came up with the below:

ValueError: To call multi_gpu_model with gpus=2, we expect the following devices to be available: ['/cpu:0', '/gpu:0', '/gpu:1']. However this machine only has: ['/cpu:0', '/gpu:0']. Try reducing gpus.

I think model_multigpu file option would be the way to go.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

kellurian avatar Mar 02 '18 04:03 kellurian

See #241 (temporary PR until we have a more generic PR)

Clorr avatar Mar 10 '18 10:03 Clorr