Hi,
I have a loss function that looks like this:
 disp_diff = (torch.max(eval_target[:, -1:, ...], eval_source[:, -1:, ...]) /
 torch.min(eval_target[:, -1:, ...], eval_source[:, -1:, ...])) - 1

disp_diff[disp_diff != disp_diff] = 0

loss = torch.sum(disp_diff, dim=[2, 3])

The max/min operation can be (0/0) = NaN. That’s why I set those position to 0 afterwards. The problem arises that when I try to do the loss.backward() in the next iteration the network only predicts NaNs. Is this because eval_target and eval_source have requires_grad=True and their NaNs can be propagated during the backward pass?