title: Pytorch loss inf nan
body: <p>I'm trying to do simple linear regression with 1 feature. It's a simple 'predict salary given years experience' problem.
  The NN trains on years experience (X) and a salary (Y).
  For some reason the loss is exploding and ultimately returns <code>inf</code> or <code>nan</code></p>
  <p>This is the code I have:</p>
  <pre class="lang-py prettyprint-override"><code>    import torch
      import torch.nn as nn
      import pandas as pd
      import numpy as np
      
      dataset = pd.read_csv('./salaries.csv')
      
      x_temp = dataset.iloc[:, :-1].values
      y_temp = dataset.iloc[:, 1:].values
      
      X_train = torch.FloatTensor(x_temp)
      Y_train = torch.FloatTensor(y_temp)
     
      class Model(torch.nn.Module): 
          def __init__(self):
              super().__init__()
              self.linear = torch.nn.Linear(1,1)
      
          def forward(self, x):
              y_pred = self.linear(x)
              return y_pred
      
      model = Model()
      
      loss_func = torch.nn.MSELoss(size_average=False)
      optim = torch.optim.SGD(model.parameters(), lr=0.01)
      
      #training 
      for epoch in range(200):
          #calculate y_pred
          y_pred = model(X_train)
      
          #calculate loss
          loss = loss_func(y_pred, Y_train)
          print(epoch, &quot;{:.2f}&quot;.format(loss.data))
      
          #backward pass + update weights
          optim.zero_grad()
          loss.backward()
          optim.step()
      
      
      test_exp = torch.FloatTensor([[8.0]])
      print(&quot;8 years experience --&gt; &quot;, model(test_exp).data[0][0].item())
  
  </code></pre>
  <p>As I mentioned, once it starts training the loss gets super big and ends up showing <code>inf</code> after like the 10th epoch.</p>
  <p>I suspect it may have something to do with how i'm loading the data? This is what is in <code>salaries.csv</code> file:</p>
  <pre><code>Years Salary
  1.1 39343
  1.3 46205
  1.5 37731
  2   43525
  2.2 39891
  2.9 56642
  3   60150
  3.2 54445
  3.2 64445
  3.7 57189
  3.9 63218
  4   55794
  4   56957
  4.1 57081
  4.5 61111
  4.9 67938
  5.1 66029
  5.3 83088
  </code></pre>
  <p>Thank you for your help</p>