Your suggestion works, and might really be useful in a lot of cases, but it may not have the same effect with (requires_grad=false)
It works since it sets the selected gradients to zero and ensure thats there will be no changes for some certain weights, but the gradients will still be calculated for all the weights, including the ones that have been frozen.
I am concerned about the outcome of that since I am not sure if it would create the same kind of result as setting a requires_grad flag to false.
Because I think =not sure tho= that the loss calculation might be omitting the participation of frozen parameters in the inference when we set requires_grad to false and this would create a focus on the parameters with requires_grad set to true during loss calculation and may eventually let these parameters to be penalized as they are responsible for all the losses of the network.
Please correct me if I am wrong, I know I am assuming a lot of things but, maybe these thoughts can help someone.