This use case fits exactly into the custom autograd.Function usage, so you would have to write the backward method manually as described in the tutorial.
Autograd cannot track the numpy operations (or generally any operations from other libraries) which is why the backward is needed.