Skip to main content

Training Steps, Epochs & Gradient Accumulation Calculator

Computes effective batch size, steps per epoch, total optimizer steps, warmup steps and optionally tokens seen for a fine-tuning run.

For anyone setting epochs, per-device batch size, gradient accumulation and GPU count.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

The arithmetic

Seven inputs: training examples, epochs, per-device batch size, gradient accumulation steps, GPUs, warmup ratio, and optionally average tokens per example. Counts must be whole numbers; examples may be 0, the others must be at least 1.

  • Effective batch = per-device batch × accumulation × GPUs.
  • Steps per epoch = ceil(examples / effective batch), keeping a partial final batch.
  • Total steps = steps per epoch × epochs.
  • Warmup steps = ceil(total steps × ratio).
  • Tokens seen = examples × epochs × tokens per example, shown only when you fill in the optional field.

Worked example

Defaults: 50,000 examples, 3 epochs, per-device batch 4, accumulation 8, 1 GPU, warmup ratio 0.03.

  • Effective batch: 4 × 8 × 1 = 32.
  • Steps per epoch: 50,000 / 32 = 1,562.5, rounded up to 1,563.
  • Total optimizer steps: 1,563 × 3 = 4,689.
  • Warmup steps: 4,689 × 0.03 = 140.67, rounded up to 141.
  • With 512 tokens per example, tokens seen are 76,800,000.

Moving to 4 GPUs with the same settings gives an effective batch of 128, 391 steps per epoch and 1,173 total steps. That is a different training recipe, not just a faster one, so the learning rate usually needs revisiting.

Caveats and sources

  • Last batch: the step count assumes the final partial batch is kept. Dropping it lowers the count.
  • Step definition: a step here is an optimizer update, not a forward pass. Logging and checkpoint intervals in your framework may be expressed in either.
  • Packing and padding: tokens seen is based on the average you enter, not on actual tokenised lengths.

Sources: Hugging Face Transformers documentation, Trainer and TrainingArguments (gradient_accumulation_steps, warmup_ratio), and the Hugging Face Accelerate gradient accumulation guide.

Frequently Asked Questions

Common questions about the Training Steps, Epochs & Gradient Accumulation Calculator

Effective batch size is per-device batch size times gradient accumulation steps times the number of GPUs. With 4 examples per device, 8 accumulation steps and 1 GPU it is 32 examples per optimizer update. Doubling the GPU count doubles it unless you halve the other terms to compensate. This matches the convention used by the Hugging Face Trainer.

From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Explore More Tools

Explore these related tools for your next step.

ai
ai
ai
ai
ai
ai