Hello.
I was wondering since the C++ API is pretty close to the python one.
Could you try to use the autograd.grad function as described here 24?
The gradient will be accumulated in the input_vector instead of in your case x.
The input_vector is usually set to “ones” with the shape of the output_vector.