All posts

QK-Clip, Audited: Kimi K2's Logit Cap Lags One Step Behind, α = 0.5 Is Load-Bearing Under Muon, and Weight Decay Does the Deactivating

8 min read optimizersmuonattentiontraining-stabilityllm-training

In the Kimi K2 technical report (arXiv 2507.20534), a 9B-active/53B-total MoE trained with plain Muon pushes its maximum attention logit past 1,000 within about 15k steps, and loss spikes follow. Logit soft-capping acts after the dot product has blown up, and QK-Norm doesn't fit multi-head latent attention (MLA), whose keys are never fully materialized at inference.

K2's fix is QK-Clip, which is applied to the weights, not to the activations. During the forward pass, record each head's largest pre-softmax logit:

S_max^h = max over batch, i, j of  (q_i^h · k_j^h) / sqrt(d)

After the optimizer step, if S_max^h > τ, set γ_h = τ / S_max^h and shrink that head's projections: W_q ← γ^α W_q, W_k ← γ^(1−α) W_k, with α "typically 0.5". The logit is bilinear in the two matrices, so the head's logit shrinks by exactly γ whatever α is. K2 combines this with Muon, decoupled weight decay, and Adam-RMS matching, calls the result MuonClip, and trains with τ = 100, η = 2e-4, λ = 0.1 and 67M-token batches. The report says the clip was active for the first ~70k steps, touched 12.7% of heads, and then never fired again.

I rebuilt the mechanism in numpy: one head, a retrieval task where each token must attend to a fixed partner, and Muon (quintic Newton–Schulz, μ = 0.95, update scaled by 0.2·sqrt(max(n,m))) on W_q and W_k. Numbers below are from that toy unless marked as K2's.

The MLA split checks out

In MLA, each head's logit is the sum of a content term q_C · k_C and a rotary term q_R · k_R, and k_R is shared across every head. K2 scales q_C and k_C by √γ, scales q_R by γ, and leaves k_R alone:

def qk_clip_mla(head, s_max, tau):
    if s_max <= tau:
        return
    g = tau / s_max
    head.W_qc *= g ** 0.5   # content query
    head.W_kc *= g ** 0.5   # content key
    head.W_qr *= g          # rotary query: takes the full factor...
    # head.W_kr untouched   # ...because the rotary key is shared by all heads

Both terms shrink by exactly γ: with γ = 0.37 on random vectors I measured a logit ratio of 0.3700. Carrying the MHA habit of √γ over to the rotary query gave 0.63 instead, under-clipping by whatever share of the logit lives in the RoPE dimensions. Algorithm 1 gets this right; it's the line to check in a reimplementation.

Reproducing the explosion, and a confound

On the solvable retrieval task with η = 0.01 and no weight decay, Muon pushed S_max from about 65 at step 100 to 1,207, where it stopped only because the softmax gradient underflowed in float64 (loss 2.6e-18). AdamW at the same learning rate leveled off at 43. That matches the report's direction.

The report's Appendix E blames Muon's flat, full-rank update spectra. My toy adds a confound: once the task is solved, Adam's ε brakes updates whose per-coordinate gradients fall below about 1e-8, while Newton–Schulz normalizes the whole momentum matrix and keeps taking full-size steps. Lowering Adam's ε raised its step-3,000 logit from 43 (1e-8) to 55 (1e-12) to 334 (1e-16). It isn't the whole story, since at step 300 Muon was at 478 and every Adam variant at 37. When comparing optimizers' logit growth, fix ε and report it.

Finding 1: the cap lags one step behind

The detail that matters is in the report itself: S_max "is already computed during forward." The forward pass used the weights from step t−1. γ is computed from that logit and then applied to the weights from step t, which already include the Muon update. On the same batch, the logit after the clip is therefore τ · S(W_t)/S(W_{t−1}), not τ.

Muon makes that ratio easy to predict. Every update has spectral norm η·s with s = 0.2·sqrt(max(n,m)), whatever the size of the weights. If the update lines up with the direction that grows the logit, one step multiplies it by about

r ≈ 1 + η·s·(1/σ_q + 1/σ_k)        σ = spectral norm of W_q, W_k

and the cap the clip actually holds is τ·r. In my toy (τ = 20, η = 0.01, s = 2.263), the clip settled the weights at σ_q ≈ σ_k ≈ 1.35, so the formula gives r = 1.0335 and a ceiling of 20.67. The measured S_max over 2,954 clipped steps had a mean of 20.68 and a max of 20.72. When I recomputed γ from the post-update logit (one extra forward pass), the measured value was 20.00 on every step.

At K2's settings the overshoot is small. For a 7168-wide matrix, s ≈ 16.9 and η·s ≈ 3.4e-3, so with illustrative spectral norms of 10 the overshoot is 0.07%. That fits the report's flat line at 100. Still, "S_max ≤ τ" is not what the mechanism guarantees. What it guarantees is S_max ≤ τ·r, and r goes up as clipping shrinks the weights, because Muon's step size doesn't shrink with them. Shrinking the weights makes each fixed-size step a larger fraction of their norm. With small or freshly initialized matrices, a high learning rate, or a warmup that ends while the clip is active, budget for that gap or set τ below the real target.

Finding 2: under Muon, α = 0.5 is load-bearing

The report gives α = 0.5 one sentence: it applies "equal scaling to queries and keys." Since the logit scales by γ for any α, you might think the split is a matter of taste. Under Muon it isn't, because of the formula above. Muon adds a fixed-size update regardless of weight size, so any matrix that clipping keeps shrinking gets a larger relative step on every iteration.

With α = 1.0 (clip only W_q), the toy ended with σ_q = 0.05 and σ_k = 54.75. W_q had collapsed 27× below the balanced run, and W_k had grown to make up the difference. The term 1/σ_q then dominates r. The formula predicts a ceiling around 29, and the measured S_max averaged 26.4 with a peak of 30.8, a 54% overshoot of τ. Adding weight decay (λ = 0.1) reduced the imbalance to σ_q = 0.10 and σ_k = 21.5, but the peak was still 24.6, 23% over. With α = 0.5 the matrices stay balanced and the overshoot stays at the 3.5% one-step lag. Under AdamW, whose per-coordinate step also ignores weight scale, I'd expect the same failure. For Muon specifically, the symmetric split is what keeps the cap bounded. It isn't just a stylistic default.

Finding 3: weight decay does the deactivating

The report presents self-deactivation as something QK-Clip achieves: active for the first 70k steps, "after training stabilizes, QK-clip is deactivated." The bookkeeping is consistent: 15.5T tokens at 67M per batch is 231k steps, so 70k is the caption's "approximately 30%" (30.3%).

The toy suggests a different cause. On the same task with τ = 50:

setting clipped steps (of 6,000) last clip final S_max
Muon + clip, λ = 0.1 437 step 527 39.8
Muon + clip, λ = 0 5,914 step 6,000 50.0 (pinned)
Muon, no clip, λ = 0.1 — — 39.9 (peak 728 @ step 492)

The clip switched off only when weight decay was on. Even with no clip at all, Muon plus decay rises to 728 and then relaxes to the same ~40 equilibrium, the point where decay balances what the task gains from sharper attention. QK-Clip trimmed the peak. Decay set where the logits ended up. Without decay, the clip has to keep working because nothing else pulls the logits down. (At τ = 100, λ = 0, clipping stopped at step 716 only because the loss underflowed with S_max parked at 99.9.)

The K2 run fits the same picture. Its decay time constant is 1/(η·λ) = 1/(2e-4 · 0.1) = 50k steps, and the clip ran for 70k steps, about 1.4 time constants. My toy deactivated at about 0.5 time constants (η·λ = 1e-3, last clip near step 520), so I can't claim a fixed multiple. What both runs show is the clip handing control to weight decay on decay's timescale. The practical rule: shorten the run, lower λ, or decay the learning rate early (all lower η·λ), and expect the clip to stay on longer, possibly for the whole run.

QK-Clip is a good idea, and its good property is that it only steps in when a head's logits get too large. The report, though, describes it with more precision than the mechanism delivers. τ is a set-point the clip tracks one step late, α is a stability parameter, and the clip's shutdown is driven by the optimizer's weight decay.