Hello,
In my shallow view, it will work, but we should fix something manaully, see this thread 9 which computing Hessian product and do backward, I think it is similar to you, do backward on a gradient.
So, did you have a try on the snippet above?