Skip to content

[DistMuon] Cap the elements each rank computes per bucket - #5703

Draft
weifengpy wants to merge 1 commit into
gh/weifengpy/85/basefrom
gh/weifengpy/85/head
Draft

weifengpy wants to merge 1 commit into
gh/weifengpy/85/basefrom
gh/weifengpy/85/head

Conversation

@weifengpy

@weifengpy weifengpy commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Why

#5468 places compute chunks by Newton-Schulz cost alone. If a bucket mixes unevenly sharded compute-ready work with redistributed parameters, the ranks with less fixed work can absorb every chunk. Their compute exchange buffer and all-to-all receive volume then grow to the whole bucket, while the other ranks receive nothing. In-tree Kimi recipes keep routed experts in their own buckets, so they don't hit this.

Example. 48 dp_shard ranks, EP=1, and one bucket holding Kimi K3 layers 3-4 including the routed experts. Storing 896 experts on 48 ranks puts 19 on every rank except rank 47, which gets 3 (fake process group, planning only):

largest compute exchange buffer ranks computing redistributed chunks largest Newton-Schulz cost
before #5468 179.8M elements 12 71.0e12
main 572.1M elements (1.14 GB in bf16, per pipeline slot), all on rank 47 1 55.1e12
this PR 99.5M elements 16 63.3e12

What changed

  • _assign_balanced_compute_regions caps the elements each rank computes in a bucket at the bucket's even share of redistributed elements plus its largest chunk. A rank that a chunk would take over the cap is skipped for that chunk, and the existing cost order picks among the other ranks.
  • Why this cap: every chunk lands whole on one rank, so any placement leaves some rank with at least the even share or the largest chunk, whichever is larger, and the cap is within twice that. It is also the smallest cap that placement can always meet: until every chunk is placed, some rank holds less than the even share and can take any chunk.
  • test_shared_bucket_matches_per_parameter_buckets used fixed work to pack every parameter onto rank 3, and the cap now spreads those chunks. blocks becomes (6, 6), so its 4-row and 2-row chunks still pack onto one rank, and the packing check accepts any rank. The final check gathers mismatches from every rank (see Testing).

Alternatives considered

  • Weigh all-to-all bytes against Newton-Schulz FLOPs: needs a hardware-specific exchange rate.
  • A configurable cap: a user has no way to choose a value.

Numerics

Placement only: each chunk runs the same Newton-Schulz on whichever rank computes it, so results are unchanged.

Testing

  • New test_skewed_fixed_work_caps_compute_elements_per_rank (CPU, fake process group): ranks 0-2 hold fixed work and rank 3 none, and four (16, 64) Owned parameters must compute 1024, 1024, 0 and 2048 elements per rank. Without the cap, all 4096 go to rank 3.
  • Kimi K3 non-routed layers, the same 10 configs as the previous PR: plans are identical with and without the cap.
  • test_shared_bucket_matches_per_parameter_buckets still catches both earlier bugs. With the return-region fix from [DistMuon] Fix compute buffer overwrite with replicated storage #5695 removed, layers.0.c and layers.0.blocks differ on ranks 0-2. With DistMuon placing views as if the chunks were packed in reverse order, layers.0.blocks differs on ranks 0-2. Rank 3 stores no rows of blocks and computes neither c nor blocks, so it passed and then waited in teardown. The final check now gathers mismatches from every rank, so the test fails everywhere instead of hanging.
  • pytest tests/unit_tests/gpu/distributed/flex_shard/test_dist_muon.py tests/unit_tests/cpu/distributed/flex_shard: 22 passed.

Known issues / follow-ups

  • In skewed buckets the cap trades Newton-Schulz balance for memory: in the example, the largest cost is 15% above main's. Step time is not measured.
  • Chunks can still leave the ranks that store them (the review of [DistMuon] Balance Owned and sharded compute placement #5468 found +10.7% all-to-all volume for Moonlight-16B at 32-way FSDP). This PR doesn't address that.

This PR was drafted with an AI assistant (Claude Code).

[ghstack-poisoned]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant