TonyTr:

the output is supposed to be 0 because both are the same.


This is the part I don’t understand. Why do you expect the output of the specific loss function that you have defined in the code above to be zero when both its inputs are identical?