crowsonkb / style-transfer-pytorch

Neural style transfer in PyTorch.
MIT License
479 stars 115 forks source link

Multi-GPU allocation #13

Open jdumont0201 opened 3 years ago

jdumont0201 commented 3 years ago

Hi,

I'm trying to understand device allocation here. I have different GPUs capacities, and the program stops with OOM during backward() even when free space is available.

In the code, I see two critical parts for GPU alloc:

  1. In class StyleTransfer, you create a device plan to spead the load of the 27ish layers of VGG over GPUs.

    if len(self.devices) == 1:
            device_plan = {0: self.devices[0]}
        elif len(self.devices) == 2:
            device_plan = {0: self.devices[0], 5: self.devices[1]}

    meaning you send 5 first layers to GPU0 and all other to GPU1.

  2. In the stylize main loop, you actually send all images and styles to GPU0:

    self.image = self.image.to(self.devices[0])
content = content.to(self.devices[0]) 

so I'm not sure whether the load is spread at all during the backward descent.

How would you see a version where the load is spread evenly depending of each capacity?

Regards, J