I defined a loss function for my network, and it’s computed as:
    loss = pred.mm(pred.T) - (label.view(-1,1) == label.view(1,-1)).to(dtype=torch.float32)
    loss = loss**2
    loss = torch.pow(loss, (2-loss)**2)
    loss = loss.sum() / (label.size(0)**2 +1.0)    
    return loss

During training, the following error report appeared:
RuntimeError: Function 'PowBackward1' returned nan values in its 1st output.
and this error is traced to the line:
   loss = torch.pow(loss, (2-loss)**2)
I’m not clear about how this error is related to this line of code. Can anyone help me out?