You would have to derive the backward formula manually and save all tensors needed in the backward calculations in ctx.
However, just by skimming through the code, it seems you could swap the numpy calls for their PyTorch equivalent.