According to the PyTorch documentation, the advantage of the class BCEWithLogitsLoss() is that one can use the
log-sum-exp trick for numerical stability.
If we use the class BCEWithLogitsLoss() with the parameter reduction set to None, they have a formula for that:
I now simplified the terms, and obtain after some lines of calculation:
I was curious to see whether this is the way how the Source code does it, but I couldn't find it.. The only code they have is this:



