Sparse reproducibility: compare routing identities before aggregate loss
Build layered tests for gate arithmetic, selection, capacity admission, permutation, gradients, and repeatability under a precisely recorded sparse-training configuration.
On this page
The question for today
What you’ll understand
- Separate algorithmic reproducibility, identity replay, and floating-point tolerance.
- Test ties, overflow order, pack/unpack maps, and backward routing.
- Record checkpoint and runtime state needed to interpret a repeatability claim.
A sparse model can produce the same count histogram while sending different tokens to experts, or choose identical experts while producing slightly different reductions. Reproducibility therefore needs several tests rather than one final-loss comparison. Define the configuration and acceptable numerical variation, then inspect identities and admission decisions before diagnosing a divergence as random noise or an optimization failure.
Separate gate, selection, admission, and arithmetic tests
Begin with a tiny reference using labeled tokens and known expert functions. Compare logits, full probabilities, selected identities, retained weights, capacity survivors, and final outputs as separate artifacts. Add exact ties and near ties with an explicitly supported tie rule. PyTorch 2.14 warns that tied top-k indices are not guaranteed stable, so an unstated index preference is not a portable reference. A deterministic selection requirement may need a deliberately implemented rule, whose numerical and performance cost should be evaluated.
Admission order can matter even when selection and total capacity are fixed. Position-based dropping depends on token order; score-based admission needs tie handling; randomized admission needs controlled random state. A token permutation may preserve a no-drop pointwise expert function but change a capacity-limited position policy. Do not demand permutation invariance from a policy that explicitly depends on position. Instead test its stated behavior and compare matched identities. The same distinction applies when changing routing groups or microbatch boundaries alters the capacity population.
Control the configuration without promising universal bitwise identity
Record data order, token masking, global expert identities, router parameters and dtype, gate normalization, capacity factors, admission policy, group membership, software versions, device architecture, and backend flags. Save optimizer and scaler state plus the relevant per-rank random-generator states for continuation. Dropout, router jitter, stochastic second choices, and randomized capacity selection may consume different random streams. A seed alone does not describe which operation consumed each value, particularly after graph or parallel-layout changes.
PyTorch's reproducibility guidance scopes deterministic settings to supported operations and environments rather than guaranteeing identical results across every version and platform. GPU reductions, atomics, fused kernels, and collective scheduling can alter floating-point order. Compare finite outputs and gradients with declared tolerances, while treating NaN and infinity under a separate policy. A small output difference can later change a near-tie selection, so track when routing first diverges. Distinguish repeatability within one configuration from equivalence between two changed algorithms.
Localize failures with a layered experiment
Test pack and inverse-pack operations using unique assignment labels, including zero-row experts and empty peer splits. Validate a fixed-routing expert forward and backward path before enabling live routing. Check gate gradients with small perturbations that stay away from membership and admission boundaries, then test boundary behavior as discrete events. Compare checkpoint resume against an uninterrupted run under the same recorded conditions. When parallel layout changes, verify the intended mathematical policy first; local capacity or nondeterministic arithmetic can legitimately prevent exact identity replay.
The modular lab supplies two deterministic orderings over four labels. Reset, set m=4 and a=1, predict residues 0,1,2,3 before returning to zero, then Play or Step. Separately Reset, set m=4 and a=3, predict 0,3,2,1, then Play or Step. Both have period four, but their order differs. The instrument has no top-k, random generator, or capacity admission. Use the ordering contrast to construct a paper test where a two-slot position policy admits different labels, showing why equal counts alone do not prove the same executed computation.
Work it through
A membership change can alter capacity survivors
Four labeled tokens request top-one experts. Run A selects [0,1,0,1]; run B selects [0,1,1,1]. Each expert has capacity two, admitting tokens in label order without rerouting.
Only token three changes selected expert, so D_route=1/4=25%. Requested counts change from [2,2] to [1,3].
Run A accepts every token. Run B accepts token one at expert zero and tokens two and three at expert one; token four's branch is rejected.
The accepted-token masks therefore differ at token four, also one quarter of tokens. Output and gradient comparisons must use these identities and the specified dropping rule rather than only total expert work.
A single membership change causes a different token to lose its branch. Routing, admission, numerical outputs, and gradients require separate diagnostics.
The living notebook
Explore the model
Interactive lab · modular
Equal period does not mean equal processing order
Reset, set m=4 and a=1, predict order 0,1,2,3 and period 4, then Play or Step. Separately Reset, set m=4 and a=3, predict 0,3,2,1 and period 4, then Play or Step. This deterministic orbit has no router, random seed, or admission buffer.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. 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 forAn order-dependent capacity policy needs identity-level tests even when aggregate counts agree.
Pause & reason
Check your understanding
Your turn
Try it yourself
Three labeled assignments A,B,C target one expert with capacity two and position-based admission. Compare input orders [A,B,C] and [C,A,B]. Can identical accepted counts establish identical computation?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Write the surviving labels before comparing any numerical result.
Compare with the solution
The first order accepts A and B; the second accepts C and A. Both accept two assignments, but their accepted identity sets differ. Unless the corresponding token/expert results happen to coincide, outputs and gradients differ. This behavior follows the stated position policy rather than violating an assumed permutation-invariance guarantee.
Keep the idea
Take it with you
- Trace gate arithmetic, selection, admission, and tensor restoration separately.
- Seeds do not replace complete runtime, policy, and checkpoint state.
- Use identity checks alongside scoped numerical tolerances and supported determinism controls.
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.