NLLLoss doesn’t ask for one-hot encoding. Input to the NLLLoss is (N,C) where C is the number of classes and the target is (N). Are you inputting elements one-by-one and accumulating the loss for each element? Can you recode so that you can input larger batches instead of batch size of 1? Accumulating loss for each element will surely result in a huge memory requirement.