Router precision: protect the selection margin as well as softmax
Separate stable probability evaluation from robust expert ordering, and evaluate selective precision, logit regularization, and near-tie sensitivity.
On this page
The question for today
What you’ll understand
- Derive a sufficient top-k margin condition under bounded logit perturbations.
- Distinguish max-shift stability, router dtype, and logit z-loss.
- Test routing identities alongside loss and gradient behavior.
A tiny numerical change in a dense layer may slightly change its output. In a sparse router, the same change can choose a different expert and alter communication, capacity admission, and subsequent gradients. Stable exponentials therefore solve only part of the problem. Investigate both probability evaluation and the margin separating selected from unselected logits, under the exact dtype and training configuration.
A stable softmax does not restore a lost ordering
For finite logits, subtracting their maximum before exponentiation avoids positive exponential overflow in the mathematical normalization. It does not undo errors already introduced while computing or storing the logits, and tiny probabilities can still underflow. Top-k ordering can be computed from logits without exponentiating because exact softmax preserves their order. In finite arithmetic, however, rounding can collapse nearby values into ties. Define nonfinite handling, tie policy, and where precision promotion occurs rather than declaring the router stable because it subtracts a maximum.
Switch's selective-precision design uses higher precision locally in routing while keeping other work and communicated tensors at lower precision under its stated implementation. Megatron-Core 0.15.0 exposes router dtype choices with their own scope. Promoting a previously rounded low-precision logit cannot recover its missing bits; performing the relevant projection and normalization in a wider path is a different intervention. Compare these choices with matched model parameters and inputs, and inspect the generated execution path rather than assuming a configuration name proves every router operation uses that dtype.
Margins and logit penalties answer different questions
Suppose every computed logit differs from a reference by at most epsilon. If the gap between the kth and next logit exceeds twice epsilon, no selected logit can fall below an unselected one under that bound. This is a sufficient ordering condition, not an estimate of the actual error or a quality guarantee. Near the boundary, compare selected identities explicitly. A probability difference that looks negligible can change capacity survivors or route a representation to an expert with very different parameters.
Router z-loss, introduced in ST-MoE, penalizes squared log-sum-exp under a stated coefficient and batch reduction. It controls a logit-scale-related quantity rather than directly enforcing uniform hard assignments. Adding a common constant leaves softmax probabilities unchanged but changes log-sum-exp and thus this penalty. It is distinct from entropy regularization and the hard-count/soft-mass auxiliary objective. If several regularizers are combined, log each scaled component and inspect their gradients; improved numerical behavior does not establish that the expert workload became balanced.
Trace numerical changes through routing and training
Test well-separated logits, exact ties, near ties, large common offsets, and the declared nonfinite cases. Compare reference logits, selected expert identities, selected weights, overflow masks, auxiliary terms, and router-gradient norms. A count histogram can miss swapped token identities. Use fixed routing in one ablation to isolate expert numerical error, then restore live routing to measure selection sensitivity. For a stability intervention, compare convergence at matched data order and token budget as well as immediate throughput and memory cost.
The network lab only evaluates a stable binary sigmoid. Reset, set x=1 and w=1, predict p≈0.622459, then Play or Step. Separately Reset, set x=1 and w=1.05, predict p≈0.634136, then Play or Step. Both control values are reachable. The instrument has no dtype conversion, top-k boundary, logit projection, or z-loss. It shows a continuous probability response; the hand example establishes how a separate finite representation can collapse ordering before such normalization occurs.
Work it through
A near tie can disappear before normalization
Two reference logits are [1,1.001]. Round each directly to IEEE bfloat16 with round-to-nearest, ties-to-even, and use a stipulated lowest-index winner for exact ties. Consider top one.
Near one, bfloat16 spacing is 2⁻⁷=0.0078125. The increment 0.001 is below half that spacing, so both stored logits become exactly one.
The reference ordering selects the second expert because 1.001>1. The rounded pair is tied, so the stipulated tie rule selects the first expert instead.
Subtracting the rounded maximum or later promoting those two ones to a wider dtype cannot reconstruct the lost distinction. Wider evaluation before this rounding, or an explicit tolerance study, addresses a different stage of the problem.
An apparently small logit error changes expert identity in this scoped hand example. The result does not prescribe any library's undocumented tie order.
The living notebook
Explore the model
Interactive lab · network
A continuous probability response is only one part of routing
Reset, set x=1 and w=1, predict p≈0.622459, then Play or Step. Separately Reset, set x=1 and w=1.05, predict p≈0.634136, then Play or Step. The fixed sigmoid does not round logits, choose experts, or implement router z-loss.
- Product · wx
- 1.2
- Logit · wx − 0.5
- 0.7
- Sigmoid output
- 0.6682
One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. 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 forProbability stability and discrete selection robustness require different evidence.
Pause & reason
Check your understanding
Your turn
Try it yourself
Each logit has a known absolute error bound 0.002. Does a boundary gap 0.006 satisfy the stated sufficient condition? What about gap 0.003?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compare each gap with twice the error bound, using a strict inequality.
Compare with the solution
Twice the bound is 0.004. Gap 0.006 exceeds it and guarantees unchanged selected membership under the assumptions. Gap 0.003 does not satisfy the condition; a flip is possible but not inevitable. The guarantee does not imply identical probabilities or identical later capacity admission.
Keep the idea
Take it with you
- Stable exponentials do not repair already rounded router logits.
- Selection margins provide a scoped robustness condition.
- Selective precision, z-loss, and load balancing target different mechanisms.
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.