# Data parallelism error for pretrained model

**URL:** <https://discuss.pytorch.org/t/data-parallelism-error-for-pretrained-model/79197>\
**Category:** Uncategorized\
**Created:** [May 1, 2020, 1:58am UTC](https://discuss.pytorch.org/t/data-parallelism-error-for-pretrained-model/79197 "2020-05-01T01:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SU801T](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@SU801T](https://discuss.pytorch.org/u/SU801T)\
**Post date:** [May 1, 2020, 1:58am UTC](https://discuss.pytorch.org/t/data-parallelism-error-for-pretrained-model/79197/1 "2020-05-01T01:58:24Z")

</div>

Hi,

I am trying to run my model on multiple GPUs for data parallelism but receiving this error:

```auto
AttributeError: 'DataParallel' object has no attribute 'fc'

```

I have defined the following pretrained model :

```auto
def resnet50(num_classes, device):
    model = models.resnet50(pretrained=True)
    model = torch.nn.DataParallel(model)
    for p in model.parameters():
        p.requires_grad = False
    num_ftrs = model.fc.in_features
    model.fc = nn.Linear(num_ftrs, num_classes)

    model = model.to(device)
    return model

```

It’s unclear to me where I can add “module”

Cheers

---

<div class="post-metadata">

**Author:** ![mrshenli](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mrshenli/32/12220_2.png) [@mrshenli](https://discuss.pytorch.org/u/mrshenli)\
**Post date:** [May 1, 2020, 2:12am UTC](https://discuss.pytorch.org/t/data-parallelism-error-for-pretrained-model/79197/2 "2020-05-01T02:12:56Z")

</div>

If you are trying to access the `fc` layer in the resnet50 wrapped by the DataParallel model, you can use `model.module.fc`, as `DataParallel` stores the provided model as `self.module`:

> <https://github.com/pytorch/pytorch/blob/df8d6eeb19423848b20cd727bc4a728337b73829/torch/nn/parallel/data_parallel.py#L131>

---

<div class="post-metadata">

**Author:** ![SU801T](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@SU801T](https://discuss.pytorch.org/u/SU801T)\
**Post date:** [May 1, 2020, 2:29am UTC](https://discuss.pytorch.org/t/data-parallelism-error-for-pretrained-model/79197/3 "2020-05-01T02:29:30Z")

</div>

Great, thanks. I added .module to everything before .fc including the optimizer.
