Solved by Ali_Amiri in post #2 
              
              
                i found the solution 

output should be log_softmax with nll loss function
Y should be (batch_size,)
zero_grad should be called after encoder(x)