You could use unreduced losses (reduction=‘none’), calculate the weight tensor for each element of your current batch and multiply it with the per-sample loss.
nn.BCEW(WithLogits)Loss povides a weight argument, which can be used alternatively.