I don’t quite understand the issues, as they seem to point to different errors.

The first one (multi-target not supported) is raised e.g. if your target has additional dimensions as seen here:

criterion = nn.CrossEntropyLoss()

output = torch.randn(1, 2048)
target = torch.randint(0, 2048, (1,))
loss = criterion(output, target) # works

target = target.unsqueeze(1)
loss = criterion(output, target)
> RuntimeError: 1D target tensor expected, multi-target not supported



The second issue (size mismatch) could be created by a wrong reshape operation, which changes the batch size.


The last post would indicate that the model output is [batch_size=1, nb_classes=2048], while the target would use [batch_size=1024], which is also wrong.


Could you thus explain your use case a bit more, i.e. what is the expected batch size and how many classes are you working with?