Skip to content

feat: colocated Megatron reshard - #3490

Merged
terrykong merged 25 commits into
NVIDIA-NeMo:mainfrom
tdene:tde/refit_colocated
Aug 18, 2026
Merged

feat: colocated Megatron reshard#3490
terrykong merged 25 commits into
NVIDIA-NeMo:mainfrom
tdene:tde/refit_colocated

Conversation

@tdene

@tdene tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

This PR adds the ability to refit during colocated RL.

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

  • ...

@tdene
tdene requested review from a team as code owners August 4, 2026 10:37
@copy-pr-bot

copy-pr-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@tdene tdene added the CI:L1 Run doctests, unit tests, and functional tests label Aug 4, 2026
@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test fcda426

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d24e7c4

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4941ebb

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9fc3e0a

Comment thread nemo_rl/models/generation/megatron/megatron_generation.py Outdated
Comment thread nemo_rl/models/generation/megatron/megatron_worker.py
Comment thread nemo_rl/models/generation/megatron/megatron_worker.py Outdated
Comment thread nemo_rl/models/megatron/memory_saver.py Outdated
@wdykas

wdykas commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

left a few minor comments but looks like it follows the megatron rl pattern and should be good

@wdykas wdykas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM except a few comments

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d549a67

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 796a168

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 738d84d

@tdene

tdene commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 07f392e

@tdene
tdene force-pushed the tde/refit_colocated branch from 738d84d to 07f392e Compare August 4, 2026 17:17
shanmugamr1992
shanmugamr1992 previously approved these changes Aug 4, 2026
@tdene
tdene force-pushed the tde/refit_colocated branch from 07f392e to 7a2653a Compare August 5, 2026 03:46
@tdene

tdene commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7a2653a

@tdene

tdene commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 94f7a94

@tdene

tdene commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 110a8b6

@tdene

tdene commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test fe4e7ac

tdene and others added 13 commits August 17, 2026 09:32
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
The NVIDIA-NeMo#3499 rebase replaced worker_init_timing_metrics with the
SetupTimingMetrics dataclass; the eager initial sync is the
generation load in that scheme.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
refit_policy_generation no longer hand-rolls the Megatron collective;
without a wired synchronizer it fell through to the vLLM broadcast
path (AttributeError: model_update_group).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
@tdene
tdene force-pushed the tde/refit_colocated branch from f81a58d to 4c3e03c Compare August 17, 2026 16:52
@tdene

tdene commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4c3e03c

Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
@tdene

tdene commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3ad74f7

@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.

Team review of the colocated Megatron reshard. 7 specialised agents plus two independent adversarial passes; 9 candidate findings were dropped as wrong or unfounded before posting.

Overall this reads well and I'd like to see it land. Routing Megatron through WeightSynchronizer removes 7 isinstance(policy_generation, MegatronGeneration) conditions from refit_policy_generation, and I verified the upstream API usage in detail (build_inference_pg_collection, swap_model_weights, the _pg_collection setattr, finalize() idempotency, and the torch_memory_saver pattern all match Megatron-LM / Megatron-Bridge precedent). The moe_router_num_groups reset is a genuinely necessary workaround for InferenceTopKRouter's assert, not a clobber.

Two items worth acting on before merge: the offload_optimizer_for_refit default silently changes behaviour for two shipped nemo_gym configs, and the colocated reshard path lacks the virtual-pipeline guard its nccl_reshard sibling already has. The rest are suggestions and nits.

Reviewed at 3ad74f7 (re-verified after the rebase).

Generated by Claude Code

Comment thread nemo_rl/models/megatron/setup.py Outdated
Comment thread nemo_rl/models/policy/workers/megatron_policy_worker.py
Comment thread nemo_rl/weight_sync/megatron_weight_synchronizer.py
Comment thread nemo_rl/models/policy/workers/megatron_policy_worker.py
Comment thread nemo_rl/models/generation/megatron/config.py
Comment thread nemo_rl/models/megatron/setup.py Outdated
Comment thread nemo_rl/models/megatron/setup.py
Comment thread nemo_rl/models/generation/megatron/megatron_worker.py Outdated
Comment thread nemo_rl/models/generation/megatron/megatron_worker.py
tdene added 4 commits August 17, 2026 17:38
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com>
@tdene

tdene commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5f1f294

@tdene

tdene commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@terrykong I believe I've addressed all the comments. I also found a couple of extra issues I fixed in 5f1f294

Can you please take another look?

@terrykong
terrykong enabled auto-merge (squash) August 18, 2026 00:09
@terrykong
terrykong merged commit 3d873eb into NVIDIA-NeMo:main Aug 18, 2026
177 of 180 checks passed
asolergi-nv added a commit that referenced this pull request Aug 18, 2026
…03-elastic-recovery

Part 2 (#3590) landed as a squash, so every file it touched conflicts with
itself here. Verified all 17 are byte-identical between the Part 2 branch tip
and main, which makes "ours" (that same content plus this branch's delta) the
provably correct side. pyrefly.toml was the one real conflict: three commits
each appended an allow-list entry, all three kept.

The substantive change comes from the colocated Megatron reshard (#3490):
mark_stale() is gone from WeightSynchronizer and every implementation, with
per-step staleness now owned by the training loop. Nothing on this branch
called it, so the removal merged cleanly; the one leftover was a fake in
test_reconcile_communicator that still defined it, now dropped so the fake
matches the interface it stands in for.
@yuki-97 yuki-97 mentioned this pull request Aug 26, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants