Hi,
I am solving a non-linear optimization problem and use torch.autograd.grad to provide Jacobian that an optimizer requires.
Please see the code snippet below:
_stateplus = torch.stack([x[0], x[1], _ar1_plus]).numpy()
_controls_plus[z_idx, epsilon_idx, :] = policy_plus[z_idx].evaluate(
   _stateplus)

where x is a tensor variable with respect to which I want to compute the gradient.
I add the .numpy() argument, because the .evaluate() accepts only numpy array.
But in this case, I encounter the following error as expected:
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

I think the detach().numpy() argument breaks the computational graph, but I need a gradient with respect to x.
How can I avoid this situation?