Modifying parameters this way doesn’t work.
In my opinion the best way to do this is to create your own layer using W and K as parameters and using torch.nn.functional.linear in the forward.
for the multiplication, (provided m is even), I’d probably suggest
   mul = torch.ones(2, 1, 1, device=K.device)
   mul[0, 0, 0] = K
   weight = (W.view(2, m//2, -1) * mul).view(m, -1)

and then using weight. Backpropagation should work this way.
There is a somewhat elaborate way to replace parameters with calculated quantities, see e.g. the spectral norm implementation for inspiration. Unfortunately, there doesn’t seem general interest for a more generally applicable interface (I’ve tried to pitch my ideas at https://github.com/pytorch/pytorch/issues/7313 33 ).
Best regards
Thomas