# Data parallel tutorial

**URL:** <https://discuss.pytorch.org/t/data-parallel-tutorial/15257>\
**Category:** Site Feedback\
**Created:** [March 21, 2018, 10:31am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257 "2018-03-21T10:31:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 21, 2018, 10:31am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/1 "2018-03-21T10:31:27Z")

</div>

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.

Anyway, I’m viewing this [http://pytorch.org/tutorials/beginner/blitz/data\_parallel\_tutorial.html](http://pytorch.org/tutorials/beginner/blitz/data_parallel_tutorial.html) tutorial and I’m seeing some `model.gpu()` and similar `.gpu()` stuff written there and it seems like it’s a mistake made by someone who wanted to write `.cuda()`?

---

<div class="post-metadata">

**Author:** ![tjoseph](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tjoseph/32/11927_2.png) [@tjoseph](https://discuss.pytorch.org/u/tjoseph)\
**Post date:** [March 21, 2018, 10:55am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/2 "2018-03-21T10:55:26Z")

</div>

Seems like it. Without code it is hard to say, why you don’t get more performance!

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 21, 2018, 11:07am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/3 "2018-03-21T11:07:18Z")

</div>

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 [DataParallel performance?](https://discuss.pytorch.org/t/dataparallel-performance/1590)

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.

---

<div class="post-metadata">

**Author:** ![Foivos\_Diakogiannis](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/foivos_diakogiannis/32/6787_2.png) [@Foivos\_Diakogiannis](https://discuss.pytorch.org/u/Foivos_Diakogiannis)\
**Post date:** [March 21, 2018, 11:13am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/4 "2018-03-21T11:13:49Z")

</div>

Hi there,

am just starting with pytorch, but have you tried [using](https://discuss.pytorch.org/t/pytorch-performance/3079) the flag: `torch.backends.cudnn.benchmark=True`. It should help (if you have a static architecture).

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 21, 2018, 11:24am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/5 "2018-03-21T11:24:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 21, 2018, 1:24pm UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/6 "2018-03-21T13:24:19Z")

</div>

One thing I very much wonder about is the example in the docs

```auto
model = Model(input_size, output_size)
if torch.cuda.device_count() > 1:
  print("Let's use", torch.cuda.device_count(), "GPUs!")
  # dim = 0 [30, xxx] -> [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())

```

when and where is the data actually transfered? Are we first transferring to say GPU0 with `data.cuda()` and later back to the CPU and from CPU to the other GPUs when DataParallel takes that input?

That’s quite an important question. And also what about similar stuff about loss, backward pass and loss weights.

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 21, 2018, 11:35pm UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/7 "2018-03-21T23:35:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 23, 2018, 10:45pm UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/8 "2018-03-23T22:45:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sharpy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sharpy/32/5129_2.png) [@Sharpy](https://discuss.pytorch.org/u/Sharpy)\
**Post date:** [March 31, 2018, 1:42am UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/9 "2018-03-31T01:42:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![taehyunzzz](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/taehyunzzz/32/42473_2.png) [@taehyunzzz](https://discuss.pytorch.org/u/taehyunzzz)\
**Post date:** [May 26, 2022, 1:08pm UTC](https://discuss.pytorch.org/t/data-parallel-tutorial/15257/10 "2022-05-26T13:08:51Z")

</div>

How are you measuring PCIe bandwidth?
