I am writing a custom BCE in pytorch but in some cases it returns -inf and nan most cases. Which is due to the log function.
bce_loss=y_true*torch.log2(y_pred) + (one_torch-y_pred)*torch.log2(one_torch-y_pred)

Is there a way to rewrite this? Note  y_pred is a sigmoid output which is between 0 and 1.