Note the example in documentation 6.

Examples:
>>> target = torch.ones([10, 64], dtype=torch.float32)  # 64 classes, batch size = 10
>>> output = torch.full([10, 64], 0.999)  # A prediction (logit)
>>> pos_weight = torch.ones([64])  # All weights are equal to 1
>>> criterion = torch.nn.BCEWithLogitsLoss(pos_weight=pos_weight)
>>> criterion(output, target)  # -log(sigmoid(0.999))
tensor(0.3135)


Maybe loss = criterion(outputs, labels.float()) or loss = criterion(outputs, labels.double())can solve your problem.