Thanks Tomas. I am using loss.backward() to accumulate gradients, I also try to let retain_graph =True.
As to the dependency on the parameters, I tried to not using ds but grads_data to compute hessian vector product. I still get the same error message.
“Hd = torch.autograd.grad(grads_fun, params, grad_outputs=grads_data, only_inputs=True, retain_graph=True,allow_unused=False)
RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.”
Cheers