Agatha:

I’m working on multi-label classification with 8 labels and BCEWithLogitsLoss as a loss function. My target is in the range [0, 7].


This sounds rather like a multi-class classification (one active class per sample) and you could use nn.CrossEntropyLoss instead.
nn.BCEWithLogitsLoss is used for a multi-label classification (zero, one, or multiple active classes per sample) and expects the model output and target in the same shape.