Repository navigation
Conversation
Allow native 3D parameters to redistribute row shards into complete matrix batches using the existing region planner. Cover uneven rows, empty compute participants, replicated mesh axes, and deterministic training comparisons with Owned compute.
Contributor
Author
weifengpy
added a commit
that referenced
this pull request
Sep 21, 2026
A parameter can have a DistMuon compute layout while an optimizer-selection regex routes it to AdamW. Kimi's old w[123] pattern misses fused w13 weights, so its catch-all silently selects AdamW despite the unused Muon metadata. Validate local trainable parameters against the actual optimizer assignments after grouping, before constructing optimizers for that model part. Conflicting assignments now raise an actionable ValueError naming the parameter and assigned optimizer. Mapped parameters omitted from all groups also raise; checkpoint-wrapped names are canonicalized, and frozen parameters and entries for other pipeline stages are ignored. Make this validation safe to land independently: derive Kimi's FFN selection and compute metadata from a shared w2-only mapping. This removes the stale w13 layout/bucket entries and preserves the existing AdamW assignment. Optimizer behavior and checkpoint state format remain unchanged. The explicit w13 switch to Muon with Shard(0) compute is in the dependent #4811. Validation: - 37 CPU tests pass, including nine assignment-validation cases, all four Kimi recipes, EP overrides, and existing optimizer parameter-group coverage. Kimi tests verify w13 remains on AdamW and has no Muon layout/bucket entry. - Before/after 10-step C4 checks compare main with this validation base using the actual Kimi recipe assignments, without an optimizer override: eight H100s, FSDP8/EP8, sequence length 256, seed 42, and strict deterministic algorithms. All 10 full-precision training losses, 10 gradient norms, seven held-out losses, and per-rank assignment/update summaries are bitwise identical. - Changed-file type checks pass. Full pre-commit passes all other hooks and reports the same 30 existing Pyrefly diagnostics and source locations; unrelated automatic suppression removals are excluded. ghstack-source-id: 451de93 ghstack-comment-id: 5754025658 Pull-Request: #4813
weifengpy
added a commit
that referenced
this pull request
Sep 21, 2026
Kimi's dense and shared-expert fused w13 weights currently use AdamW. Select them for DistMuon and use Shard(0) compute to distribute the two complete [F, D] matrices in each native [2, F, D] parameter across ranks. Keep w2 on Owned compute. Enable the required Shard(1) storage -> Shard(0) compute transition on one mesh axis, with other non-unit storage axes replicated. The existing redistribution planner gathers complete matrices and returns update rows to the original storage ranks, including uneven row shards and empty compute participants. Parameters retain their native matrix-batch view; transport and Muon kernels are unchanged. A [2, F, D] batch uses at most two compute ranks; no performance improvement is claimed. This intentionally switches w13 from AdamW to Muon across the Kimi debug, Moonlight, Kimi-VL, and Kimi-K2.5 recipes. Model checkpoint names and shapes are unchanged, but old AdamW state for w13 does not supply Muon momentum state. Load old model weights with fresh optimizer state when adopting this change. Depends on the independent validation base #4813. This PR combines the redistribution support and the Kimi optimizer/layout change previously split across #4811 and #4812. Validation: - 41 CPU tests and five subtests pass, covering exact redistribution routes in both directions, uneven row shards, empty compute ranks, replicated mesh axes, unsupported-layout rejection, all four Kimi recipes, EP overrides, and optimizer assignment validation. - The combined production tree is identical to the previously tested stack at 3360775; only a CPU test function was renamed during consolidation. The six-test GPU DistMuon suite passed, covering Owned, BlockShard, checkpoint state, expert routing, and the new matrix-sharded compute path. - On H100, [2, 7, 5] matches Owned bitwise over 10 synthetic training steps with seed 42 and strict deterministic algorithms on two and four ranks, including loss, gradient norm, gradients, parameters, and momentum. An extra [3, 5, 7] case uses a 1e-6 absolute tolerance: local Newton-Schulz baddbmm batching can produce a one-FP32-ULP rounding difference. Every shape is not guaranteed bitwise equivalent to Owned. - Two 200-step C4 runs on eight H100s use the six-layer Kimi debug decoder, FSDP8/EP8, sequence length 256, seed 42, and strict deterministic algorithms. Both use the same 4,096 training documents and 512 held-out documents and train on 409,600 tokens. Runtime checks confirm optimizer assignments, Shard(1) storage, Shard(0) compute with six empty participants, and updated w13 weights on every rank. | w13 optimizer | Initial held-out loss | Held-out loss at step 200 | Mean training loss, last 20 steps | | --- | --- | --- | --- | | AdamW baseline | 8.0564976 | 2.7773604 | 2.7658222 | | DistMuon, Shard(0) | 8.0564976 | 2.7758863 | 2.7614102 | The C4 runs are a short learning check on the debug decoder, not full-model convergence or a performance comparison. Changed-file type checks pass. Full pre-commit reports the same 30 existing Pyrefly diagnostics as the validation base; all other hooks pass and unrelated automatic suppression removals are excluded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A parameter can have a DistMuon compute layout while an optimizer-selection regex routes it to AdamW. Kimi's old w[123] pattern misses fused w13 weights, so its catch-all silently selects AdamW despite the unused Muon metadata.
Validate local trainable parameters against the actual optimizer assignments after grouping, before constructing optimizers for that model part. Conflicting assignments now raise an actionable ValueError naming the parameter and assigned optimizer. Mapped parameters omitted from all groups also raise; checkpoint-wrapped names are canonicalized, and frozen parameters and entries for other pipeline stages are ignored.
Make this validation safe to land independently: derive Kimi's FFN selection and compute metadata from a shared w2-only mapping. This removes the stale w13 layout/bucket entries and preserves the existing AdamW assignment. Optimizer behavior and checkpoint state format remain unchanged. The explicit w13 switch to Muon with Shard(0) compute is in the dependent #4811.
Validation: