Hi albanD,
Thank you for your answer and torch.autograd.grad indeed works for me!
I checked the docs of functional.jacobian again, and I found that I misunderstood the use of it. After I change the code, the result of functional.jacobian is all good now.