Batch Size
Batch size is the number of examples used to estimate the training gradient per update. It affects memory use, optimization noise, throughput, and generalization.
For a batch , the mini-batch loss is:
With distributed training and gradient accumulation, effective batch size is:
See Gradient accumulation for the difference between micro-batches, optimizer steps, and consumed samples.
Example Batch vs Token Batch
For fixed-size examples, example count is usually enough. For sequence, graph, or structure data, valid elements may vary:
or more generally:
where is a mask for valid elements. A batch of 8 long sequences can contain more learning signal and memory pressure than a batch of 32 short sequences.
Gradient Noise Scale
Batch size controls the stochastic gradient estimate:
With approximately independent examples:
This is why larger batches can make optimization smoother, while smaller batches add noise. The best batch size is a systems-and-optimization choice, not only a memory setting.
Learning Rate Coupling
Changing effective batch size changes update dynamics. A common heuristic is linear scaling:
but this is not a law. Warmup, optimizer choice, normalization, gradient clipping, and task distribution can make the relationship weaker.
Systems Boundary
Batch size is constrained by several memory terms:
Activation memory usually grows with batch size and sequence length. If memory is the limit, the alternatives are gradient accumulation, activation checkpointing, shorter context, lower precision, smaller model, or different batching.
Checks
- Is the reported batch size per device, global, or effective?
- Are gradients accumulated intentionally?
- Are accumulation steps included in the effective batch size calculation?
- Does the learning rate change with effective batch size?
- Does padding or variable-size data change the real number of valid elements?
- Is memory pressure from activations or optimizer state limiting batch size?
- Are schedules, validation intervals, and checkpoints counted in optimizer steps or consumed samples?
- Is throughput reported as examples/sec, tokens/sec, or optimizer steps/sec?
- Is evaluation using the same natural distribution even when training batches are balanced?