title: Sharing parameters between certain layers of different instances of the same pytorch model
body: <p>I have a pytorch model with multiple layers that looks something like this</p>
  
  <pre><code>class CNN(nn.Module):
      def __init__(self):
          super(CNN).__init__()
          self.layer1 = nn.Conv2d(#parameters)
          self.layer2 = nn.Conv2d(#different_parameters)
          self.layer3 = nn.Conv2d(#other_parameters)
          self.layer4 = nn.Conv2d(#final_parameters)
  
      def forward(self, x):
          out1 = self.layer2(F.relu(self.layer1(x)))
          out2 = self.layer4(F.relu(self.layer3(x)))
          return torch.cat((out1, out2), 0)
  </code></pre>
  
  <p>I then want to instantiate multiple instances of this class <code>(cnn1, cnn2)</code>, and share the parameters of the first path <code>(layer1, layer2)</code> across instances while keeping the other parameters separate.</p>
  
  <p>Is there an optimal/supported way to do this?</p>