Thank you very much for your help K. Frank,
I didn’t saw the weight parameter in the torch.nn.BCEWithLogitsLoss function.
It sure is easier than to do my own function.
Also thanks for the tip regarding the numerical stability for sigmoid.
Have a great day !