Different results when running binary_cross_entropy() and the BCEWithLogitsLoss

Hey everyone, in the lectures Jeremy said that the binary_cross_entropy function and the function
returned by nn.BCEWithLogitsLoss have the same implementation, but when invoking them I am getting different results. Has there been a change in the BCEWithLogitsLoss implementation or am I misunderstanding something?

Hi @armanharutyunyan

Nice job on trying to reimplement BCE to understand the inner workings of the loss function. In your definition, in the torch.where clause, you need to either do targets == 0 for your code to work or you can change the conditionals to inputs, 1-inputs instead of vice-versa and then the two outputs should match.

Hope this helps,
Thanks! :slight_smile: