Custom loss function in PyTorch

Hi
I’m trying to train a network by my own loss function.
I can train a network with loss functions are included in the PyTorch.But, I meet the challenge when I am trying to define my own loss function.
Indeed, I need to a correct example to train a network by custom loss function in details

My loss function is:
Capture

Isn’t this the max margin loss?
That said, the beauty of PyTorch is that you aren’t forced to designate something a loss function, to define your own, just write out the computation and take the backward.

Best regards

Thomas