title: Pytorch gradients exist but weights not updating
body: <p>So, I have a deep convolutional network with an lstm layer, and after the ltsm layer it splits off to compute two different functions (using two different linear layers) whose results are then added together to form the final network output. </p>
  
  <p>When I compute the loss of the network so that I can have it compute the gradients and update the weights, I have it do a few operations and then have it compute the loss between the derived value and the calculated target value. </p>
  
  <pre><code>def update(output, target):
      # target output is calculated outside the function
      # operations on output
      loss(output, target).backward()
      self.optimizer.step()
  </code></pre>
  
  <p>The network has some loss (sometimes in a very small order of magnitude, but sometimes also on higher orders of magnitude), for example a few of the losses:</p>
  
  <pre><code>tensor(1.00000e-04 *
     5.7420)
  tensor(2.7190)
  tensor(0.9684)
  </code></pre>
  
  <p>It also has gradients as calculated here:</p>
  
  <pre><code>for param in self.parameters():
      print(param.grad.data.sum())
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>tensor(1.00000e-03 *
     1.9996)
  tensor(1.00000e-03 *
     2.6101)
  tensor(1.00000e-02 *
     -1.3879)
  tensor(1.00000e-03 *
     -4.5834)
  tensor(1.00000e-02 *
     2.1762)
  tensor(1.00000e-03 *
     3.6246)
  tensor(1.00000e-03 *
     6.6234)
  tensor(1.00000e-02 *
     2.9373)
  tensor(1.00000e-02 *
     1.2680)
  tensor(1.00000e-03 *
     1.8791)
  tensor(1.00000e-02 *
     1.7322)
  tensor(1.00000e-02 *
     1.7322)
  tensor(0.)
  tensor(0.)
  tensor(1.00000e-03 *
     -6.7885)
  tensor(1.00000e-02 *
     9.7793)
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>tensor(2.4620)
  tensor(0.9544)
  tensor(-26.2465)
  tensor(0.2280)
  tensor(-219.2602)
  tensor(-2.7870)
  tensor(-50.8203)
  tensor(3.2548)
  tensor(19.6163)
  tensor(-18.6029)
  tensor(3.8564)
  tensor(3.8564)
  tensor(0.)
  tensor(0.)
  tensor(0.8040)
  tensor(-0.1157)
  </code></pre>
  
  <p>But when I compare the weight before and after running the optimizer, I get the result that the weights are equal to each other.</p>
  
  <p>Code to see if weights change:</p>
  
  <pre><code>before = list(neuralnet.parameters())
  neuralnet.update()
  after = list(neuralnet.parameters())
  for i in range(len(before)):
      print(torch.equal(before[i].data, after[i].data))
  </code></pre>
  
  <p>The above returns True for each iteration.</p>