The weight argument in nn.BCEWithLogitsLoss and F.binary_cross_entropy_with_logits gives the weight values per sample, not per class. From the docs:

weight (Tensor 3, optional) – a manual rescaling weight given to the loss of each batch element. If given, has to be a Tensor of size nbatch.

so you could need to calculate this tensor for each batch using the current targets (or use the pos_weight if applicable).