def detect_anomaly(self, loss):
    if (not torch.isfinite(loss).all()):
        raise FloatingPointError('Loss is infinite or NaN!')
def detect_anomaly(self, loss):
    if (not torch.isfinite(loss).all()):
        raise FloatingPointError('Loss is infinite or NaN!')