I am trying to do autocast but I am getting the following error
RuntimeError: torch.nn.functional.binary_cross_entropy and torch.nn.BCELoss are unsafe to autocast.
Many models use a sigmoid layer right before the binary cross entropy layer.
In this case, combine the two layers using torch.nn.functional.binary_cross_entropy_with_logits
or torch.nn.BCEWithLogitsLoss.  binary_cross_entropy_with_logits and BCEWithLogits are
safe to autocast.

This is  saying me to use BCEWithLogitsLoss instead of BCELoss, but my last layer contain tanh instead of sigmoid. How can I use BCEWithLogitsLoss though I don’t want sigmoid layer.
Thanks