Hey,
Unfortunately autograd is not magic. It works with all pytorch ops because we wrote manually all the formulas.
So for it to work here you need to either:

write things in pytorch ops for which we have the formulas
tell the autograd what is the formula yourself with a custom op Extending PyTorch — PyTorch 1.7.1 documentation 2 and then you can do whatever you want in the forward.