Adam optimizer state per parameter: fill in the moment buffers and bytes
Two fp32 buffers per parameter: m for the first moment and v for the second, four bytes each, eight bytes of optimizer state per trainable parameter.
Imagine a coach watching every player on a roster across many games. For each player, the coach keeps two notepads. The first notepad records the running average of how much the player moved in each game, in which direction. The second notepad records the running average of how big those moves were, ignoring direction. Both notepads stay open between games so the coach always has a smoothed picture per player. Adam works the same way for parameters. There is one notepad per parameter for the first moment of the correction signal and one for the second moment of that same signal. Each notepad holds a number that takes four bytes of memory. Two notepads at four bytes each adds up to eight bytes of optimizer bookkeeping per parameter.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: two moments m and v + why both are fp32 + 8-bytes per parameter calculation + total memory implications at 7B and 70B + how 8-bit Adam, paged Adam, ZeRO-1, and LoRA each shrink the number.
Real products, models, and research that use this idea.
- Hugging Face Transformers and TRL default to AdamW in fp32 state, which is why their out of the box 7B fine-tune needs roughly 56 GB for optimizer state alone.
- bitsandbytes ships 8-bit AdamW that quantises m and v from fp32 to int8 with block-wise scaling, cutting optimizer state from 8 bytes to about 2 bytes per parameter.
- DeepSpeed ZeRO-1 shards the fp32 Adam state across data-parallel ranks, so an N-rank job carries 8/N bytes of optimizer state per parameter per GPU.
- QLoRA recipes pair 4-bit base weights with 8-bit AdamW state on the adapters only, which is what makes 70B-class fine-tuning on a single 80 GB GPU feasible.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Adam state need fp32 when the model runs in bf16?
QHow does 8-bit AdamW preserve training quality despite quantising m and v?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Forgetting that optimizer state is fp32 even in a mixed-precision run. Adam's moments stay in fp32 for numerical stability while the model itself runs in bf16.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.