Compute the effective batch from per-device batch, accum steps, and GPU count
Effective batch is per_device_train_batch_size times gradient_accumulation_steps times world_size. With 2, 8, and 4 GPUs that is 64 examples per optimizer update.
Imagine four bakery teams each baking trays of cookies. Each team's oven only fits two trays at a time, so they bake two trays per oven round. They keep collecting cookies into a shared pile and only deliver the pile to the storefront after eight oven rounds. That means each team contributes 2 trays per round times 8 rounds equals 16 trays before delivery. Four teams doing this in parallel deliver 4 times 16 equals 64 trays per delivery cycle. The optimizer is the storefront and one delivery cycle is one update. The accumulation steps are the oven rounds, and the GPUs are the bakery teams.
Detailed answer & concept explanation~6 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: state the three-factor formula, walk through the worked example, then cover the loss-reduction trap and the LR-scaling implication that catch most teams.
Real products, models, and research that use this idea.
- Hugging Face Trainer logs effective_train_batch_size at startup as per_device times accum times world for exactly this reason.
- Axolotl's YAML configs expose all three knobs explicitly so users can compute the effective batch before launching long Llama 4 fine-tuning runs.
- Unsloth recipes for Qwen 3.5 on a single 24GB GPU use per_device=4, accum=8, world=1 to reach an effective batch of 32 without OOM.
- DeepSpeed and Accelerate's launcher both expose train_micro_batch_size_per_gpu and gradient_accumulation_steps as separate first-class config keys.
- Multi-node Llama 4 Maverick fine-tunes at large compute orgs routinely use per_device=1, accum=32, world=64 to reach effective batches of 2048.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does tensor parallel not multiply the effective batch the way data parallel does?
QHow should you adjust the learning rate when scaling from 4 GPUs to 16 GPUs with the same per-device batch and accumulation?
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 to multiply by world_size when computing effective batch. The optimizer sees the combined gradient from all data-parallel ranks, not just one rank's contribution.
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.