How to use a network B to obtain a tensor and use it to replace the weight of a layer of network A, and this back propagation process will train A and B

How to use a network B to obtain a tensor and use it to replace the weight of a layer of network A and this backpropagation process will train A and B。

I make a code, which uses the weight of a layer of network A as input into network B. then B output a tensor and I use it to replace the weight of a layer of the network A. But I find the weight only needs the type of nn.Parameter() and I convert the tensor to Parameter type, but I find the weight of network B does not get an update. Can you help me please!

It’s noted that I want to train the weight of network B by the loss of the network A.