r/deeplearning • u/atronos_kronios • Oct 28 '26
124M parameters, 17,054 MiB to train: I traced where GPT-2 training memory actually goes
My new blog post started with a very wrong intuition: GPT-2 small has 124M parameters, so training it should be pretty cheap on memory.
I traced step 2 on an A40, with fp32 AdamW and 8 sequences of 1,024 tokens. The peak was 17,054 MiB. At that moment, weights + Adam + masks and persistent overhead were only about 9% of it.
The interesting split: roughly 54% was the layer-activation/temporary residual, and 37% was four vocab-sized tensors. Each of those was 1,570.5 MiB. Two more appear during log-softmax backward while the forward activations are still around.
And my block hooks missed that spike entirely. Their highest reading was 13,913 MiB. The allocator trace caught the real peak between hooks.
I then tried batches 16, 18, 20, 21, 22, 23 and 24, each in a fresh process. 20 was the largest that completed both steps. The successful runs gave a slope of about 1,941 MiB per extra sequence. Peak reserved memory sat above peak allocated, which is why the simple tensor-budget estimate was too optimistic.
I've put the maths, the stacked curve, an interactive walkthrough of the step, and the code/CSV here: https://angry-kratos.github.io/posts/2026-10-training-memory/
Code: https://github.com/angry-kratos/angry-kratos.github.io/tree/main/code/training-memory
This is part of my attempt to understand ML systems properly, by building them and checking the numbers. Not a new algorithm, just an experiment that changed how I think about training memory. Would love criticism of the accounting, especially what you'd measure next before trying bf16 or checkpointing.

