When you use pretrained models for finetuning, you don’t want to backpropagate though the pretrained model. i.e. You only update the weights of the new layers added on top the pretrained model. To a achieve this, you should iterate through the parameters of the pretrained model and set requires_grad = False. For example,

resnet = models.resnet152(pretrained=True)
modules = list(resnet.children())[:-1]      # delete the last fc layer.
resnet = nn.Sequential(*modules)
### Now set requires_grad to false
for param in resnet.parameters():
param.requires_grad = False