induwara.lk
induwara.lkAI · Training

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.

By Induwara AshinsanaUpdated Jul 10, 2026
Training steps & epochsHugging Face Trainer
Self-verified
Presets

Rows in your dataset.

per_device_train_batch_size.

Data-parallel replicas.

Micro-batches per optimizer step.

num_train_epochs (may be fractional).

Tokens per sample (padded).

Fraction of total steps (0–1). warmup_steps override applies if you switch to steps.

Total training steps
4,686
Feed this to max_steps
Global batch size
32
8 micro × 4 accum
Steps per epoch
1,562
+1 partial step/epoch (2 left over)
Warmup steps
141
3.01% of total
Micro-batches / epoch
6,250
Total fwd/bwd passes
18,750
Micro-batches across the run
Tokens seen (approx)
76.80M
76,800,000 total
Samples processed
150.0K
Micro-batches × micro-batch size

Formula breakdown

QuantityFormula (your numbers)Value
Global batch size8 × 1 × 432
Micro-batches / epochceil(50,000 / 8)6,250
Update steps / epochmax(floor(6,250 / 4), 1)1,562
Total training stepsfloor(1,562 × 3)4,686
Total fwd/bwd passesfloor(6,250 × 3)18,750
Tokens seen (approx)50,000 × 3 × 51276,800,000
Warmup stepsround(0.03 × 4,686)141

Copy-ready TrainingArguments

TrainingArguments(
    output_dir='./out',
    num_train_epochs=3,
    per_device_train_batch_size=8,
    gradient_accumulation_steps=4,
    max_steps=4686,  # optional; overrides num_train_epochs
    warmup_ratio=0.03,  # ≈ 141 steps
)

Sources cited: step-counting mirrors the Hugging Face Trainer (num_update_steps_per_epoch = len(dataloader) // gradient_accumulation_steps), with PyTorch DataLoader drop_lastsemantics. Full links in “Sources & references” 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:

  1. Micro-batch size — the tensor that goes through the model at once is B × D. The global (effective) batch size is B × D × G, because G micro-batches are accumulated before one weight update.
  2. Micro-batches per epoch — this is len(dataloader). With PyTorch's drop_last=false the final partial batch is kept, so it is ceil(N / (B × D)); with drop_last=true it is dropped, giving floor(N / (B × D)).
  3. 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 the max(…, 1) floor guarantees at least one step even for a tiny dataset.
  4. Total training steps floor(steps_per_epoch × E). This is the value to pass as max_steps, which overrides num_train_epochs when set. Fractional epochs are floored, matching int(...) in the source.
  5. Forward/backward passes and tokens — total micro-batches over the run is micro_batches × E; approximate tokens seen is N × E × L, treating every sample as padded to L.
  6. 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 explicit warmup_steps overrides warmup_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

Single-GPU 7B fine-tune

N=50,000 · B=8 · D=1 · G=4 · E=3 · L=512 · warmup 0.03

  1. Micro-batch size: 8 × 1 = 8
  2. Global batch size: 8 × 1 × 4 = 32
  3. Micro-batches/epoch: ceil(50,000 / 8) = 6,250
  4. Steps/epoch: max(floor(6,250 / 4), 1) = 1,562 (6,250 % 4 = 2 → +1 partial step/epoch)
  5. Total steps: floor(1,562 × 3) = 4,686 → max_steps
  6. Total fwd/bwd passes: 6,250 × 3 = 18,750
  7. Tokens seen: 50,000 × 3 × 512 = 76,800,000 ≈ 76.8M
  8. Warmup steps: round(0.03 × 4,686) = 141

Small multi-GPU adapter tune

N=1,200 · B=2 · D=2 · G=8 · E=5 · L=1,024 · warmup 0.10

  1. Micro-batch size: 2 × 2 = 4
  2. Global batch size: 2 × 2 × 8 = 32
  3. Micro-batches/epoch: ceil(1,200 / 4) = 300
  4. Steps/epoch: max(floor(300 / 8), 1) = 37 (300 % 8 = 4 → +1 partial step/epoch)
  5. Total steps: floor(37 × 5) = 185
  6. Total fwd/bwd passes: 300 × 5 = 1,500
  7. Tokens seen: 1,200 × 5 × 1,024 = 6,144,000 ≈ 6.14M
  8. Warmup steps: round(0.10 × 185) = round(18.5) = 19

Edge case — dataset smaller than a batch

N=5 · B=8 · D=1 · G=4 · E=2 · L=128 · drop_last=true

  1. Micro-batch size: 8 × 1 = 8
  2. Micro-batches/epoch: floor(5 / 8) = 0 (no full batch forms)
  3. Steps/epoch: max(floor(0 / 4), 1) = 1 (the max(…, 1) floor runs one step)
  4. Total steps: floor(1 × 2) = 2
  5. Total fwd/bwd passes: floor(0 × 2) = 0
  6. Tokens seen: 5 × 2 × 128 = 1,280
  7. The tool warns that drop_last is discarding the whole dataset — turn it off or lower the batch size.

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.