I want to share some weights between two models using pytorch.

  
      github.com
  
  
    seokinj/coPassGAN/blob/master/models.py#L27 2

        nn.ReLU(True),
        nn.Conv1d(DIM, DIM, 5, padding=2),#nn.Linear(DIM, DIM),
        nn.ReLU(True),
        nn.Conv1d(DIM, DIM, 5, padding=2),#nn.Linear(DIM, DIM),
    )


def forward(self, input):
    output = self.res_block(input)
    return input + (0.3*output)


G_block_share1 = ResBlock()
G_block_share2 = ResBlock()


D_block_share4 = ResBlock()
D_block_share5 = ResBlock()


class Generator_A(nn.Module):


def __init__(self, charmap):
    super(Generator_A, self).__init__()





  
  
    
    
  
  


In this code, he make modules(‘G_block_share/D_block_share’) as global variable to share weights, and then use thos modules in two different model classes(‘Generator A&B or Discriminator A&B’)
This code is right way to share weights between two models?