No, detach() is used if you don’t want to do backward on that variable
To freeze some weights, you can add them to a different param groups in the optimizer, and set the learning rate there to be 0.
You can also manually set the grad of those weight to 0 before calling step()