MultiGPU Training Discrepancy DP vs DDP

solarflarefx: <p>Hello,</p>
<p>I have been experimenting with multiple GPU training with 8 GPUs and I am running into some inconsistencies between my expected results and my actual results.  I have been experimenting with both Windows (Server 2019) and Ubuntu 18.04 LTS.  I have tried data parallel on both Windows and Ubuntu, and distributed data parallel on Ubuntu (single node + 8 GPUs).</p>
<p>I have run some metric tests to assess the speed of the training, which are shown below.  I am basing this on one epoch.</p>
<p>Windows Data Parallel: ~1000 ms / step<br>
Ubuntu Data Parallel: ~300 ms/step<br>
Ubuntu Distributed Data Parallel: ~350 ms/step</p>
<p>There are a few areas of confusion:</p>
<ol>
<li>
<p>Why does running the same code in Windows and Linux produce such different results?</p>
</li>
<li>
<p>I would expect distributed data parallel to be faster than data parallel or perhaps the same speed, but this is not the case in my situation.</p>
</li>
</ol>
<p>So perhaps the optimization of the parallelization is different on Windows versus Ubuntu and may explain the difference.  Though I am still surprised there is this much of a difference.</p>
<p>I am much more surprised at the difference between distributed data parallel and data parallel.  There could be a problem in how I am distributed the data in the distributed data parallelization approach.  My situation may be a bit atypical, but I am working with 3D data, but I am using patches of this data as the input.  So for example, a single 3D file may contain 30 patches.  I am using a custom dataset with a GetItem that based on a directory will load a 3d file.  Then I use a custom sampler that loads the patch indices and has an iterator that passes patches when called. I feed this sampler to the DistributedSampler, which goes to the Dataloader of the GPU process.</p>
<p>On the surface this appears to work without conflict, though in this scenario since different patches could be part of the same file, multiple GPU processes could be trying to access the same file at the same time.  To be honest I am not 100% sure if this is valid, though I believe the GPUs would be accessing the files in read-only mode, so I would think it would be ok.  However, would this cause inefficiency and delay?  Would I be better off distributing the 3D files among the GPU instead so multiple GPUs would not be accessing the same file?</p>
<p>I suppose that the overhead of distributing the work could also be a factor, but according to the PyTorch documentation, “Thus, even for single machine training, where your data is small enough to fit on a single machine, DistributedDataParallel is expected to be faster than DataParallel.” : <a href="https://pytorch.org/tutorials/intermediate/ddp_tutorial.html" rel="nofollow noopener">https://pytorch.org/tutorials/intermediate/ddp_tutorial.html</a></p>
<p>I will further note that I am using the native PyTorch distributed parallel library instead of NVIDIA Apex, but I am wondering if this would make a difference.</p>
<p>I could also experiment with the number of workers, but is there a general guideline on how to adjust this parameter on multiGPU training?</p>
<p>I would appreciate any insight and pointers.  Thanks in advance.</p>

solarflarefx: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, any insight on this?  Could it be due how I am loading the data?</p>

ptrblck: <p>I’m unfortunately not really familiar with Windows and cannot comment on the performance.</p>
<p>However, your point about Dataparallel vs. DDP is a valid concern.<br>
We usually see a better performance with DDP using a single process for each GPU, as the model is replicated only during the start and the GIL shouldn’t get in the way.</p>
<aside class="quote no-group" data-username="solarflarefx" data-post="1" data-topic="69797">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/898d66/48.png" class="avatar"> solarflarefx:</div>
<blockquote>
<p>I could also experiment with the number of workers, but is there a general guideline on how to adjust this parameter on multiGPU training?</p>
</blockquote>
</aside>
<p>How many workers are you using in each process? If you are using too many workers (processes), you might see an overall slowdown, so you could try to decrease this number and check the performance again. A general guideline is hard to give, as it depends on your used system.</p>