advanced25 min studyLesson 589 in Engineering

Topology-changing training resume

Separate supported state redistribution from preserving effective batch semantics, numerical behavior, and data ownership after scaling.

On this page

What you’ll understand

  • Distinguish data, tensor, pipeline, and expert parallel compatibility.
  • Preserve a stipulated global batch while changing data-parallel degree.
  • Define oracles for logical equivalence without promising bitwise identity.

Loading the same logical tensors on a different number of accelerators is only one part of elastic recovery. The new layout can also change effective batch size, random-stream assignment, data ownership, communication order, and memory peaks. A supported resharding path must be paired with an explicit training-policy decision. Otherwise a successful load can quietly start a different experiment.

Check compatibility by state category and parallel dimension

Data parallelism usually partitions different examples among replicas, while tensor and pipeline parallelism partition model computation. Expert parallelism introduces additional ownership and routing state. A format that can redistribute one category of shards need not support every combination or arbitrary model changes. Megatron documents distinct optimizer formats with different model-parallel resharding capabilities. Its global tensor mapping cannot make an unsupported legacy optimizer encoding portable. Preserve the original immutable checkpoint while converting so a failed conversion does not destroy the last proven recovery point.

Universal Checkpointing studies a logical representation that separates state from its physical parallel arrangement. That is a capability of a specified framework and supported model mapping, not a promise that any rank-file directory can resume anywhere. Validate architecture, tensor names, shapes, optimizer semantics, and object state. Build the destination configuration first, estimate its memory needs, and use a tested format conversion where required. A full-state consolidation path can have a very different host-memory peak from direct sharded loading, even if final per-device shards fit comfortably.

Mshard,ideal=MpartitionablepM_{\rm shard,ideal}=\frac{M_{\rm partitionable}}{p}
For p equal owners and evenly divisible lossless partitionable state, the expression gives ideal bytes per owner. It excludes replicated state, padding, metadata, live inputs, optimizer temporaries, communication buffers, and restore-time staging. Total device count is not always the relevant sharding degree.↔ Scroll wide equations horizontally.

Preserve or explicitly change the optimization contract

Under a simple equal-example data-parallel setup, effective examples per update equal replica count times local microbatch size times accumulation steps. Changing replica count while leaving the other factors unchanged changes that batch. Decide whether to preserve it or change the learning policy intentionally. Token-based objectives, variable sequence lengths, masked examples, and unequal rank contributions require actual contribution counts and correct normalization; the simple product is not a universal effective-token formula. Scheduler progress should use the intended committed-step or token convention rather than a newly inferred wall-clock duration.

A new rank assignment can change how samples are partitioned and how rank-local random streams are consumed. Preserve logical sample progress and define how unfinished prefetched work is redistributed. Simply restoring old rank zero’s cursor into new rank zero can repeat or omit data when membership changes. Counter-based randomness keyed by logical sample and operation can help only when the implementation actually defines and preserves that mapping. It does not automatically remove changes from different kernel or collective reduction orders.

Bglobal=pDP blocal aB_{\rm global}=p_{\rm DP}\,b_{\rm local}\,a
This equal-size example counts examples per successful optimizer update, with p_DP data-parallel replicas, b_local examples per microbatch per replica, and a accumulation microsteps. It assumes all contributions are used once and excludes variable token weights, dropped work, and other parallel dimensions.↔ Scroll wide equations horizontally.

Make a topology transition a tested recovery event

First verify reconstructed logical state, then compare the next data identities, optimizer counters, normalized gradients, and parameter update under the new layout. Bitwise matching may fail because reassociated floating-point reductions change rounding, even when the mathematical update is equivalent. Set tolerances from a reference and numerical analysis rather than widening them until every run passes. If changing batch or learning-rate policy intentionally, label the transition and evaluate that new trajectory instead of claiming uninterrupted equivalence.

The optimization lab shows how equal current values can hide different continuation rules. Reset, set both η=0.5 and x₀=2, predict x₂=0.5 and x₃=0.25, then Step three times and inspect both positions. Separately Reset, set both η=1.5 and x₀=2, predict x₂=0.5 and x₃=−0.25, then Step three times. Both runs agree at iteration two but differ at the next update. This fixed quadratic model has no topology, sharding, or distributed optimizer; it supports only the distinction between matching current state and matching future behavior.

Keep the example batch fixed while scaling replicas

An equal-example run uses eight data-parallel replicas, four examples per local microbatch, and four accumulation microsteps. It resumes with sixteen data-parallel replicas and the same local microbatch size. Assume complete equal contributions and an unchanged objective.

  1. The original global batch is 8×4×4=128 examples per successful update. The factors describe data-parallel replicas, not all devices used for tensor or pipeline parallelism.

  2. To retain 128 examples with sixteen replicas and local size four, choose a=128/(16×4)=2 accumulation microsteps. Keeping four would instead produce 256 examples per update.

  3. This preserves the simple batch count only. The loader must still restore optimizer and scheduler state, reconstruct the next logical data, verify normalization, and compare updates under a justified tolerance for changed parallel reduction order.

The result

A topology change needs both a state-mapping plan and a training-semantics plan. Equal parameter shapes or a successful load establish neither by themselves.

Explore the model

Interactive lab

Interactive lab · optimization

Matching a current value does not prove the next update

Reset, set both η=0.5 and x₀=2, predict x₂=0.5 then x₃=0.25, and Step three times. Separately Reset, set both η=1.5 and x₀=2, predict x₂=0.5 then x₃=−0.25, and Step three times. The fixed quadratic model illustrates continuation rules, not topology-changing training or sharded loading.

Matching a current value does not prove the next updateGradient 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 forValidate the next transition as well as the currently reconstructed values.

Check your understanding

A supported loader reconstructs every tensor after doubling data-parallel replicas. What additional check is necessary for faithful continuation?

Try it yourself

Sixteen data-parallel replicas use two examples per local microbatch and four accumulation microsteps. If the job shrinks to eight replicas with unchanged local size, how many accumulation microsteps preserve the simple global batch?

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

Give me a hint

Compute the original examples per update before solving for the new accumulation factor.

Compare with the solution

The original batch is 16×2×4=128 examples. With eight replicas and local size two, a=128/(8×2)=8 accumulation microsteps. This arithmetic assumes equal complete contributions; it does not by itself preserve sample order, token-weighted normalization, numerical rounding, scheduler semantics, or an unsupported optimizer resharding format.

Take it with you

  • Verify support for each state category and changed parallel dimension.
  • Preserve effective batch and data progress or record the intentional policy change.
  • Use logical and numerical next-update oracles separately from bitwise claims.

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.