What is the proper input dimension for torch.nn.BCEWithLogitsLoss?
I am training a binary classifier and using torch.nn.BCEWithLogitsLoss as the loss function. I am confused about the proper input dimension for the loss function. Should it be [n, 1] or [n, 2]? In the case of [n, 1], where n is the number of samples, the values for the targets would just be 0 or 1, which represents the class that the sample belongs to. In the case of [n, 2], the targets would be torch.nn.functional.one_hot(targets, num_classes=2).float(). Which one is the proper dimension and what would be the corresponding logits and/or last layer of my network?

The documentation tells you all you need to know.
For a prediction tensor x of shape (num_samples, num_classes), the target tensor y should of the exact same shape.
Case 1
If your number of classes is two, and they are mutually exclusive, ax of shape (num_samples,) should be contrasted with a y of shape (num_samples,) taking values 0 | 1 (but typecast to float).
Case 2
If your number of classes is two, but they are not mutually exclusive (multi-class classification), x and y should be of shape (num_samples, 2) with y still taking float values from 0 | 1.
In either case, you need a final layer that projects your network's dimensionality to your number of classes (whatever that means in your context). So in case 1, something like Linear(model_dim, 1), whereas in case 2 Linear(model_dim, 2).
Remember not to apply any activation function to your network's output, as this is incorporated in BCEWithLogitsLoss already.
If your target labels are not discrete, adjust accordingly (values from [0..1] rather than 0 | 1).
