albanD:

This will work to freeze the gradients to 0.
Be careful though that many optimizer will still update the weights even for a gradient of 0! If you have regularization or momentum for example.


@albanD, I add the same issue and when setting param.grad = None it force the optimizer to skip this param update at step. Thus, also optimizers with momentum will keep those layers params fixed.