I would wrap it in a no_grad() block, to make sure that this assignment is not tracked by Autograd.


If these parameters are not referenced anymore, they’ll be freed. E.g. if you’ve passed them to an optimizer before replacing them, they might be kept alive (and the new parameters would have to be added to the optimizer).