Thank you very much, I think that this could be my mistake!
In my code:
outputs.size() returns torch.Size([32,1])
and
targets.size() returns torch.Size([32])
Should I transform outputs.size() to  torch.Size([32]) or targets.size() to  torch.Size([32,1])? Or it’s the same?
Thank you very much, I hope this is going to solve my problem. And thanks also for noticing the problem with l2_reg