It works without loss.backward()  and the shape of output for following code is (8,64,64,64), but I can’t get loss of each class.
import torch
N, C = 8, 21
loss = torch.nn.CrossEntropyLoss(reduction='none')
data = torch.randn(8,21 ,64, 64, 64)
target = torch.empty(8, 64, 64,64, dtype=torch.long).random_(0, 21)
# target.requires_grad = True
output = loss(data, target)
# output.backward()
print(output.shape)
### torch.Size([8, 64, 64, 64])