The error message is raises as it seems that the model’s output are on the GPU, while the target tensor is still on the CPU.
You might thus need to move the targets to the GPU before passing them to the criterion via:
target = target.to('cuda')