title: torch.nn.sequential vs. combination of multiple torch.nn.linear
body: <p>I'm trying to create a multi layer neural net class in pytorch. I want to know if the following 2 pieces of code create the same network. </p>
  
  <p>Model 1 with <code>nn.Linear</code></p>
  
  <pre><code>class TestModel(nn.Module):
  def __init__(self, input_dim, hidden_dim, output_dim):
      super(TestModel, self).__init__()
      self.fc1 = nn.Linear(input_dim,hidden_dim)
      self.fc2 = nn.Linear(hidden_dim,output_dim)
  
  def forward(self, x):
      x = nn.functional.relu(self.fc1(x))
      x = nn.functional.softmax(self.fc2(x))
      return x       
  </code></pre>
  
  <p>Model 2 with <code>nn.Sequential</code></p>
  
  <pre><code>class TestModel2(nn.Module):
  def __init__(self, input, hidden, output):
      super(TestModel2, self).__init__()
      self.seq = nn.Sequential(
                 nn.Linear(input_dim,hidden_dim),
                 nn.ReLU(),
                 nn.Linear(hidden_dim,output_dim),
                 nn.Softmax()
                 )
  
  def forward(self, x):
      return self.seq(x)
  </code></pre>