title: Train multi-output regression model in pytorch
body: <p>I'd like to have a model with 3 regression outputs, such as the dummy example below:</p>
  <pre><code>import torch
  
  class MultiOutputRegression(torch.nn.Module):
  
      def __init__(self):
          super(MultiOutputRegression, self).__init__()
          self.linear1 = torch.nn.Linear(1, 10)
          self.linear2 = torch.nn.Linear(10, 10)
          self.linear3 = torch.nn.Linear(3, 3)
  
      def forward(self, x):
          x = self.linear1(x)
          x = self.linear2(x)
          x = self.linear3(x)
          return x
  </code></pre>
  <p>Suppose I want to train it to perform a dummy task, such as, given the input <code>x</code> returning <code>[x, 2x, 3x]</code>.</p>
  <p>After defining the criterion and the loss we can train it with the following data:</p>
  <pre><code>for i in range(1, 100, 2):
      x_train = torch.tensor([i, i + 1]).reshape(2, 1).float()
      y_train = torch.tensor([[j, 2 * j] for j in x_train]).float()
      y_pred = model(x_train)
      # todo: perform training iteration 
  </code></pre>
  <p>Sample data at the first iteration would be:</p>
  <pre><code>x_train
  tensor([[1.],
          [2.]])
  y_train
  tensor([[1., 2., 3.],
          [2., 4., 6.]])
  
  </code></pre>
  <p>How can I define a proper loss and criterion to train the neural network?</p>