You can use torch::autograd::Function exactly the same way you’d use torch.autograd.Function in Python. So you could first go to the Python documentation on torch.autograd.Function and then navigate in your C++ IDE to where torch::autograd::Function is defined and look at the example that is given in the comments. That’s how I got very quickly the hang of it.