def METHOD_NAME(self, *args, **kwargs):
    loss = super().METHOD_NAME(*args, **kwargs)
    self.patience -= 1
    if self.patience < 0:
        return torch.as_tensor([float("nan")], device=loss.device, dtype=torch.float32)
    return loss