Data parallel tutorial

Sharpy: <p>I’m struggling here with a multi-GPU setup with DataParallel, only getting 1.7x boost from 3 GPUs. If someone has any blind suggestions on how that can be improved, they would be appreciated. One thing I’ve noticed is that like 10x more PCIe bandwidth is used by PyTorch than by parallelized Keras+TF. Model is similar. I have very little idea why.</p>
<p>Anyway, I’m viewing this <a href="http://pytorch.org/tutorials/beginner/blitz/data_parallel_tutorial.html" rel="nofollow noopener">http://pytorch.org/tutorials/beginner/blitz/data_parallel_tutorial.html</a> tutorial and I’m seeing some <code>model.gpu()</code> and similar <code>.gpu()</code> stuff written there and it seems like it’s a mistake made by someone who wanted to write <code>.cuda()</code>?</p>

tjoseph: <p>Seems like it. Without code it is hard to say, why you don’t get more performance!</p>

Sharpy: <p>I’m guessing there may be some general suggestions and reasons. I’m getting a huge PCIe bandwidth even when I train on a single GPU - I think it’s 2x-4x that of Keras+TF. I have no clue why so much data is being sent when basically what seems reasonable to send is simply the input data and algorithmic instructions. I don’t think it’s got much to do with anything I do specifically, but more like what PyTorch is like in general <a href="https://discuss.pytorch.org/t/dataparallel-performance/1590">DataParallel performance?</a></p>
<p>It seems to me like some totally unnecessary stuff is being exchanged between CPU and GPUs and that’s just the way PyTorch currently is.</p>

Foivos_Diakogiannis: <p>Hi there,</p>
<p>am just starting with pytorch, but have you tried <a href="https://discuss.pytorch.org/t/pytorch-performance/3079">using</a> the flag: <code>torch.backends.cudnn.benchmark=True</code>. It should help (if you have a static architecture).</p>

Sharpy: <p>Thanks, that might help in the future. Didn’t change the speed this time, though, and it won’t influence PCIe traffic. It’s for autoselecting a faster algorithm for particular convolution parameters, as far as I understand.</p>

Sharpy: <p>One thing I very much wonder about is the example in the docs</p>
<pre><code class="lang-auto">model = Model(input_size, output_size)
if torch.cuda.device_count() &gt; 1:
  print("Let's use", torch.cuda.device_count(), "GPUs!")
  # dim = 0 [30, xxx] -&gt; [10, ...], [10, ...], [10, ...] on 3 GPUs
  model = nn.DataParallel(model)

if torch.cuda.is_available():
   model.cuda()

for data in rand_loader:
    if torch.cuda.is_available():
        input_var = Variable(data.cuda())
    else:
        input_var = Variable(data)

    output = model(input_var)
    print("Outside: input size", input_var.size(),
          "output_size", output.size())
</code></pre>
<p>when and where is the data actually transfered? Are we first transferring to say GPU0 with <code>data.cuda()</code> and later back to the CPU and from CPU to the other GPUs when DataParallel takes that input?</p>
<p>That’s quite an important question. And also what about similar stuff about loss, backward pass and loss weights.</p>

Sharpy: <p>When Keras+TF utilizes some 2% of PCIe bandwidth when training on a single GPU, PyTorch will easily chew up 20x that amount.</p>

Sharpy: <p>I’m not sure which of the things that I’ve tweaked did that, I’m guessing, maybe, removal of unpooling with pool indices - I’ll test that later, but PCIe usage has by now dropped for me to same Keras-level 1-3%. And, of course, scaling efficiency went up.</p>

Sharpy: <p>PCIE usage problem is back for me for some reason. Anybody tackled this issue? Running on a single GPU here with no pool indices. PCIE 16x loaded by some 45%. No clue why. If there’s any way to debug and find out what’s being transferred that would be cool.</p>

taehyunzzz: <p>How are you measuring PCIe bandwidth?</p>