param.requires_grad = False (will cause the parameter not to get a gradient stored in the loss.backward() call.
When you param.requires_grad = False to some parameters, it will not affect the gradient calculation for the others. Note that while the errors need to backpropagate through the layers for your set-up, the parameters of the layers are leaf nodes (and the backpropagation continues through the input data).

Best regards
Thomas