Hi Neta!



 netaglazer:

i have a multi class problem and i want to use MSE loss


As an aside, you probably don’t want to use MSELoss for a
multi-class problem.


    loss = out.sum(0)

but now the loss is a tensor with 61 length (i have 61 classes)
and i get error:
“grad can be implicitly created only for scalar outputs”


out.sum(0) is summing over the batch dimension of your
input / target (even if your batch size is 1).
Given what you say, I speculate that input (the output of your
model) is a vector of 61 values, one for each class (for a single
sample in your batch), and that target is also a vector of 61
values (perhaps your class labels one-hot encoded).
If you want to do this (and your probably don’t), you should be
using out.sum() to sum over all elements of the out tensor,
that is, over both the batch and class dimensions.
Best.
K. Frank