advanced26 min studyLesson 629 in Engineering

Control optimizer steps and effective exposure

Relate microbatches, accumulation, target tokens, and schedules without treating one default learning rate as universal.

On this page

What you’ll understand

  • Count effective sequences per optimizer update under explicit data-parallel assumptions.
  • Distinguish optimizer steps, examples, and selected target-token exposure.
  • Compare hyperparameters with fixed artifacts, objective, and evaluation.

A learning rate means little without the optimizer, gradient normalization, batch structure, and number of updates. Fine-tuning configurations can look similar while exposing an adapter to very different target-token counts. Gradient accumulation and distributed training add another layer of reduction semantics. Make the effective experiment visible before changing rank, epochs, or learning rate, and evaluate target gains together with retention rather than treating lower training loss as the release criterion.

Count the unit passed to an optimizer step

With D data-parallel workers, an unpacked per-worker microbatch of b sequences, and A accumulation microsteps, a full update processes D×b×A sequences when all workers contribute complete microbatches. This count does not establish an identical gradient to one large batch unless loss normalization, stochastic behavior, and optimizer stepping are equivalent. Last partial batches, dropped records, packing, and variable target lengths can change both the count and the effective weighting. Record realized rather than merely configured exposure.

Selected target tokens determine supervised mass under a token-mean objective. Two microbatches with the same number of sequences can have different target counts because prompt lengths, answer lengths, and masking differ. Averaging each microbatch's mean equally can unintentionally overweight short ones. Use the trainer's supported consistent reduction for the intended objective and inspect it for the pinned version. An accumulation factor is not permission to update optimizer moments on every microstep when the experiment assumes one update after accumulation.

Bseq=D b A,Mupdate=∑d,a,iMdaiB_{\rm seq}=D\,b\,A,\qquad M_{\rm update}=\sum_{d,a,i}M_{dai}
The first count assumes full equal unpacked microbatches in synchronized data-parallel training. The second sums actual selected targets over those examples. Neither formula by itself specifies gradient scaling or equivalence under another optimizer/reduction implementation.↔ Scroll wide equations horizontally.

Learning-rate schedules run on a defined clock

Warmup and decay may be indexed by optimizer steps, epochs, or another implementation-defined measure. Changing accumulation or data size changes how many tokens arrive before the same step number. Optimizer state, weight decay, gradient clipping, precision, and LoRA scaling also affect updates. Standard alpha/r adapter scaling is not a universal replacement for learning-rate selection, and other adapter variants use different rules. Check actual trainable tensors and gradients rather than assuming a configuration file matched every intended target.

Use controlled sweeps with a small, justified search budget and a held-out validation protocol. Record random seeds, early-stop rules, and how checkpoints are selected. Repeatedly picking the best result on one small test set overfits the selection process. A smaller learning rate can still accumulate a large behavioral change over enough steps, and a larger one can damage retention without obvious immediate training instability. There is no single rate or epoch count that guarantees safe adaptation across datasets and bases.

θt+1=θt−ηtgt\theta_{t+1}=\theta_t-\eta_t g_t
This is illustrative plain gradient descent with parameter vector theta, learning rate eta, and a consistently defined gradient g. Actual Adam-family updates, decay, clipping, and mixed-precision logic have additional state and are not represented by this equation.↔ Scroll wide equations horizontally.

Measure the run that actually happened

Log completed optimizer updates, selected target tokens, gradient norms, validation outcomes, and peak resource use. Check for skipped updates, nonfinite gradients, and batches with no supervised targets. Preserve the exact data/split manifest and preprocessing configuration so exposure comparisons remain meaningful. If a run resumes, restore the intended optimizer, scheduler, sampler, and random state where reproducibility requires it. Loading adapter weights alone is not necessarily a faithful continuation of the training experiment.

The optimization lab is a bounded smooth illustration. Reset and set both η=0.5, x₀=2, predict first update x=1 and lower quadratic loss. Reset and re-set η=2.5, x₀=2, predict first update x=−3 and higher loss on f(x)=x²/2, then inspect as iterations advance with Play or Step. These reachable controls show this fixed model's unstable regime, not an LLM optimizer or learning-rate recommendation. It has no Adam state, token batches, LoRA scaling, or retention tasks.

A sixty-four-sequence update

Four data-parallel workers each process unpacked microbatches of two sequences and accumulate eight microsteps. A dataset has 3200 sequences and runs exactly two epochs, with no partial batches. Every sequence has exactly 32 selected targets.

  1. Each optimizer update processes 4×2×8=64 sequences. One epoch therefore has 3200/64=50 complete updates under the stated schedule.

  2. Two epochs produce 100 updates and 6400 sequence presentations. Selected target exposure is 6400×32=204,800 tokens, not the total padded input-token count.

  3. A 10%-of-updates warmup would span ten optimizer updates in this declared 100-update run. Changing accumulation, packing, or mask lengths requires recomputing the effective experiment rather than reusing that step count blindly.

The result

Batch, step, and target-token clocks must be explicit to compare fine-tuning settings meaningfully.

Explore the model

Interactive lab

Interactive lab · optimization

A step-size contrast with fixed assumptions

Reset, set η=0.5, x₀=2, predict first x=1. Reset and re-set η=2.5, x₀=2, predict first x=−3. Play or Step advances exact gradient descent on one quadratic, not an LLM optimizer or fine-tuning recipe.

A step-size contrast with fixed assumptionsGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forStep size interacts with objective and dynamics;the toy cannot supply a universal adapter learning rate.

Check your understanding

Increasing accumulation changes sequences per update. What else must be checked before claiming an equivalent large-batch objective?

Try it yourself

Two workers use microbatch three and accumulation five, with full unpacked batches. Find sequences per update. If actual selected targets total 900 per update, how many targets are processed over forty updates, and why is that not necessarily the padded-input count?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use D×b×A for sequences and actual selected targets for supervision.

Compare with the solution

Each update processes 2×3×5=30 sequences. Forty updates supply 900×40=36,000 selected targets. Padded inputs also contain unsupervised prompts, formatting, and padding, so their token total can be larger. Consistent gradient normalization and exact completed updates still need verification;the arithmetic alone does not establish a particular model-quality outcome.

Take it with you

  • Effective sequence and target-token counts depend on actual batch processing.
  • Schedules and optimizer state run on explicit update clocks.
  • Controlled validation and retention checks matter more than copying one default rate.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.