Already set "requires_grad = True", but still got element 0 of tensors does not require grad and does not have a grad_fn

I’m trying to define a autograd function. In the forward path, I want to compute the gradient of a LSTMCell’s output with respect to its input. So I called autogard.grad, however I got error " element 0 of tensors does not require grad and does not have a grad_fn". I already set “requires_grad = True” for the input, not sure why this error occur.

I attach my code here for further refer:

Thanks in advance!