Repository navigation
Conversation
Adds an all-to-all to ICollectiveComm (host-staged and grouped NCCL send/recv over one shared layout helper). The Kimi decoder shards attention heads, the dense and shared FFN, the vocabulary and the routed experts across ranks, with one AllReduce per sublayer and expert-parallel dispatch for the routed bank. One rank runs the same path with no collectives. Rank counts that do not divide the decoder are refused by name. Also fixes two engine bugs: the attention residual mix reads the running partial only inside a block, matching NeMo, and A_log is read one value per head.
2 of 3 tasks
This branch has not been deployed
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.
Summary
Multi-rank sharding for the Kimi K3.1 decoder, verified on CPU with virtual ranks. Nothing here runs on CUDA yet, and the engine does not route Kimi through this path.
ICollectiveComm.AllToAll(variable-size, counts matrix).HostStagedCommimplements it by copy.NcclCommimplements it as groupedncclSend/ncclRecvper ordered rank pair, skipping zero counts. Both use one layout helper,AllToAllLayout.MoeFeedForwardcan hold a contiguous expert range (ShardExperts). The router and latent projections stay whole. New internal entry points:RouteRows,ApplyLocalExperts,LatentEnter,LatentExit. Default behaviour is unchanged: the whole-bankForwardpath refuses a shard.ExpertParallelMoe(new, generic). Each rank sources a contiguous token slice, routes it, sends latent rows to the owning rank, runs experts there, returns outputs, and combines in latent space. The plan comes from the existingExpertParallelDispatch.Plan. The routed output is zero outside the source slice, so the caller adds other partials and runs one AllReduce.KimiK31Modeltakes aTpPlacement, or one backend for the one-rank case, which runs the same code path with no collectives. Heads (KDA and MLA), the dense and shared FFN intermediates, and the vocabulary split across ranks. The DSA indexer, latent projections, router and norms are replicated. Each sublayer ends in one AllReduce; logits use AllGather.KimiK31Stateis per rank.KimiK31Sharding.Requirenames the dimension that does not divide the rank count: heads, vocab, experts, dense intermediate, shared intermediate._forward_attn_residual). The MLP and output mixes always include it. The zero row this removes was a common scale factor before RMSNorm, so logits move only by RMSNorm eps.A_logis read one value per head and folded into each channel of its head. The loader accepts a vector with trailing padding and reads the leadingHeadsvalues.Tests run (CPU lane)
HartsyInference.LLM.Tests, CPU filter: 192 passed, 0 failed. Includes the Kimi folder, the sharded equivalence tests,ExpertParallelMoeTests,ExpertParallelDispatchTests, and the Ernie and MoE tests.HartsyInference.Core.Tests, CPU filter: 134 passed, 0 failed. IncludesHostStagedAllToAllTests(2).HartsyInference.Engine.Tests, filterErnie5|MiniMax|Moe: 33 passed, 0 failed.KimiK31ShardedForwardTests.ShardedForward_MatchesSingleRank) at 2 and 4 virtual ranks against one rank, same weights, tolerance 1e-4 over six tokens.KimiK31AttnResSourceTests) and per-head A_log fold (KimiK31ALogTests).Not run
NcclAllToAllTests(tests/HartsyInference.Core.Tests/Distributed/NcclAllToAllTests.cs), categoryGpuIntegration. 2-GPU filter:FullyQualifiedName~NcclAllToAllTests.TwoGpus. 8-GPU filter:FullyQualifiedName~NcclAllToAllTests.EightGpus. Both compile; neither was run (no GPU runs on the shared card). The grouped send/recv self-pair (i == j) is assumed valid in NCCL and is unverified.[Heads]or longer with the head values leading. Confirm against a real shard before relying on it.Memory per GPU, computed from shapes (bf16 layout, 8 ranks, excluding KV cache and activations)
Known limits
TextServiceplacement for Kimi) is out of scope; the decoder is reachable only throughKimiK31Model(TpPlacement, ...).ExpertParallelMoeTests.