nn.BCEWithLogitsLoss allows you to pass a weight as well as a pos_weight argument.
The former tensor should have the shape [batch_size] and will be applied to each sample, while the latter should have the shape [nb_classes] and will be applied to the positive examples as described in the docs 1.
Based on your code snippet I assume you would like to use pos_weight.