It is certainly possible to write your own BCE loss function.

Two comments:

First, the second term in what you’ve posted has y_pred twice
and no y_true. That might just be a typo, but if it’s like that in
your actual code, it won’t work.

Second, to reduce the likelihood of nan, it his better to modify
your BCE loss to take a logit (from -infinity to infinity), rather
than a probability (from 0 to 1).

This allows you to combine together, internally to your loss
function, the sigmoid and log, and use the “log-sum-exp trick”
to improve numerical stability.

By the way, what is your motivation in writing your own BCE
loss function?