批次与轮次 · 一次更新不等于看完一遍Batch and Epoch · One Update Is Not One Full Pass
samples → batches → update steps → one full epoch
批次是一次更新使用的样本组;轮次是全部训练数据被看过一遍。100
张卡、每批 20 张,需要 5 次更新才完成 1 epoch。A batch is the sample group used for one update; an epoch means every training example has
been seen once. With 100 cards and batches of 20, five updates complete one epoch.
01 · 洗一整桶衣服01 · Wash a full hamper
洗衣机一次只能放 20 件;开了一次机器,能算整桶 100
件都洗过了吗?The washer holds 20 items. After one cycle, can you claim all 100 items in the hamper
were washed?
20×5
02调批量,看一圈需要几次更新Change Batch Size and Count Updates per Lap
唯一变量:batch sizeOne variable: batch size
batch
0/5
本轮更新updates this epoch
samples seen
0/100
本轮已看seen this epoch
epoch
0
完整轮次full passes
03不要把四个计数器混成一个Do Not Collapse Four Counters into One
sample · batch · step · epoch
SAMPLE
样本Sample
一张训练卡,是最小数据单位。One training card is the smallest data unit.
BATCH
批次Batch
一次共同计算梯度的样本组。A group used for one gradient calculation.
STEP
更新步Update step
处理一个 batch 后更新一次参数。One parameter update after one batch.
EPOCH
轮次Epoch
全部训练样本被看过一遍。Every training sample has been seen once.
04最小机制:更新数由数据量和批量共同决定Minimal Mechanism: Dataset and Batch Size Set Update Count
steps per epoch = ⌈N / B⌉
steps/epoch = ⌈N / B⌉
N = 100、B = 20 → 5 步。若 B 不能整除
N,最后一批会更小,仍算一次更新。N = 100 and B = 20 gives 5 steps. If B does not divide N, the smaller final batch
still counts as one update.
改变 batch sizeChange batch size每步样本数改变samples per step change
每轮步数改变Steps per epoch change⌈100/B⌉⌈100/B⌉
看完 100 张See all 100epoch 才加 1then epoch +1
05边界实验:把最后 10 张误算成整批Boundary Test: Mistake the Last 10 for a Full Batch
主动制造失败Create a failure
用 batch size = 30Use batch size = 30
100 ÷ 30 不是 3 个完整更新;还剩 10 张,需要第 4
步。忽略尾批就没有真正完成一轮。100 ÷ 30 is not three complete updates. Ten cards remain and need a fourth step;
ignoring them means the epoch never completed.
尚未执行。Not run yet.
✗ 一个 batch 就是一个 epoch。One batch is one epoch.
→ ✓ 只有看完全部训练集才是一轮。An epoch requires the entire training set.
✗ batch size 是训练总样本数。Batch size is total training samples.
→ ✓ 它只是一次更新用多少样本。It is samples used per update.
✗ 100/30 向下取整为 3 步。100/30 rounds down to three steps.
→ ✓ 尾批也要一次更新,所以向上取整。The tail batch needs an update, so round up.
06 · 一句话带走06 · One line to keep
batch 决定一次更新看几张,epoch
表示整套训练数据看完一遍;两者不能互换。A batch sets how many samples one update sees; an epoch means one full pass over
training data. They are not interchangeable.