"params.requires_grad = False" has elevated memory usage in v0.1.11

I downloaded the pretrained weights for resnet152 using Python 3.5 and test the below code with both Python 2.7 and Python 3.5. When i ran the code below in Python 2.7, it cause out-of-memory error (it requires more than 12GB).

resnet = torchvision.models.resnet152(pretrained=True)
for param in resnet.parameters():
    param.requires_grad = False             # It seems not work in Python 2.7
images = torch.randn(128, 3, 224, 224)
resnet = resnet.cuda()
images = images.cuda()
outputs = resnet(Variable(images))          # requires 2.3GB in Python 3.5 

Do you have any idea why this is happening?

Which version do you use? I test this code under pytorch-0.1.10-post2 with python-2.7.13, and everything works fine.

@yunjey i’m looking into this. This seems like a pytorch v0.1.10 vs v0.1.11 problem, and not a python 2.7 vs 3.5 problem. For now you can workaround using this line:

outputs = resnet(Variable(images, volatile=True))

I will be tracking this issue here: https://github.com/pytorch/pytorch/issues/1184