Batch size is the number of training examples or inference requests processed together in one model computation. Grouping work can improve throughput and GPU efficiency, but it consumes more memory and may increase latency. section 3.4.7 section 6.1.3
Use batch size as a practical speed–memory–latency trade-off:
- Choose powers of two when possible, such as 16, 32, or 64, to improve speed and memory efficiency on GPUs. section 5.4.2 section 6.1.3
- Expect larger inference batches to require additional memory for the tokens processed concurrently; training requires substantially more memory for gradients and optimizer tensors. section 3.4.7
- Use adaptive or dynamic batching for services: pool requests until the maximum batch size or delay is reached, then return results to each client. section 6.1.3
- Increase the maximum batch size or batch delay only when the system has latency budget; doing so generally improves throughput while adding waiting time. section 6.1.3
A production constraint
A development environment achieved single-digit millisecond responses, but production imposed a batch size of 20. The fixed value limited optimization because surrounding systems depended on it. section 5.4.2
Table 5.2 Training choices to consider
|
Method
|
Improve speed
|
Improves memory utilization
|
Difficulty
|
|---|---|---|---|
|
Batch size choice
|
Yes
|
Yes
|
Easy
|
|
Gradient accumulation
|
No
|
Yes
|
Medium
|
|
Gradient checkpointing
|
No
|
Yes
|
Medium
|
|
Mixed precision
|
Yes
|
No
|
Hard
|
|
Optimizer choice
|
Yes
|
Yes
|
Easy
|
|
Data preloading
|
Yes
|
No
|
Medium
|
|
Compiling
|
Yes
|
No
|
Easy
|
Compare batch size with gradient accumulation, checkpointing, mixed precision, optimizer choice, data preloading, and compilation across speed, memory utilization, and difficulty. section 5.4.2











