title: Pytorch autograd fails with "RuntimeError: differentiated input is unreachable" after collecting inputs
body: <p>Pytorch version 0.3.1</p>
  
  <p>EDIT: I am rewriting this question to be simpler, as I've narrowed down the bug.</p>
  
  <p>I have some variables:</p>
  
  <pre><code>x = ag.Variable(torch.ones(1, 1), requires_grad = True)
  y = ag.Variable(torch.ones(1, 1), requires_grad = True)
  z = ag.Variable(torch.ones(1, 1), requires_grad = True)
  </code></pre>
  
  <p>I then create a variable representing their concatenation:</p>
  
  <pre><code>w = torch.cat([x, y, z])
  f = x + y + z
  </code></pre>
  
  <p>Then I try to take derivatives:</p>
  
  <pre><code>ag.grad(f, x, retain_graph=True, create_graph=True)
  </code></pre>
  
  <p>This is fine and returns 1, as expected. Same for y and z.</p>
  
  <p>However,</p>
  
  <pre><code>ag.grad(f, w, retain_graph=True, create_graph=True)
  </code></pre>
  
  <p>Returns an error: RuntimeError: differentiated input is unreachable</p>
  
  <p>Of course that makes sense - w is not explicitly used in the declaration of <code>f</code>. However, I’d like a behavior where one line of code can generate something like <code>[1; 1; 1]</code> as output.</p>
  
  <p>Let’s say I wanted to conveniently batch my variables together, and then take the gradient of the whole shebang at once, rather than processing variables independently (which can make bookkeeping a nightmare). Is there any way to get the outcome I desire?</p>