How to calculate 2nd derivative of a likelihood function

Thanks you @dpernes for you inspiring comments, that works for that problem.

But I found this still can not help me find the 2nd derivative of a likelihood function for each weight, do you know how to achieve that?

Or do you know if we can do it based on the current pytorch version?