Zenaique

Micro batch vs effective batch in fine-tuning: give the relationship

Flashcard·Easy·4.0 · 0·~30s·Asked atNykaaOlaRedis·Relevant atCoreweaveDatabricksFireworks AiLambda Labs
Attempt it
TL;DR

Micro batch is what fits in one GPU in one pass. Effective batch is what the optimizer sees per step: micro batch times gradient accumulation steps times data-parallel GPU count.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine cooking a stew that serves 64 people, but your largest pot only holds 4 servings. Two options. You can cook 16 small pots one after another and pour them all into one big stockpot before serving (accumulating small pots over time), or you can have 16 cooks each making one small pot in parallel and pooling them (cooking on many stoves at once). Either way the diners receive the same 64-serving stew. The size of one pot is the micro batch: hardware constraint. The size of what reaches the dinner table is the effective batch: what the recipe actually cared about. The recipe was tuned for 64 servings, and as long as you reach 64 by any combination of more pots over time or more cooks in parallel, the dish tastes right.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Almost every fine-tuning reproducibility bug eventually traces back to a confusion between micro batch and effective batch. The two are both called 'batch' in training code, but they answer completely different questions and one cannot be substituted for the other without breaking the recipe. Internalising the distinction once saves an enormous amount of debugging time.

Micro batch is a hardware concept. It is the number of examples that fit on one GPU in one forward and backward pass, bounded by activation memory. On a 24 GB consumer GPU running a 7B model at 2048 tokens, the micro batch is often 1 or 2. On an 80 GB H100 it might be 4 or 8. The micro batch number tells you nothing about how the optimizer behaves; it only tells you what your hardware can hold.

Effective batch is a statistical concept. It is the number of examples whose gradients are averaged together before the optimizer takes a step. The learning rate, the weight decay, the warmup schedule, all of the optimisation hyperparameters were tuned against this quantity. Two runs with the same effective batch but different micro batches will converge to similar results; two runs with the same micro batch but different effective batches will not.

The relationship is a simple product: effective batch equals micro batch times gradient accumulation steps times the number of data-parallel GPUs. Each factor contributes a different mechanism, and any combination of values that reaches the target effective batch will reproduce the recipe. This deep dive walks through each factor in detail, explains why accumulation is mathematically equivalent to a large batch for transformers, shows why data parallelism contributes a multiplier rather than independent runs, and lays out the practical implications for porting recipes across hardware shapes.

The two definitions and why both names exist

Micro batch is the number of examples processed in one forward-backward pass on one GPU. It is the quantity you set as per_device_train_batch_size in Hugging Face Trainer or as train_micro_batch_size_per_gpu in DeepSpeed configs. The bound on this number is activation memory, which scales with batch size, sequence length, hidden dimension, and number of layers.

Effective batch is the number of examples whose gradients are averaged before the optimizer steps. It is the quantity the recipe is implicitly tuned against, even when the recipe documentation calls it 'batch size' without qualifying which kind.

Both names exist because the two roles diverged historically. In the early deep-learning era, GPUs were small relative to models and a single physical batch was the only kind of batch in play. As models grew, that single batch became too large to fit on one GPU and the field developed gradient accumulation (one GPU, multiple sequential micro batches) and data parallelism (multiple GPUs, one micro batch each, gradients averaged). Both techniques produce an effective batch larger than the micro batch, and the term 'batch' became ambiguous unless qualified.

The practical consequence is that any modern training config has at least two numbers that affect the optimizer's view of batch size: per_device_train_batch_size and gradient_accumulation_steps. Add a multi-GPU world size and you have three. The recipe author tuned for the product of all three; reproducing the recipe means hitting that product, by any combination.

Gradient accumulation: the first multiplier
Data parallelism: the second multiplier
Why effective batch is the tuning quantity
Practical patterns and the traps that bite
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
AspectMicro batchEffective batch
What it isExamples per GPU per forward-backward passExamples whose gradients are averaged before optimizer step
Bound byActivation memory on one GPURecipe choice; product of micro, accumulation, world size
What the LR is tuned againstNo (hardware artifact)Yes (statistical quantity)
Effect of doubling itDoubles activation memoryRoughly doubles per-step gradient signal to noise
Common typical value1 to 8 per H100 on 7B model32 to 256 for LoRA fine-tunes

Real products, models, and research that use this idea.

  • Hugging Face Trainer's per_device_train_batch_size, gradient_accumulation_steps, and world_size combine multiplicatively into effective batch and are the canonical knobs in modern fine-tuning scripts.
  • QLoRA recipes for Llama 3.1 8B routinely set micro batch 4 with accumulation 8 on one GPU to hit an effective batch of 32, matching the published learning rate.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does linear LR scaling break down at very large effective batches?
A

Linear scaling assumes the gradient noise scale matches the optimizer's tolerance. At very large effective batches the per-step gradient becomes too low-noise for SGD-style optimisers to explore well, and the optimum effective step size grows sub-linearly. Square-root scaling is a common empirical compromise; warmup also has to lengthen because the first few steps with a large effective batch can destabilise.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Treating micro batch as the value the LR schedule was tuned against. Recipes are written for effective batch; using the wrong one quietly mis-scales the learning rate.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The two definitions: micro batch as memory constraint, effective batch as optimizer-step quantity

  • The product formula linking micro batch, accumulation steps, and data-parallel GPU count

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy