The C++ API doesn’t have all the “pass a tensor and it’ll be treated as a 1-element list of tensors” functions that PyTorch has in Python.
In other words, use torch::autograd::grad({outputs}, {inputs}, /* grad_outptus=*/ {}, /* create_graph=*/ true); or so, as seen in the higher order gradient example for C++.
Best regards
Thomas