Yes, this will zero out the weight and gradients of model.fc1, as I’ve used your code snippet, which only dealt with this layer.
If you need to apply the mask on other layers as well, you would need to create the masks using the appropriate shapes for each parameter and maybe write utility functions to keep your code clean.