Stick to the second approach, as the first one is deprecated and might yield unwanted side effects.
In a torch.no_grad() block all new operations won’t be tracked. The requires_grad attribute of your parameters will not be changed:
model = models.resnet50()

with torch.no_grad():
    print(model.fc.weight.requires_grad)    
    > True
    out = model(torch.randn(1, 3, 224, 224))
    print(out.requires_grad)
    > False

out = model(torch.randn(1, 3, 224, 224))
print(out.requires_grad)
> True