I think you can refer to this topic:

  
    
    
    How to create model with sharing weight? 
  
  
    EDIT: we do support sharing Parameters between modules, but it’s recommended to decompose your model into many pieces that don’t share parameters if possible. 
We don’t support using the same Parameters in many modules. Just reuse the base for two inputs: 
class MyModel(nn.Module):
    def __init__(self):
        self.base = ...
        self.head_A = ...
        self.head_B = ...

    def forward(self, input1, input2):
        return self.head_A(self.base(input1)), self.head_B(self.base(input2))…