Thank you for the reply. Unfortunately as I can’t check the documentation of torch.binary_cross_entropy_with_logits, I couldn’t quite understand the necessary shape and form of pos_weight. I tried following, but I quite don’t know if that is the correct approach:
def bce_with_logits_loss(logit, target):
    criterion = nn.BCEWithLogitsLoss(reduction='none')
    loss = criterion(logit, target)
    loss = torch.mul(loss, pos_weight[None, :, None, None])
    loss = torch.mean(loss)
    return loss