Could you post a link to the repository you are using?
Also, could you post the inputs and targets for a negative loss value?
Negative values for nn.BCE(WithLogits)Loss can be created if your target is out of bounds.