title: PyTorch: Not being able to run my fit function
body: <p>I am using <a href="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.researchgate.net%2Fprofile%2FMohamed_El_Azzouzi2%2Fpublication%2F275349599%2Ffigure%2Fdownload%2Ftbl2%2FAS%3A391760950906883%401470414497156%2FCorrosion-rate-value-of-the-corrosion-of-mild-steel-in-HCl-1M-media-with-and-without.png&amp;f=1&amp;nofb=1" rel="nofollow noreferrer">this table btw</a></p>
  <pre><code>input = np.array([
                    [[313, 1], #HCL
                     [323, 1],
                     [333, 1],
                     [343, 1]], 
                    [[313, 10e-3], #Ortho
                     [323, 10e-3],
                     [333, 10e-3],
                     [343, 10e-3]], 
                    [[313, 10e-3], #Para
                     [323, 10e-3],
                     [333, 10e-3],
                     [343, 10e-3]]
                    ], dtype='float32')   target = np.array([[[14.76, 16.42, 18.08, 23.41]],
                      [[5.87, 11.14, 13.20, 25.72]],
                      [[2.73, 4.42, 8.04, 13.68]]], dtype='float32') loss_fn = F.mse_loss loss = loss_fn(model(input), target)
  </code></pre>
  <p>Output:</p>
  <pre><code>/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: UserWarning: Using a target size (torch.Size([3, 1, 4])) that is different to the input size (torch.Size([3, 4, 4])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
  
  
  def fit(num_epochs, model, loss_fn, opt):
    for epoch in range(num_epochs):
      for xb, yb in train_dl:
        pred = model(xb)
        loss = loss_fn(preds, yb)
        loss.backward()
        opt.step()
        opt.zero_grad()
  
      if (epoch+1) % 10 == 0:
        print('Epoch [{}/{}], Loss: {:.4f}'.format(epoch+1, num_epochs, loss.item()))
  
  fit(100, model, loss_fn, opt)
  </code></pre>
  <p>Output:</p>
  <pre><code>Epoch [10/100], Loss: 25.1053
  Epoch [20/100], Loss: 25.1050
  Epoch [30/100], Loss: 25.1047
  Epoch [40/100], Loss: 25.1043
  Epoch [50/100], Loss: 25.1040
  Epoch [60/100], Loss: 25.1036
  Epoch [70/100], Loss: 25.1033
  Epoch [80/100], Loss: 25.1030
  Epoch [90/100], Loss: 25.1026
  Epoch [100/100], Loss: 25.1023
  
  /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:5: UserWarning: Using a target size (torch.Size([3, 1, 4])) that is different to the input size (torch.Size([3, 4, 4])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
    &quot;&quot;&quot;
  </code></pre>
  <p>I'm wondering if the shape mismatching gives an error in the fit function. Also I would like some general tips on how to make these matrices. So I don't run into this, maybe like a general rule of thumb. Or things I can do when I do run into this problem, because I don't wanna not be able to do anything once this happens.</p>
  <p>EDIT: I fixed the error while in the <code>fit</code> function. But the warning persists. I am not sure what to do, because this gives very wrong data.</p>