AI Training Steps & Epochs Calculator
Turn your batch size, gradient accumulation and epoch count into the exact optimizer steps a run will take — steps per epoch, total training steps for max_steps, warmup steps and tokens seen. Counted the way the Hugging Face Trainer counts them. No signup, sources cited below.
How it works
Before launching a GPU run you usually want two numbers: how many optimizer steps it will take (to set logging, checkpoint and evaluation intervals, and to estimate wall-clock time) and a sensible warmup. Both fall out of a handful of exact formulas that the Hugging Face Trainer uses internally. This tool reproduces them so the count you plan against matches the count your training loop actually runs.
Let N = samples, B = per-device batch size, D = devices, G = gradient accumulation steps, E = epochs and L = sequence length. The derivation is:
- Micro-batch size — the tensor that goes through the model at once is
B × D. The global (effective) batch size isB × D × G, because G micro-batches are accumulated before one weight update. - Micro-batches per epoch — this is
len(dataloader). With PyTorch'sdrop_last=falsethe final partial batch is kept, so it isceil(N / (B × D)); withdrop_last=trueit is dropped, givingfloor(N / (B × D)). - Update steps per epoch — the HF Trainer computes
num_update_steps_per_epoch = max(len(dataloader) // G, 1). One optimizer step is one gradient update, so G micro-batches collapse into a single step, and themax(…, 1)floor guarantees at least one step even for a tiny dataset. - Total training steps —
floor(steps_per_epoch × E). This is the value to pass asmax_steps, which overridesnum_train_epochswhen set. Fractional epochs are floored, matchingint(...)in the source. - Forward/backward passes and tokens — total micro-batches over the run is
micro_batches × E; approximate tokens seen isN × E × L, treating every sample as padded to L. - Warmup steps — in ratio mode this is
round(warmup_ratio × total_steps); in steps mode the explicit value is used directly. In the HF Trainer an explicitwarmup_stepsoverrideswarmup_ratio.
One subtlety: when micro-batches per epoch is not an exact multiple of G, the leftover micro-batches still trigger a final optimizer step at the end of the epoch in recent Trainer versions. The tool surfaces this as a “+1 partial step per epoch” note so the floored figure and the real count never differ silently. Every formula above is verified against the two worked examples below at page-load time, and the “Self-verified” badge on the calculator only shows when they reconcile.
Worked examples
Frequently asked questions
Sources & references
- Hugging Face Transformers — Trainer & TrainingArguments reference
- Hugging Face Transformers — Trainer source (num_update_steps_per_epoch)
- PyTorch — DataLoader (drop_last semantics)
The step-counting formulas on this page were last cross-checked against the Hugging Face Trainer documentation and source on 2026-07-10. They are reviewed whenever the Trainer changes how it counts update steps.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.