Hi,
This is “expected” given the how all these functions are supposed to work.
In particular, load_state_dict is 100% breaking the computational graph so you won’t be able to backpropagate through what it does.
The nn.Parameters() that are recovered by model.parameters() are supposed to be special Tensors that are learnt when you use nn tools.
In your case, your try and hack around that by having some nn.Parameters() that you don’t actually learn.
Unfortunately, you cannot do it this way.
A simple way to do this is to create your own nn.Module that inherits from the orignal module you wanted and that has M as an nn.Parameter() but not the original .weight for example. Then inside the forward pass of this module, you will first compute the new weight, update it with a simple self.weight = new_value, and then call the parent’s module forward method