loss.item() should be a float32 scalar value. How large is the expected StackedLossTensor, that you are running out of memory?
The posted code snippet assumed that the loss is stored for each batch during training.
Let me know, if I misunderstood your question.