why do u need .mean() before the .backward()? It seems cannot remove the .mean(). In my case, the backward is something like this

loss  = nn.CrossEntropyLoss()
loss = (out, y)
loss.backward()

and the loss cannot be updated