Well again,
A) You need gradients
i)If you know the algorithm used you can implement it with pytorch functions.
ii) You can use the code as it is (won’t be very efficient) and implement the backward function. This is, telling pytorch how to get the gradients of the input wrt the output.
B) You don’t need gradients
Then you can just use the code as it is.