It works. But when I tried implementing a squared version of this hinge loss, after the first time it computes the loss it goes to 0, even if the training accuracy is very low.
here is the class I implemented:
class SqHinge(nn.Module):
  def __init__(self):
        super(SqHinge, self).__init__()

  def forward(self, y_pred, y_true):
        criterion = nn.MultiMarginLoss()
        l1 = criterion(y_pred, y_true)
        l2 = l1*l1
        return l2

I tried using torch.pow, but the result was the same