To freeze layers, is it enough to set requires_grad to False?

Hi, setting it to False is sufficient for the right thing to happen.

Here is a very good explanation.

But just to be sure, here is the source code for the SGD optimizer. As you can see, when updating the parameters the flag is checked and if set to False then nothing will happen. So it will no be taken as having zero gradient, it will just do nothing for those parameters.