title: Is there a mistake in pytorch tutorial?
body: <p>The official pytorch tutorial (<a href="https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html#gradients" rel="nofollow noreferrer">https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html#gradients</a>) indicates that <code>out.backward()</code> and <code>out.backward(torch.tensor(1))</code> are equivalent. But this does not seem to be the case.</p>
  
  <pre><code>import torch
  
  x = torch.ones(2, 2, requires_grad=True)
  y = x + 2
  z = y * y * 3
  out = z.mean()
  
  # option 1    
  out.backward()
  
  # option 2. Replace! do not leave one after the other
  # out.backward(torch.tensor(1))
  
  print(x.grad)
  </code></pre>
  
  <p>Using option 2 (commented out) results in an error.</p>
  
  <p><strong>Note</strong>: do not leave two backward calls. Replace option 1 with 2.</p>
  
  <p>Is the tutorial out of date? What is the purpose of the argument?</p>
  
  <p><em>Update</em>
  If I use <code>out.backward(torch.tensor(1))</code> as the tutorial says, I get:</p>
  
  <pre><code>E       RuntimeError: invalid gradient at index 0 - expected type torch.FloatTensor but got torch.LongTensor
  
  ../../../anaconda3/envs/phd/lib/python3.6/site-packages/torch/autograd/__init__.py:90: RuntimeError
  </code></pre>
  
  <p>I tried also using <code>out.backward(torch.Tensor(1))</code> and I get instead:</p>
  
  <pre><code>E       RuntimeError: invalid gradient at index 0 - expected shape [] but got [1]
  
  ../../../anaconda3/envs/phd/lib/python3.6/site-packages/torch/autograd/__init__.py:90: RuntimeError
  </code></pre>