Skip to content

MoE DDP negative control: accept the idle rank's missing gradient, whichever rank fails first - #17151

Merged
danielhanchen merged 1 commit into
mainfrom
fix-moe-ddp-negative-control-race
Nov 8, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-moe-ddp-negative-control-race

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, rest) fails on some PRs at a test #15880 added yesterday. Today that includes #17129 and #17132, neither of which touches context parallelism:

tests/test_remote_moe_shims.py:920: in test_without_context_parallelism_idle_experts_stall_ddp
E   AssertionError: Regex pattern did not match.
E     Expected regex: 'not close|finished reduction|did not receive grad'
E     Actual message: '-- Process 1 terminated with the following error:
      ...
      File "tests/test_remote_moe_shims.py", line 895, in _moe_ddp_worker
        assert got.grad is not None, name  # a zero gradient, never None, for DDP
    AssertionError: experts.0.gate_proj.weight

The test is a negative control. With context parallelism off, each rank leaves the experts its peer routes to with a None gradient, so DDP without find_unused_parameters never reduces that bucket. The test expects the run to fail, and it does, every time. Which error the test sees depends on which of the two spawned ranks fails first:

  • the rank that used an expert holds an unreduced local gradient, and assert_close fails with not close, which the regex accepts;
  • the rank that left the same expert idle reaches assert got.grad is not None first, and that assertion's message is just the parameter name, which the regex does not accept.

torch.multiprocessing.spawn reports whichever process dies first. So the test passes or fails on scheduling, while the product behaviour it checks is identical either way. Context parallelism itself is correct. The positive test next to it, with context parallelism on, passes.

Change

tests/test_remote_moe_shims.py, test only:

  • The worker's gradient assertion says what it found: f"{name}: no gradient".
  • The negative control's regex also accepts no gradient, with a comment on why both ranks' errors are the same finding.

The control still fails if context-parallel-off training ever stops stalling DDP, because then nothing raises at all.

Testing

result
main, with rank 0 delayed 3 s before its checks so rank 1 fails first (the CI case) fails: Regex pattern did not match, Process 1 terminated
this branch, same delay passes
this branch, tests/test_remote_moe_shims.py 49 passed

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T14:54:59.440741Z d77cea7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d77cea768b

ℹ️ 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".

@danielhanchen
danielhanchen merged commit a402f1a into main Nov 8, 2026
@danielhanchen
danielhanchen deleted the fix-moe-ddp-negative-control-race branch November 8, 2026 15:00
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