If your goal is to create a new operations, you don’t think to change anything in pytorch’s code.
Just create a new function with your operations. If they are all differentiable, then you will get the gradients automatically.
If they are not differentiable (or you implement the forward in low level code that the autograd cannot work with), you can create an autograd.Function 3.