Hi all,
I want to create a new criterion as a black box (which uses numpy). Since autograd cannot compute the gradient, I need to define both the forward() and backward() functions. The new criterion gets the output of the network; then, together with some other values, it computes both the loss and the gradients to the input. Now,

Do I need to inherit from a module in Pytorch?
Do I need to iterate a for-loop to compute the loss for each sample within a batch and then compute the average loss?

Any help would be highly appreciated.