I define my custom loss as follows:
def custom loss(target,output,mask):
    output = torch.neg(output)
    loss = torch.add(target,output)
    loss = torch.pow(loss,2)
    loss = torch.mul(loss,mask)
    loss = torch.mean(loss)

I’ve seen many people use a class. But I also read a function would be fine. Would that loss work? target,output and mask are Variable.
Subsequently, in my training loop, I call loss.backward(). The program runs but I just want to confirm my implementation of the loss is correct.
Thanks