Skip to content

fix: gate MTP layers from the nccl-reshard bulk refit path - #3619

Merged
terrykong merged 5 commits into
mainfrom
youngeunk/nccl-reshard-mtp-gating
Aug 14, 2026
Merged

terrykong merged 5 commits into
mainfrom
youngeunk/nccl-reshard-mtp-gating

Conversation

@youngeunkwon0405

Copy link
Copy Markdown
Contributor

I am separating PR #3532 into two. Wire-safe part and the MTP gating part.

What does this PR do ?

Gate the MTP layers from the nccl-reshard path. It will force the use of the conventional refit path for the MTP layer.
The PR also contains the correct MTP gating for the DeepSeek MTP and the refactor in the misc path call to correctly update the MTP drafter in the vLLM engine.

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

Co-trained MTP drafter weights must not take the bulk xferdtensor
path: vLLM keeps the drafter separate from the main model and updates
it through load_weights, and bulk-resharding MTP layers either trips
the layer_prefix assert / per-stage KeyError on the train side or
targets main-model params vLLM does not have.

MTP weights are recognized two ways:
- bare mtp.-prefix HF names (NemotronH, Qwen3.5) in
  is_nccl_reshard_param
- DeepSeek-style MTP exported as trailing model.layers.N indices via
  provenance: the Megatron-side name on the Bridge conversion tasks is
  uniformly mtp.*, so the worker collects those HF layers
  (_collect_mtp_hf_layer_names) and routes them to the misc path

Run nccl_reshard_refit finalization through _weight_update_lifecycle
so the drafter gets _maybe_process_mtp_drafter_after_loading() like
the ipc/collective transports — freshly refit MTP MoE weights need
their runtime (grouped-GEMM/quant) layout conversion.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
@youngeunkwon0405
youngeunkwon0405 requested review from a team as code owners August 13, 2026 00:18
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 13, 2026
@youngeunkwon0405 youngeunkwon0405 self-assigned this Aug 13, 2026
@youngeunkwon0405 youngeunkwon0405 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Aug 13, 2026
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 31ff9af

@youngeunkwon0405 youngeunkwon0405 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Team review: 4 agents (RL expert, test reviewer, bug finder, devil's advocate) + lead; every finding independently re-verified against the pinned Megatron-Bridge SHA (0c565c9a) before posting.

The fix is correct and necessary. All three pre-PR failure modes were verified real: the layer_prefix assert fires for bare-mtp. families (NemotronH/Qwen3.5), DeepSeek's trailing-index MTP hits the per-stage KeyError, and the lifecycle switch newly runs the MTP drafter post-load processing that the old inline finalization never did. Verified clean: finalization ordering is exactly preserved vs main (independently diffed by two agents); the provenance gate operates on wildcard-resolved mappings with literal MTP layer indices, so no false or missed keys are possible for the pinned bridges; GLM-4.5's grouped MTP experts are correctly excluded by the layer-key design (a per-param gate would have missed them); and the two added tests use exact bridge-exported names.

3 inline comments, none blocking: a free CPU test-coverage gap for the new prefix gate (verified rows provided), a docstring/design-doc accuracy fix for the "uniformly mtp.*" claim (two counterexample families at the pin), and an optional setup-time guard for the real-quant combination the lifecycle change newly touches. Linter (ruff check + format): clean.

Generated by Claude Code

@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 1127c81

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 926e5a5

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review at 926e5a5. The fix is correct and needed — I could not construct a case where it breaks, and both pre-PR failure modes are real, not hypothetical:

  • Bare-mtp. families (NemotronH/Qwen3.5): mtp.layers.0.mixer.up_proj.weight ends in up_proj.weight, so it took the bulk path, and _extract_layer_prefix then returned mtp against a backbone incumbent → the layer_prefix mismatch assert.
  • DeepSeek-style: MTP exports at model.layers.61, so the assert passes but _build_layer_to_pp_stage never emits that index → the KeyError whose message already names MTP as the expected cause.

Verified clean, for the record:

  • Nothing is dropped. The gate sits on the if of an if/else; the else writes misc_meta, and because _task_is_misc filters against set(misc_meta.keys()), the MTP conversion tasks land in _misc_conversion_tasks too. Both halves of the misc path carry MTP, so there's no silent stale-drafter case.
  • Keying the exclusion by HF layer rather than by param was the right call. It keeps _task_is_misc's "first HF name is representative" assumption valid for compound mappings — a whole MTP layer moves to misc together, so a GatedMLPMapping can never end up half-bulk/half-misc and desync the packed-broadcast order.
  • The provenance gate can't go stale per-family. The key is derived with _extract_layer_name from the same task's hf_param that produces the name being tested, so it matches by construction. Checked at the pinned Bridge: 17 families define MTP mappings, all name the Megatron module mtp.layers.N, and a grep for nextn|eagle|draft|speculat in any megatron_param= returns nothing.
  • GLM-4.5's grouped-MoE MTP is handled — its HF name ends in experts.gate_up_proj, so is_nccl_reshard_param returns True and only the provenance set excludes it. A per-param gate would have missed this.
  • No over-broad exclusion is possible. MTP names without a layers.N produce coarse keys (mtp, model.embed_tokens). Those can never collide with an FFN param: every FFN name sits under layers.N and keys as <prefix>.layers.N, while the fallback branches structurally cannot emit that shape.
  • The lifecycle refactor preserves ordering exactly and adds the one thing that was missing — the deleted inline block was a hand-rolled copy of the base finalize() that omitted _maybe_process_mtp_drafter_after_loading(). Adopting the shared hook matches how ipc and collective already call it.
  • The real_quant guard closes the loop. The bulk xferdtensor phase sits outside the with, while ModelOpt's override runs initialize_layerwise_reload on entry — the new violation forbids exactly that pairing. Guard and narrow with are a matched pair.

Reviewed by a 7-agent team; every finding was re-verified against the pinned Megatron-Bridge SHA 0c565c9a before posting. Two candidate findings were dropped under challenge: a missing real_quant row in the config-validation test table (that table spot-checks 2 of 17 violations, so there's no convention being broken), and a GLM-4.5 test fixture (the existing DeepSeek fixture already exercises the provenance-only path). Linters pass; pyrefly couldn't run in my environment, so it's unchecked rather than failing.

Three comments below, all low severity, none blocking — and all the same shape: the routing rule changed, and one of the four places describing it got updated. No code changes requested.

Generated by Claude Code

Comment thread docs/design-docs/nccl-reshard-refit.md Resolved
Co-authored-by: Terry Kong <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
@youngeunkwon0405
youngeunkwon0405 force-pushed the youngeunk/nccl-reshard-mtp-gating branch from b28b4a4 to c0589ee Compare August 14, 2026 07:11
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test c0589ee

@terrykong
terrykong enabled auto-merge (squash) August 14, 2026 07:25
@terrykong
terrykong merged commit 282fe40 into main Aug 14, 2026
142 of 145 checks passed
@terrykong
terrykong deleted the youngeunk/nccl-reshard-mtp-gating branch August 14, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants