The mixed-precision training utility (amp) raises the error when you are using sigmoid + nn.BCEWithLogitsLoss, as its usage was determined to not be numerically stable in float16. Thus passing the raw logits to nn.BCEWithLogitsLoss is the right approach, since internally log_sigmoid will be applied, if I’m not mistaken.
I had a guess that using torch.sigmoid on the output might have exactly the same issue when you are trying to predict the outputs and it seems to be indeed the case.