Skip to content

Enforce cross-rank parameter order in the Muon preflight - #66

Merged
thad0ctor merged 3 commits into
mainfrom
fix/final-review-followups
Jul 13, 2026
Merged

Enforce cross-rank parameter order in the Muon preflight#66
thad0ctor merged 3 commits into
mainfrom
fix/final-review-followups

Conversation

@thad0ctor

@thad0ctor thad0ctor commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-ups from the final pre-merge review sweep of #65 (the sweep found no critical or major issues; these are its three minor findings):

  • Enforce identical parameter-group order across mesh ranks in the exact/distributed Muon preflight. The order-insensitive presence check could pass while step() still assigns momentum owners and enters gradient collectives by insertion index, so rank-divergent registration order with consistent gradient presence would misalign the step. Each sorted parameter's local insertion position is now reduced to its mesh-wide max/min (one extra small all-reduce per mesh dimension on the already-guarded exact/distributed path only) and any divergence raises the same error on every rank before mutation.
  • scripts/release_gpu_gate.sh fixes: --help prints the full header again (it had outgrown a hardcoded sed range and silently dropped the GEFEN_GATE_EXTRA_SITE / CUDA_VISIBLE_DEVICES docs); a relative --wheel path now resolves against the invocation directory instead of breaking after the script's cd; a missing --wheel argument exits with a usage error instead of a raw set -u failure.
  • CHANGELOG bullet extended to disclose the order rejection.

Validation

  • The updated 2-rank gloo regression test (reversed_consistent must now raise the order error) fails on the previous code and passes with the fix.
  • CPU: grad-presence, distributed-checkpoint-safety, FSDP2-checkpoint, and step-preflight suites — 56 passed.
  • GPU (2× RTX 3090, NCCL, fresh JIT build root): grad-presence + full FSDP2 parity + checkpoint safety — 43 passed.
  • Gate script: bash -n clean; full --help verified; both --wheel error paths exercised from a foreign working directory.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Added distributed validation to detect inconsistent parameter-group ordering across ranks before collective operations.
    • Improved error messages to identify parameters involved in ordering or gradient-presence mismatches.
    • Prevented potential deadlocks and momentum-assignment inconsistencies in exact and distributed sharded modes.
  • Chores

    • Improved GPU release script help output and handling of wheel paths.

The grad-presence preflight tolerated rank-divergent parameter-group
registration order after its content-sort hardening, but exact and
distributed stepping enter gradient collectives and assign momentum
owners by insertion index, so divergent order with consistent gradient
presence could still misalign those collectives. Reduce each sorted
parameter's local insertion position to its mesh-wide max and min and
fail with the same error on every rank before any mutation. Also
complete the release-gate script's --help output (the header outgrew
the hardcoded sed range), resolve --wheel paths against the invocation
directory, and reject a missing --wheel argument with a usage error
instead of a raw set -u failure.
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 91a3141b-6076-47ef-a307-f363478d872b

📥 Commits

Reviewing files that changed from the base of the PR and between ef58f58 and eed3554.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • scripts/release_gpu_gate.sh
  • src/gefen/gefen_muon.py
  • tests/test_muon_grad_presence.py
📝 Walkthrough

Walkthrough

The change adds cross-rank parameter-group order validation before distributed Muon collectives, expands regression coverage, and hardens release GPU gate help and wheel-path handling.

Changes

Distributed Muon preflight

Layer / File(s) Summary
Rank-consistent preflight validation
src/gefen/gefen_muon.py, CHANGELOG.md
The distributed preflight now detects rank-divergent parameter-group insertion order alongside gradient-presence mismatches before collectives.
Regression coverage for order and gradient checks
tests/test_muon_grad_presence.py
Tests cover reversed-order rejection, aligned gradient mismatches, and aligned-consistent success with specific diagnostics.

GPU release gate

Layer / File(s) Summary
Release script argument and help handling
scripts/release_gpu_gate.sh
Usage output scans leading comments dynamically, while --wheel requires a path and resolves it to an absolute normalized location.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Rank0
  participant Rank1
  participant Preflight as GefenMuon._assert_sharded_grad_presence_consistent
  participant ProcessGroup
  Rank0->>Preflight: Build local parameter order probe
  Rank1->>Preflight: Build local parameter order probe
  Preflight->>ProcessGroup: all_reduce order probe
  ProcessGroup-->>Preflight: Reduced cross-rank values
  Preflight-->>Rank0: Reject divergent order
  Preflight-->>Rank1: Reject divergent order
Loading

Possibly related PRs

  • thad0ctor/Gefen-X#52: Addresses related distributed momentum ownership and parameter-order alignment checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: enforcing consistent parameter order across ranks during the Muon preflight.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/final-review-followups

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/gefen/gefen_muon.py (1)

1376-1409: 🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift

Reject bare or non-uniquely named distributed parameters before this order probe.

This aligns ranks by name, shape, and dtype, but bare parameters receive positional auto-names. If same-shaped a, b are registered as [a, b] on one rank and [b, a] on another, both ranks still produce positions 0, 1 for the same auto-names, so this check passes while later full_tensor()/owner collectives follow divergent orders. Require globally unique explicit names for exact/distributed DTensor groups (or provide another stable cross-rank ID), and add a reversed bare-parameter regression case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/gefen/gefen_muon.py` around lines 1376 - 1409, Before constructing
order_probe in the distributed parameter-group path, reject bare parameters and
any non-unique auto-generated names for exact/distributed DTensor groups.
Require globally unique explicit parameter names, or another stable cross-rank
identifier, so identical-shaped parameters cannot be aligned only by positional
auto-names; preserve the existing name/shape/dtype alignment for valid groups
and add coverage for reversed bare-parameter registration order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/release_gpu_gate.sh`:
- Around line 53-57: Update the --wheel argument handling in release_gpu_gate.sh
to reject a missing value when the next token begins with “-”, including
option-like values such as --help, before calling realpath. Preserve accepting
valid wheel paths and the existing usage-error exit behavior for missing or
invalid --wheel arguments.

---

Outside diff comments:
In `@src/gefen/gefen_muon.py`:
- Around line 1376-1409: Before constructing order_probe in the distributed
parameter-group path, reject bare parameters and any non-unique auto-generated
names for exact/distributed DTensor groups. Require globally unique explicit
parameter names, or another stable cross-rank identifier, so identical-shaped
parameters cannot be aligned only by positional auto-names; preserve the
existing name/shape/dtype alignment for valid groups and add coverage for
reversed bare-parameter registration order.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7704b347-bdaf-4604-b640-9727d6228bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 7c37a01 and ef58f58.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • scripts/release_gpu_gate.sh
  • src/gefen/gefen_muon.py
  • tests/test_muon_grad_presence.py

Comment thread scripts/release_gpu_gate.sh

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef58f58b37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gefen/gefen_muon.py Outdated
Comment thread src/gefen/gefen_muon.py Outdated
Use optimizer-wide insertion positions in the order probe so swaps
between parameters on different DeviceMeshes are caught (step() enters
per-mesh collectives in global registration order). Fail closed when
parameters in one mesh share a name, shape, and dtype: construction
accepts duplicate explicit names, and such parameters cannot be
identified across ranks by any rank-local property. Same-shaped bare
parameters have positionally auto-generated names with the same
ambiguity; warn once and recommend named construction instead of
breaking the common identically-constructed case. The gate script also
rejects an option-like value after --wheel instead of treating it as a
path.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83c29eec4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gefen/gefen_muon.py Outdated
Comment thread src/gefen/gefen_muon.py Outdated
Ride the duplicate-label count on the MAX-reduced order probe so a rank
with clean labels learns about duplicates on a peer and raises the same
error instead of blocking in a collective the peer abandoned, and defer
duplicate/order/presence raises until every local mesh has completed
its probe collectives so overlapping but non-identical meshes cannot be
stranded mid-preflight by an early exit.
@thad0ctor
thad0ctor merged commit f6bf3ec into main Jul 13, 2026
15 checks passed
@thad0ctor
thad0ctor deleted the fix/final-review-followups branch July 13, 2026 00:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eed3554403

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gefen/gefen_muon.py
Comment on lines +1533 to +1534
if order_mismatches:
raise RuntimeError(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate order failures to overlapping mesh peers

When DeviceMeshes overlap but are not identical, an order mismatch on only one mesh still is not propagated to ranks that only share a later clean mesh. For example, with meshes over ranks [0,1] and [1,2], ranks 0/1 raise here for an order mismatch on [0,1] after all probes complete, but rank 2 never records order_mismatches and proceeds into _maybe_refresh_gefen_codebook()/step() collectives for [1,2] after rank 1 has exited. This preserves the unmatched-collective failure the preflight is meant to avoid; the error flag needs to reach overlapping peers before any post-preflight collectives run.

Useful? React with 👍 / 👎.

Comment thread src/gefen/gefen_muon.py
collisions = {}
for name, p, _ in items:
if _AUTO_PARAM_NAME.match(str(name)):
key = (tuple(p.shape), str(p.dtype))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat all positional auto-names as unverifiable

When a DTensor optimizer is built from bare parameters and two ranks register [a, b] vs [b, a], the generated param_0/param_1 labels follow local position rather than tensor identity. This collision map only warns when multiple auto-named params share the same (shape, dtype), so differently shaped or differently typed bare params produce no warning/error; the order probe then compares identical local positions for param_0/param_1 and passes, leaving later full_tensor()/distributed collectives to run for different tensors on each rank. The auto-name path needs to fail closed or otherwise avoid trusting positional labels even when shapes differ.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant