每轮训练步数

🧮 Steps per Epoch Calculator

Compute the number of training steps per epoch from dataset size and batch size, for training-loop and sharding checks.

📐 计算公式 / 原理
每卡训练步数(本页代码口径):每卡步数=⌈数据集样本数÷批次大小⌉(向上取整);每步覆盖样本=批次大小×GPU 数。校验:无强校验,空值按 0 兜底;结果非有限时提示「部分结果无定义(分母为 0 或输入为空)」。判据:无固定分级,除不尽的余数样本并入最后一步。
多卡数据并行时,全局批量 = 单卡批量 × 卡数,每卡步数不变但每步实际看到的样本翻倍数等于卡数。因此扩卡后要保持等效训练强度,需按比例调大学习率或增加轮数。

📐 计算公式与说明

步数判读(与上式互补):步数=⌈数据÷批次⌉ 仅由数据规模与批次决定、与卡数无关——卡数只改变每步吞吐(每步覆盖样本=批量×卡数),页面两项并列展示。校验:与上方一致,空值按 0 兜底。判据:无固定分级,批次增大步数按比例减少,数据量翻倍步数翻倍。

分布式下每卡步数不变,总样本覆盖相同。

📚 深度解析:每轮训练步数

💡 常见使用场景

步数计算
N=50000, batch=64 → steps=⌈50000/64⌉=782 步/轮。4 卡数据并行每卡 batch=64 则每卡 782 步(总样本不变),等效 batch=256 使收敛更快。

❓ 常见问题(FAQ)

分布式每卡步数变少吗?
若每卡 batch 不变,每卡处理的样本数减少,步数按每卡样本算会减少;总计算量不变,只是并行加速,等效 batch 变大了。
尾批怎么影响步数?
向上取整已含尾批(不足 batch 的余量)。若启用 drop_last 则步数=⌊N/batch⌋,少算一个不完整批,需在指标上对应处理。

Formula & Standard References

Item Formula / Note Source / Standard
Steps formula steps per epoch equals the sample count divided by batch size rounded up PyTorch DataLoader docs
Last partial batch a non-dividing sample count leaves a smaller last batch that may be dropped PyTorch DataLoader docs
Distributed sharding with multiple devices per-device steps divide by the device count while shards must cover the data PyTorch DistributedDataParallel docs