Hi Szandala!
The short story is that – for separate reasons – you are passing an
improper input and target to your CrossEntropyLoss criterion
function.



 szandala:

criterian = nn.CrossEntropyLoss()
...
        loss = criterian(output, Y.argmax())

I have output of tensor of shape 1x9


This is appropriate.  You have a batch size of 1, with 9 predictions
for a nine-class classification problem.


and target is a one element tensor,


This isn’t actually true.
Your Y is a one-dimensional tensor of length nine.  Y.argmax() is a
zero-dimensional tensor.  It is a “scalar” that holds a single value, but
it is not a one-dimensional tensor of length one.
You should feed Y.argmax().unsqueeze (dim = 0) into your loss
criterion.  This will have shape = [1], and so will have the necessary
batch size of one.


tensor([[0.1639, 0.2125, 0.1067, 0.1212, 0.1434, 0.0613, 0.0512, 0.0225, 0.1172]],
       device='cuda:0', grad_fn=<SoftmaxBackward>)



This tells me that your model has a final Softmax layer.  This is incorrect
for CrossEntropyLoss, which has, in effect, Softmax already built in.
Most likely, you should have the final output of your model be the output
of your last Linear layer (which should have out_features = 9).
Good luck.
K. Frank