I wrote a general way of doing this not safe monkey patching to substitute weights into the model. The code’s here 50 as part of a way to call scipy.optimize.minimize as a PyTorch optimizer. It’s the same except for doing a deepcopy of the Module to avoid any state problems on subsequent iterations. It’s not good for efficiency.