You can see the docs here 4:

pos_weight  ( Tensor  ,  optional ) – a weight of positive examples. Must be a vector with length equal to the number of classes.

You can pass pos_weight as an argument to the creation of nn.BCEWithLogitsLoss instead of manually applying it.