Hi All, my questions might sound a bit naive, but I am really struggling to understand the framework.
I defined my own loss function and it works. When I say “it works”, I mean it does not crash or end up with error, although the loss shows no steady decrease.
class MyLossFunc(torch.nn.Module):
    def __init__(self):
        super(MyLossFunc, self).__init__()
        self.weights = None
        self.wsum = None
    def SetMask(self, mask: np.ndarray) -> None:
        self.weights = torch.from_numpy(1 - mask).float()
        self.wsum = torch.sum(self.weights)
    def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
        return (torch.sum(self.weights * torch.abs(x - y)) / self.wsum)

The questions:
The back-proparagion algorithm essentially uses the gradient of the loss function, which I do not
provide. Why the above loss function does work, although only the scalar value is computed?
Does the PyTorch framework compute numeric gradient of the loss function internally, or I missed something and my network does a dummy optimisation?
I went through the various topics in the documentation, but still be puzzled with the problem
of proper definition of a loss function. I would greatly appreciate any feedback.