Slow training, low memory usage on Tesla V100 16GB

asberman: <p>For my research, I’m running a GAN on <a href="https://www.floydhub.com/" rel="nofollow noopener">the deep learning online platform FloydHub</a>.</p>
<p>My DCGAN-based model uses 64x64 images from a data set of &gt;450k images, and my batch size is 128. The inputs to my generator and discriminator are constant (i.e. batches of 128 64x64 images). My local setup isn’t too powerful, and thankfully I have some research funds, so am trying to maximize the number of experiments I can run and thus am using the powerful but expensive Tesla V100 16GB GPU.</p>
<p>I do use <code>cuda</code>, and the GPU is found:</p>
<pre><code class="lang-auto">self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print("GPU/CPU:",torch.cuda.get_device_name(0)) 
# prints "GPU/CPU: GPU/CPU: Tesla V100-SXM2-16GB" 
</code></pre>
<p>I set call <code>.to(device)</code>, the new <code>.cuda()</code>, on my generator, discriminator, loss, noise and label tensors, as well as the fake and real images. When I checked, <code>cudnn.benchmark</code> was by default <code>True</code>. The <code>num_workers</code> of the <code>DataLoader</code> is <code>0</code>.</p>
<p>When I print the weights of generator layer or a discriminator layer, <code>device='cuda:0'</code> is included, so I know that these are using <code>cuda</code>.</p>
<p>However, my GPU usage hovers at <strong>around or below 40%</strong>, and a pass over the data set (3817 batches) takes &gt;10 minutes. I’d like to run for 100 epochs, but I’d prefer it didn’t take so long! I figure I must be doing something wrong/forgetting to <code>cuda</code> something (can’t think of what that would be though) or perhaps there’s some magic <code>cuda</code> or  <code>cudnn</code> flag I can set [although there doesn’t seem to be any documentation for <code>torch.backends.cudnn</code> !]</p>
<p>Any ideas? Or is this just how long training should take? Many thanks in advance.</p>

ptrblck: <p>Maybe your bottleneck is I/O bound.<br>
Could you try to increase the number of workers and see, if your training speeds up?<br>
You might also time your data loading using this example from the <a href="https://github.com/pytorch/examples/blob/0fadadceaafec430b3b1aa8a291d240dc9215f30/imagenet/main.py#L259">ImageNet training</a>.</p>

Andreas_Lu: <p>So I am using 4 V100s on one machine to train different network architectures (resnet152, pnasnet5large from Cadenes pretrainedmodels repo) and experience a similar behavior. The Scripts run in the latest nvidia pytorch container from <a href="https://docs.nvidia.com/deeplearning/dgx/pytorch-release-notes/running.html" rel="nofollow noopener">https://docs.nvidia.com/deeplearning/dgx/pytorch-release-notes/running.html</a>.</p>
<p>I can’t get the GPUs to 100% volatile GPU-utilization. It keeps hovering between 0 and 100% on my server.</p>
<p>I built my script upon the ImageNet training example and, at least for the pnasnet5large, I only get data timings of 0.000 and 0.001. This makes sense since I can only train with a batch size of 72 with the pnasnet5large.</p>
<p>I use a standard DataLoader to load the data from an SSD Raid 0 and tried everything between 4 and 24 workers.</p>
<p>As a sanity check I tried the setup with the plain main.py from the imageNet example and the GPUs would show the same utilization.</p>
<p>Do I miss something here? Do I need to use the multiprocessing-distributed settings to make use of the full power of these GPUs?</p>
<p>I tried to get it to work, but I get the following error:<br>
mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args))<br>
AttributeError: module ‘torch.multiprocessing’ has no attribute ‘spawn’</p>
<p>In relation to that I find a lot of posts stating that the problem is the PyTorch version in this case.<br>
The torch version in the NVIDIA container seems to be 1.0.0a0 so that can’t really be the reason.</p>
<p>I hope you can help me.<br>
Best regards,<br>
Andreas</p>

nabsabs: <p>hey <a class="mention" href="/u/andreas_lu">@Andreas_Lu</a>, did you happen to solve this?</p>

Andreas_Lu: <p>Unfortunately I didn’t find a solution for the problem. I used the Volta-DGX to conduct experiments for my thesis, so I stopped working with it when I turned it in.<br>
I tried quite a bit but didn’t get an improvement in GPU-utilization…<br>
If you happen to find a solution, let me know as I am eager to learn the cause of this as well…</p>

nabsabs: <p>oh that sucks! I am using the tesla-dgx and it seems training is a lot slower than my local machine <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=9" title=":frowning:" class="emoji" alt=":frowning:"></p>

ptrblck: <p><a class="mention" href="/u/andreas_lu">@Andreas_Lu</a>, <a class="mention" href="/u/nabsabs">@nabsabs</a><br>
I assume you are both using the DGX-1 with V100 GPUs?</p>
<p>Have you checked, if the data loading/processing might be the bottleneck in your setup?<br>
If so, I would suggest to have a look at <a href="https://github.com/NVIDIA/DALI" rel="nofollow noopener">DALI</a>, which should speedup the data processing pipeline.</p>
<p>PS: It should be already preinstalled in our containers.</p>