Repository navigation
[Kimi K3] Zero-initialize the attention residual projections - #4881
Conversation
|
|
|
@claude review this PR |
|
Claude finished @tianyu-l's task in 57s —— View job Review: Zero-initialize the Kimi K3 attention residual projections
Overall: The code change is correct and small. LGTM on the code. There is one thing to fix in the PR itself: the test file listed in the description is not in the PR. Correctness ✅
Issues
NumericsThis changes the computation at init, so it will not match earlier runs bit for bit. Per CLAUDE.md, a short loss-convergence comparison against the old init on the debug model would be good to include, though for a spec-mandated init fix it is not blocking. |
Section 5 of the Attention Residuals technical report requires every pseudo-query vector to be initialised to zero, so the depth softmax starts uniform and each residual starts as an equal-weight average of its sources; the three residual projections were drawn from trunc_normal at std 0.02.
ae3a788 to
42dac61
Compare
Refresh the 10-step loss and gradient-norm golden after the Kimi K3 attention residual projections were changed to zero initialization in pytorch#4881.\n\nThe values were extracted from B200 run 37738225414, whose source tree exactly matches upstream/main at 08f7c39.
Refresh the 10-step loss and gradient-norm golden after the Kimi K3 attention residual projections were changed to zero initialization in pytorch#4881. The values were extracted from B200 run 37738225414, whose source tree exactly matches upstream/main at 08f7c39.
## Summary - Disable Attention Gym KDA autotuning when PyTorch deterministic algorithms are enabled; ordinary training still autotunes. - Refresh the Kimi K3 10-step B200 loss and gradient-norm golden after the attention-residual initialization change in #4881. - Keep the existing `kimi_k3_debugmodel_mm_muon` recipe and FSDP2/EP2 topology unchanged. ## Why The old golden predates #4881, which intentionally changed Kimi K3 attention-residual projections from truncated-normal to zero initialization. While re-exporting it, two otherwise identical deterministic B200 runs diverged after step 1. A back-to-back diagnostic on the same runner reproduced both traces: Attention Gym's KDA autotuner can select numerically different valid schedules based on benchmark/cache state. Deterministic mode now skips that benchmark-dependent choice and uses the default schedule, matching TorchTitan's existing handling for other autotuned attention kernels. ## Numerical source - Back-to-back B200 export: https://github.com/pytorch/torchtitan/actions/runs/37752597252 - Config: `kimi_k3_debugmodel_mm_muon` - Topology: FSDP2/EP2 on two B200 GPUs - Steps: 10 - Metrics: full-precision TensorBoard `loss` and `grad_norm` - Golden SHA-256: `a261836fb1c17635d71f2a04b81b882e9b60ba08f6229091393861dc33160ae5` Both sequential exports were byte-for-byte identical. ## Validation - Final B200 CI numerics path: https://github.com/pytorch/torchtitan/actions/runs/37757612886 - `kimi_k3_mm_muon` completed with `rc=0`. - `loss_compare.py --assert-equal` matched all 10 losses and all 10 gradient norms exactly. - The overall B200 workflow was red in unrelated lanes; the K3 numerics lane passed. - Formatting, flake8, pydoclint, codespell, and link checks passed. The repository-wide Pyrefly hook reports four unrelated errors already present on `main`.
Initialize Kimi K3's attention residual projections to zero, as Section 5 of the Attention Residuals technical report requires, so the depth softmax starts uniform and each residual starts as an equal-weight average of its sources.
torchtitan/models/kimi_k3/__init__.py:attention_res_proj,ffn_res_projandoutput_res_projtakenn.init.zeros_instead oftrunc_normal_at std 0.02.tests/unit_tests/cpu/test_kimi_k3_attention_residual_init.py: the projections are zero initialized; at zero the aggregation returns the mean of its sources; the projection still gets a gradient and the norm weight does not.Split out of #4780, as suggested there.
Test plan
nn.init.zeros_, and at zero the aggregation returns the mean of its sources (checked locally).