nn.BCEWihtLogitsLoss expects the model output and target to have the same shape.
Based on your provided shapes, it seems that your target might have the shape [batch_size] and might contain the class indices for each sample?
If that’s the case, you are dealing with a multi-class classification use case and should use nn.CrossEntropyLoss instead.
Based on your model output you might also be dealing with a multi-label classification use case, where each sample might belong to zero, one, or multiple classes. If that’s the case, your target should contain values in the range [0, 1] and have the shape [batch_size, nb_classes].