title: PyTorch: access weights of a specific module in nn.Sequential()
body: <p>When I use a pre-defined module in PyTorch, I can typically access its weights fairly easily. However, how do I access them if I wrapped the module in <code>nn.Sequential()</code> first? r.g:</p>
  <pre><code>class My_Model_1(nn.Module):
      def __init__(self,D_in,D_out):
          super(My_Model_1, self).__init__()
          self.layer = nn.Linear(D_in,D_out)
      def forward(self,x):
          out = self.layer(x)
          return out
  
  class My_Model_2(nn.Module):
      def __init__(self,D_in,D_out):
          super(My_Model_2, self).__init__()
          self.layer = nn.Sequential(nn.Linear(D_in,D_out))
      def forward(self,x):
          out = self.layer(x)
          return out
  
  model_1 = My_Model_1(10,10)
  print(model_1.layer.weight)
  model_2 = My_Model_2(10,10)
  </code></pre>
  <p>How do I print the weights now?
  <code>model_2.layer.0.weight</code> doesn't work.</p>