Skip to content

feat(weight-sync): add ModelExpress trainer publishing - #3259

Open
KavinKrishnan wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
KavinKrishnan:kavink/split-3068-trainer
Open

KavinKrishnan wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
KavinKrishnan:kavink/split-3068-trainer

Conversation

@KavinKrishnan

@KavinKrishnan KavinKrishnan commented Jul 17, 2026 •

Copy link
Copy Markdown

Overview

Adds trainer-side publication for a ModelExpress (MX) weight-refit backend. NeMo RL's WeightSynchronizer remains the owner of the refit lifecycle; this PR adds the policy operation that a future ModelExpressWeightSynchronizer will call.

The existing DTensor worker and the Megatron worker publish rank-local tensor ownership and topology metadata. Generation-side discovery, transfer, resharding, and installation remain separate reviews.

Changes

  • Adds publish_weights_for_model_express() to the policy interface and trainer workers.
  • Publishes native Tensor Parallelism (TP), Pipeline Parallelism (PP), and Expert Parallelism (EP) shards without gathering the full model on rank zero.
  • Describes global tensor geometry, rank coordinates, expert ownership, and Megatron-to-Hugging Face name mappings.
  • Requires the public ModelExpress publisher lifecycle; no private MX state is accessed.
  • Fails before publication for unsupported DTensor placements or unknown Megatron placement at TP greater than one.
  • Adds focused lifecycle, geometry, role-classification, and failure tests.
  • Adds the trainer-publication design and current implementation status to the documentation.

Architecture boundary

WeightSynchronizer                              [follow-up]
  -> policy.publish_weights_for_model_express() [this PR]
  -> generation discovery and transfer          [follow-up]
  -> inference reshard and install               [follow-up]
  -> global completion                           [follow-up]

This PR does not create a second orchestration path. Existing IPC, HTTP, and NCCL synchronizers are unchanged.

Scope

This PR does not add:

  • a user-facing ModelExpress refit configuration;
  • generation-worker discovery, transfer, or installation;
  • DTensorPolicyWorkerV2 / AutoModel publication;
  • Dynamo integration;
  • Kubernetes resources, recipes, or benchmark harnesses.

The future synchronizer will own user configuration and construct the internal publisher settings explicitly.

Current status

Partially aligned: rank-local publication is implemented and unit-tested for the existing DTensor worker and the Megatron worker. End-to-end refit requires the generation-worker adapter and the corresponding ModelExpress publisher, planning, and installer APIs.

ModelExpress dependencies

Relationship to #3068

This is the trainer-publication portion of #3068, separated by ownership and review scope. The umbrella remains a reference for the complete integration.

Test plan

  • 14 focused publication lifecycle, DTensor geometry, and Megatron classification tests
  • Ruff lint and formatting
  • Focused pyrefly check for new modules
  • Python compilation and Git whitespace checks
  • DCO sign-off
  • Full repository and GPU end-to-end tests through maintainer CI

@KavinKrishnan
KavinKrishnan requested review from a team as code owners July 17, 2026 00:12
@copy-pr-bot

copy-pr-bot Bot commented Jul 17, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jul 19, 2026
@KavinKrishnan
KavinKrishnan force-pushed the kavink/split-3068-trainer branch 2 times, most recently from 8944e2c to 5fc0c0b Compare July 19, 2026 07:23
@KavinKrishnan
KavinKrishnan requested review from a team as code owners July 19, 2026 07:23
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Jul 19, 2026
@KavinKrishnan KavinKrishnan changed the title feat(megatron): add ModelExpress rank-local publishing feat(weight-sync): add ModelExpress trainer publishing Jul 19, 2026
@KavinKrishnan

Copy link
Copy Markdown
Author

/ok to test 5fc0c0b

@KavinKrishnan

Copy link
Copy Markdown
Author

/ok to test 858bf2f

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Jul 19, 2026
@KavinKrishnan

Copy link
Copy Markdown
Author

Added a correctness fix to this branch: global layer indices under pipeline parallelism

Pushed 21f804e5. Folding it in here rather than opening a follow-up, because this PR is what introduces mx_megatron_helpers.py and merging it as-is would upstream a defect that is invisible to every correctness gate.

What was wrong. model.named_parameters() names a layer by its index in the local TransformerBlock.layers ModuleList. Under pipeline parallelism that is not the global index, so at pp_size=2 on a 48-layer model both stages publish decoder.layers.0..23. The reshard shard table is keyed by name with a first-writer-wins tiebreak, so one stage's 24 layers displace the other's. Global layers 24-47 are never refit, and where a stage-1 offer wins, destination layer N is filled from global layer N+24 — at a valid address, with a self-consistent digest.

Nothing catches this. Every gate compares arrived bytes against the publisher's digest for the same name, and a name collision makes both sides agree on the wrong tensor. Measured on Qwen3-30B-A3B at trainer TP1/PP2/EP8/DP8: coverage 51%, 15.58 GB moved against the engine's own 30.6 GB per-rank footprint. After the fix, coverage is 100.0% and params_installed is 435/435 on all 16 ranks.

Why layer_number and not arithmetic. map_local_layers_to_global reads the global index off TransformerLayer.layer_number, which Megatron already maintains as 1-based and global — its own checkpoint code subtracts an offset from it to recover the ModuleList index. The tempting pp_rank * layers_per_stage is wrong under virtual pipeline parallelism, where a rank owns several non-contiguous chunks, and under uneven stages (num_layers_in_first_pipeline_stage). Reading the attribute is exact for both.

It raises rather than falling back to the local name when pipeline parallelism is on and no layer exposes layer_number. That is deliberate and I would push back on softening it to a warning: the silent fallback is exactly the failure being fixed.

Reviewer notes.

file lines what to look at
nemo_rl/distributed/mx_megatron_helpers.py +89 The two new functions, and the one-line hook in collect_megatron_publish_set.
tests/unit/distributed/test_mx_megatron_pp_layer_names.py +178 8 tests. The two worth reading are the virtual-pipeline/uneven-stage case and the raise-don't-fall-back case.
nemo_rl/models/policy/workers/megatron_policy_worker.py +1 Passes pp_size, already in scope at the call site.

collect_megatron_publish_set gains a keyword-only pp_size: int = 1. The default is deliberate: at pp_size=1 local index equals global index, so existing callers keep their current behavior and the guard cannot fire on them.

One thing worth deciding in review rather than pre-deciding: Bridge has _megatron_local_name_to_global, which is arguably the more correct dependency to lean on upstream. The layer_number approach shipped here needs nothing outside this module, which is why it went in first.

@KavinKrishnan
KavinKrishnan force-pushed the kavink/split-3068-trainer branch from 21f804e to 541c6e1 Compare July 27, 2026 18:40
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Jul 27, 2026
Lets a Megatron or DTensor policy worker publish its rank-local shards
through ModelExpress instead of gathering them first, so generation
workers can pull the geometry they need directly.

Under pipeline parallelism the published layer indices are global rather
than stage-local, so a puller sees one consistent numbering across stages.

Signed-off-by: Kavin Krishnan <[email protected]>
@KavinKrishnan
KavinKrishnan force-pushed the kavink/split-3068-trainer branch from 541c6e1 to dad5f7b Compare August 12, 2026 16:09
@KavinKrishnan

Copy link
Copy Markdown
Author

Rebased onto main (was 69 commits behind) and squashed the four commits into one, since the later three only reworked the first and replaying them produced conflicts against the same lines four times over.

Two files needed a real resolution rather than a clean replay. main grew an NCCL-reshard path (prepare_nccl_reshard_refit_info, nccl_reshard_refit, and the pipeline-stage helpers on the Megatron worker) in the same places this change adds the ModelExpress path. The two are independent, so both are kept side by side and nothing was dropped. The net diff against main is unchanged line for line from before the rebase.

No functional change, so this is still the same review.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Aug 12, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026

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

community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants