Zubnet AI学习Wiki › Batch Size & Epoch
Training

Batch Size & Epoch

Mini-Batch, Training Epoch
Batch size 是模型在更新参数前处理多少训练样本。Epoch 是完整过一遍训练数据集。一个在 100 万样本上训练 3 epoch、batch size 1000 的模型,每次更新处理 1000 样本,每个 epoch 要 1000 次更新,总共 3000 次更新。

为什么重要

Batch size 和 epoch 是训练中最基本的控制。Batch size 影响训练速度、内存使用、甚至模型学什么(小 batch 加入噪声可能帮助泛化;大 batch 收敛更快但可能泛化更差)。Epoch 数决定模型看每个样本多少次 — 太少就欠拟合,太多就过拟合。

Deep Dive

In practice, stochastic gradient descent processes the training data in random mini-batches. Each batch gives an estimate of the true gradient — larger batches give better estimates (less noise) but cost more memory and compute per step. Typical batch sizes range from 32 (small models, single GPU) to millions of tokens (LLM pre-training across thousands of GPUs).

The Large-Batch Training Challenge

LLM pre-training uses enormous effective batch sizes (millions of tokens per update) distributed across many GPUs. At this scale, the learning rate must be carefully tuned — the linear scaling rule (double the batch size, double the learning rate) works up to a point, then breaks down. Gradient accumulation lets you simulate large batches on smaller hardware by accumulating gradients across multiple forward passes before updating.

Epochs in the LLM Era

Modern LLM pre-training typically runs for less than one epoch on the full dataset — the data is so large that the model never sees all of it. This is a shift from classical ML where 10–100 epochs was normal. Research suggests that repeating data (multiple epochs) can actually hurt LLM performance due to memorization effects, though this depends on data quality. Fine-tuning, by contrast, typically runs for 1–5 epochs on a much smaller dataset.

相关概念

← 所有术语
← Backpropagation Beam Search →