Yeah the problem in the first code was after leading the state dict, you had to create the optimizer again, which you did in the second piece of code.
You don’t need to filter the model parameters to pass to the optimizer, setting requires_grad=False alone is sufficient to prevent the gradient computation of those layers with requires_grad=False