Hi,
output = Variable(output.data, requires_grad=True) you should never do that. Both because Variable don’t exist anymore, you can just use Tensors. And you should never use .data as it has many bad side effects (including preventing the gradients from flowing).
If you want to detach a Tensor, use .detach().
If you already have a list of all the inputs to the layers, you can simply do grads = autograd.grad(loss, inputs) which will return the gradient wrt each input.