Require_grad vs requires_grad

What is the difference between require_grad and requires_grad? I am trying to freeze layers of the network. But during the implementation of the freeze function, I used require_grad = False for freezing layers, and now when I am checking it with requires_grad it says layers are not frozen i.e. result in requires_grad=True? Is there any fundamental difference between the two implementations?

model.freeze()
for name,param in model.named_parameters():
    print(name,param.requires_grad)

Code of model.freeze():

def freeze(self):
        # To freeze the residual layers
        for param in self.network.parameters():
            param.require_grad = False
        for param in self.network.fc.parameters():
            param.require_grad = True

Hi,

require_grad is not a pytorch thing :slight_smile: So it has no effect.
Note that you can set any attribute you want on Tensor, this is why you didn’t see any error (param.foo = 3 would work as well).