BCELoss — PyTorch master documentation 1
Here is the original documentation in the last sentence they reveal clamping the output.

Our solution [regarding the infinity issue] is that BCELoss clamps its log function outputs to be greater than or equal to -100. This way, we can always have a finite loss value and a linear backward method.