Repository navigation
feat(megatron): dynamo switch and per-role engine layouts - #4801
Conversation
61594f7 to
8ef2983
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Reviewed all 12 changed files and the directly affected configuration, setup, runtime, and refit contracts. The preparatory engine seam is appropriately separated from the deferred Megatron fleet implementation. No blocking correctness findings; one nonblocking type-check coverage issue is noted inline.
Validation was static only: tests and linters were not executed, and no delegated review was performed.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
8ef2983 to
ed14111
Compare
ed14111 to
e6d6957
Compare
|
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. |
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
e6d6957 to
e72303f
Compare
…bership shard widths Megatron prefill/decode engines served through a managed Dynamo frontend are switched on with policy.generation.dynamo=true on a backend=megatron config, the way vLLM engines will be. A new megatron.dynamo_config module validates the dynamo_cfg block (frontend args, timeouts, per-role prefill_engine / decode_engine layout overrides), sizes each role's engine from the layout its dedicated inference policy is built with (including the expert-parallel grid check), and tiles replicas prefill-first. RefitMembership gains per-shard widths with cumulative rank prefixes so a prefill shard at TP 4 can sit next to decode shards at TP 2 in one refit communicator; the vLLM and Megatron refit paths index workers through worker_offset. The legacy GRPO entrypoint refuses the switch; the SingleController sizes inference segments by the replica width. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
e72303f to
6593448
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
Follow-up complete; no eligible findings remain.
The earlier type-check finding no longer applies: the reported module is absent from the current Dynamo directory. The current worker-pool implementation is included in the type-check roots.
I inspected all 13 changed files across three delegated topics and checked the affected setup and refit contracts. The previously reviewed source tree was unavailable, so I couldn't establish which changes were introduced since the previous review. This approval is limited to the follow-up scope, not a fresh full review.
Validation was static only; tests and linters weren't executed.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.
lauradang
left a comment
There was a problem hiding this comment.
Thanks for splitting the stack so cleanly — the arithmetic held up under review. The refit offsets were hand-checked with widths (4, 2, 2) and a dead lower shard. The expert-grid check matches Megatron-LM's initialize_model_parallel divisibility rule at the pinned commit. merged_inference_megatron_cfg is unchanged for existing callers.
Four inline items. The one that matters is the first: until PR 5 lands, the SingleController silently accepts dynamo: true.
Generated by Claude Code
…layouts - MegatronGeneration.validate_settings checks a dynamo config with validate_megatron_dynamo_generation and then refuses it, so the SingleController no longer trains plain aggregated engines with the switch on. - Per-role TP/PP overrides must be positive. - Type-check megatron/dynamo_config.py. - Test the non-megatron backend guard in resolve_generation_class. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
A Megatron engine behind Dynamo learns whether it is a prefill or decode engine from policy.generation._dynamo_role, which the engine fleet sets on each engine's own copy of the config (as TrtllmGeneration injects trtllm_cfg._engine_roles). The worker can then build the handoff engine for that role without a separate pre-build attach call. Validation refuses the key in a user's config. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
CI label:
|
jthomson04
left a comment
There was a problem hiding this comment.
Reviewed at 0db391a for the Dynamo side. The switch, the validation rules and the frontend args line up with the pinned Dynamo nightly and with Megatron-LM's integration at the pin (NIXL only, persist KV mode, one replica per engine). Two should-fix items inline; the third is a question. I haven't repeated Terry's threads.
…k by engine - Megatron behind Dynamo validates dynamo_cfg with the vLLM DynamoCfg; MegatronDynamoCfg, megatron_dynamo_cfg and DynamoFrontendArgsBase are gone. - backend megatron with disaggregation.enabled and dynamo off is refused instead of silently serving aggregated engines. - nvlink_domain_span behind Dynamo is the widest engine, not the replica: the router pairs prefill and decode engines across the whole fleet, so the KV handoff is not kept inside a replica. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 65b2e6b |
…ew-c4-c15 Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 709918f |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 2d6450e |
- MegatronGeneration.validate_settings refuses mcore_generation_config prefill_engine / decode_engine when dynamo is off; they were dropped without an error and the run used the shared layout. - dynamo/config.py module docstring covers Megatron as well as vLLM. - grpo.py guard comment names the side effects it actually precedes. - Tests: decode-wider nvlink_domain_span case; zero_prefill, frontend_tokenize and real_quant refusal cases; role layouts without Dynamo. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 6320c18 |
The per-role engine layout check indexed policy_config["generation"]["mcore_generation_config"], which pyrefly rejects because GenerationConfig has no such key. Reuse the mcore_cfg local that validate_settings already reads through MCoreGenerationConfig. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 9c549f8 |
lauradang
left a comment
There was a problem hiding this comment.
Self-review at 9c549f8. Thanks to terrykong and jthomson04: all 11 of their threads still hold at this head (C4–C15 and the three Dynamo threads). Only terrykong's C11 shared-module request is partly open; see C30 and C31.
Findings:
- (C29) Distillation now accepts
megatronwithdynamo=trueand ignores the Dynamo settings. Share the GRPO refusal with distillation. - (C30) Delete the unused
DISAGG_BACKENDS. - (C31) Make TRT-LLM use the shared layout helpers; restore the engine-count check first.
- (C32) Delete Megatron's
replica_width, which only tests call. - (C33) Drop the Dynamo check in
resolve_generation_classthat can never fire.
Checked and fine: the engine-width expert-grid rule matches Megatron-LM's initialize_model_parallel; the prefix-caching and persist requirements match Megatron-LM's disaggregation code; all 44 new tests pass on CPU; ruff is clean.
nemo-rl-review: kind=self harness=claude-code/2.1.329 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=9c549f8
- Add reject_megatron_dynamo_outside_single_controller in megatron/dynamo_config.py: for backend megatron it raises NotImplementedError when dynamo is on and ValueError when prefill_engine / decode_engine are set without dynamo. Call it from grpo.setup (replacing the inline check) and distillation.setup, so distillation no longer trains plain Megatron for a Dynamo config. - Drop the unread DISAGG_BACKENDS constant from disagg_layout.py. - Drop the duplicate dynamo guard in resolve_generation_class; the backend refusal test now targets configure_generation_config, the copy that runs. - Drop the test-only Megatron replica_width helper and its asserts. - Give each build_clusters Megatron Dynamo case an inference node count whole replicas fill. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
TRT-LLM kept its own copies of the layout helpers that disagg_layout.py now holds, so main had two resolve_disagg_layout functions and two engine planners. - trtllm/config.py drops _as_dict and resolve_disagg_layout and uses the shared ones; replica_width sums through replica_width_from. - TrtllmGeneration._plan_engines calls disagg_layout.plan_engines, so its layout errors are now ValueError instead of AssertionError. - plan_engines refuses a replica without at least one prefill and one decode engine, the check TRT-LLM's planner had: without it 0/0 hit ZeroDivisionError and 0/1 planned decode-only replicas. - grpo.py, nccl_reshard_utils.py and the TRT-LLM tests import resolve_disagg_layout from disagg_layout. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
|
/ok to test 45337a5 |
main d040a22 brings NVIDIA-NeMo#4801 (Megatron prefill/decode behind Dynamo), which adds its own disagg_layout.py with a subset of this branch's helpers, plus NVIDIA-NeMo#5267 (prefix counts per HTTP frontend) and NVIDIA-NeMo#5158 (multi-harness). - disagg_layout.py: this branch's module, with main's replica_width_from and main's plan_engines (ValueError instead of assert, role-count check). validate_disagg_entrypoint lets megatron + dynamo through to its own checks. - trtllm/config.py, trtllm_generation.py, grpo.py: keep the shared-module wrappers of this branch. - vllm_generation.py: fan the per-frontend prefix counts out per engine. - nemo_gym.py: pass both forward_session_id_as_conversation_id and multi_harness. Signed-off-by: Shiki Wu <[email protected]>
DisaggConfig takes num_prefill_engines / num_decode_engines as positive integers on this branch, so a zero count is refused when the layout block is read, before the Megatron Dynamo check and plan_engines see it. The three cases from NVIDIA-NeMo#4801 matched the later messages. Signed-off-by: Shiki Wu <[email protected]>
What and why
First of six PRs that serve NeMo RL's Megatron inference engines as separate prefill and decode workers behind a Dynamo frontend, under the SingleController. A prefill engine reads the prompt and builds its KV cache. A decode engine takes that cache over NIXL and writes the answer. The trainer pushes new weights into both after every step (a refit).
This PR is config, validation and layout arithmetic only. Nothing starts yet, and refit is unchanged.
What it adds
policy.generation.backend: megatron+dynamo: true, the same switch vLLM uses. The replica shape comes from the backend-neutralpolicy.generation.disaggregationblock.dynamo_cfg. Megatron reads the sameDynamoCfgblock as vLLM (dynamo/config.py): frontend router args and timeouts, every field with a default.mcore_generation_config.prefill_engine/decode_engine(EngineLayoutOverrides: TP and PP) let the two roles use different widths, the waytrtllm_cfgkeeps its own prefill and decode engines. Prefill (compute-bound) and decode (memory-bound) often want different widths; the KV handoff reshards between them.merged_inference_megatron_cfggains anoverrides=argument and drops the two role keys, so they never reach a model'smegatron_cfg.engine_width(role)= TP × PP of the layout the role's dedicated inference policy is built with. It refuses an expert-parallel grid that does not fit one engine, instead of failing at model build.replica_widthbuilds on it.disagg_layout.py(resolve_disagg_layout,replica_width_from,plan_engines,DISAGG_BACKENDS) holds what the disaggregated backends share, with the same names as the TRT-LLM layout module in feat: vLLM prefill/decode disaggregation for GRPO rollouts #4920.MegatronGeneration.nvlink_domain_spanis the widest engine: the router pairs prefill and decode engines across the whole fleet, so only one engine's ranks need NVLink.policy.generation._dynamo_roleis not a user key: a later PR in the stack setsprefillordecodeon each engine's own copy of the config, asTrtllmGenerationinjectstrtllm_cfg._engine_roles. Validation refuses it in a user's config.dynamo: truewith a backend other thanvllmormegatronis rejected.validate_megatron_dynamo_generationlists the shapes the engines cannot serve: no disaggregation, fewer than one prefill or decode engine, more than one frontend or frontend tokenization, colocation,refit_transportset, quantization, prefix caching off, KV mode other thanpersist, the Megatron HTTP server on.dynamo: true,MegatronGenerationrefusesdisaggregation.enabledand the per-role layouts, which only Dynamo engines read.MegatronGeneration.validate_settingsruns the checks above and then refusesdynamo: trueoutright, since nothing builds the engines yet. PR 5 removes that refusal.Diagrams come from the design doc "Megatron Prefill/Decode behind Dynamo in NeMo RL".
Stack
main ← PR 1 (#4801, this) ← PR 2 (#4912) ← PR 3 (#5023) ← PR 4 (#5024) ← PR 5 (#5025) ← PR 6 (#5097)
Each PR is based on the one before it, so review each against its own base. PRs 1–4 change nothing at runtime on their own; PR 5 turns the feature on; PR 6 adds NeMo-Gym serving.
Tests
test_megatron_dynamo_config.py(switch, per-role widths, expert grid, NVLink span, rejected shapes, refusals without Dynamo),test_setup.py(replica sizing → inference segment size),test_grpo.py(legacy entrypoint refuses).Issues
None
Convergence / perf / functionality proof
N/A: config, validation and layout arithmetic only.
dynamo: trueis still refused, so nothing new runs. GPU runs come with PR 5, which turns the feature on.Needs upstream changes
None for this PR. The stack as a whole needs a Megatron-LM pin with the Dynamo integration before PR 5 can run.
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code