I guess the best example would be gather/scatter in this file: https://github.com/pytorch/pytorch/blob/master/torch/csrc/autograd/functions/comm.cpp 10
The important bit is that Nodes are only applied. So you need one for the forward and one for the backward.
And you should use the wrap_outputs util from the functions/utils.cpp to properly set up the graph on your outputs before returning them.
Note that if you do inplace or views there is more stuff that you need to do (let me know if you need these).