In the posted code snippet you are not using mixed-precision training and in particular torch.cuda.amp.autocast, which raises the initial error.
The reason for this error is the numerical stability of sigmoid + nn.BCELoss, which is already less stable than nn.BCEWithLogitsLoss in float32 and could suffer more when using mixed-precision training.