Thanks for the code.
The error is most likely thrown, as you are trying to manipulate the require_grad attribute of the model replica parameters.
If you freeze the parameters outside of the forward method, it’ll work.
What’s your workflow that you want to freeze them in each forward pass?