BruceDai003:

But my question is how can we mannully get the gradients for the inputs if we only have output, or output.grad_fn.


To the best of my knowledge, not all “backward-functions” are exposed. In particular those in FunctionsManual.cpp 1, the backward computations which typically are composed themselves of PyTorch functions, are not themselves exported.
(At least that was the state last I looked. Personally, I think that they should be available programmatically, but it didn’t catch on.)
Best regards
Thomas