Training loss erratic

Code reviewMedium18 minOpenAI and Anthropic style

Your task

Review this PyTorch training loop.

Training is unstable and the loss behaves erratically. What's missing?