As you can see in https://pytorch.org/docs/master/autograd.html 17, the arguments of grad
torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False)
outputs and inputs are expected to be sequences of tensors. But you use just a tensor as outputs.