Skip to content

[DistMuon] Take packed chunk positions from the redistribution plan - #5697

Draft
weifengpy wants to merge 2 commits into
gh/weifengpy/82/basefrom
gh/weifengpy/82/head
Draft

weifengpy wants to merge 2 commits into
gh/weifengpy/82/basefrom
gh/weifengpy/82/head

Conversation

@weifengpy

@weifengpy weifengpy commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Why

When a rank computes several chunks of one parameter, their packed layout is defined twice. The region planner packs the chunks along dim 0 in the order it is given and uses those offsets for its routes; DistMuon separately recomputes each Newton-Schulz view's offset by summing the sizes of earlier logical_regions. Nothing checks that the two agree. A planner change that packs in a different order, for example by size, would still pass plan validation and the cross-rank check, while Newton-Schulz silently ran on the wrong rows.

Example. BlockShard(dim=0, block_sizes=(4, 2)) on a (6, 4) weight with both chunks on one rank. If the planner listed the chunks in one order but packed the 2-row chunk first, DistMuon's re-derived offsets would make the 4x4 view read logical rows [4, 5, 0, 1]. After this PR, DistMuon reads each chunk's position from the plan, so listing order no longer matters.

What changed

  • _ParticipantPartition gains tensor_regions: where each logical region sits in the participant's tensor. The region planner fills it from the same packed offsets its routes use.
  • DistMuon builds views from those regions. _matrix_batch_views_for_regions becomes _matrix_batch_views_for_region, which describes one chunk relative to its own start; the cost estimators already passed a single region.

Numerics

Unchanged: the planner packs in the same order as before, so the views have the same offsets.

Testing

  • pytest tests/unit_tests/gpu/distributed/flex_shard/test_dist_muon.py tests/unit_tests/cpu/distributed/flex_shard: 20 passed.
  • With the planner changed to list each rank's chunks in reverse while packing them in the original order, test_shared_bucket_matches_per_parameter_buckets (previous PR) passes on this PR and fails on the previous one (layers.0.blocks).

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

[ghstack-poisoned]
[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