Hi,
Functions in cpp are quite different.
A Function only has an apply method that represent the forward pass and should return as output variables with the proper .grad_fn attached.
For example, the DelayedError Function here 25 is just a noop that will raise an error if it’s backward is called.
You can see it does nothing during the forward and attach the Error Function to it’s outputs using the handy “wrap_outputs”.
For the forward pass, the function needs to be instantiates first and then the forward pass will happen when the .apply method is called (Note that it can only be called once). For backward methods, you create the instance and attach it to your output and the apply will be called once by the autograd engine when it’s needed.
You can see here 40 for example how Gather is used in pure cpp.
If you need this Function to be available in python, you can see here 23 how we do it.