Repository navigation
Conversation
|
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. |
305608c to
f3fd7e2
Compare
f3fd7e2 to
37213bc
Compare
37213bc to
74c9462
Compare
d4290d4 to
fdf1938
Compare
fdf1938 to
3228bf5
Compare
3228bf5 to
aa8e870
Compare
aa8e870 to
390601e
Compare
…o engines A refit of the prefill/decode engines now keeps in-flight KV handoffs whole. The Megatron worker's sleep is split into a pause (stop scheduling, keep admitted requests' KV) and a suspend; pause_for_refit runs the pause alone, pinned_handoff_block_count reads the prefill KV blocks still pinned for decode handoffs on the inference loop, and a wake of a paused-only engine just unpauses it. MegatronDynamoGeneration pauses the prefill engines first, so no new handoff starts, waits until the decode engines have pulled every block prefill still pins (PinnedHandoffTimeout past the deadline), suspends prefill, then decode; it resumes decode first, since decode is the reader of prefill's KV, and a failed suspend restores in that order too. Teardown attests decode termination to prefill: MegatronDynamoGeneration reads each decode engine's handoff owner (dynamo_endpoint_metadata), stops the decode engines, then has a prefill engine's rank zero run Megatron-LM's handoff-recovery hook (confirm_decode_terminated) against every listening prefill coordinator (dynamo_coordinator_address) so the blocks pinned for those owners are released before the prefill engines go down. A decode engine that did not stop cleanly is not attested. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
…tation check_alive probes every engine separately and treats a worker whose actor died (RayActorError) as dead, naming every dead engine and chaining the first error. The shutdown path calls rank zero's endpoint methods through the engines' worker handles with the control timeout (handoff owners and prefill coordinators read at once under one deadline), so a stuck engine is logged and still shut down instead of hanging the teardown. The MegatronGeneration endpoint wrappers go, since MegatronDynamoGeneration talks to each engine's rank zero directly, and init_collective no longer checks the membership it just built. confirm_decode_terminated attests every prefill coordinator concurrently and logs each failure with its address, so one unreachable coordinator no longer keeps the rest from releasing their pinned KV blocks; the overall wait is one per-coordinator timeout plus slack. An untagged prepare_for_generation no longer treats a paused engine as serving; it wakes it. The role-to-component mapping moves to dynamo_config, where the worker's endpoint start reads it too. Tests fake a dead actor in the liveness probe, hang endpoint calls during shutdown, and drive the pause, suspend and wake sequence against an engine that enforces Megatron-LM's control-signal states. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
390601e to
9b07997
Compare
…es by role The decode-then-prefill resume order was not needed. The engines keep their KV on the GPU across suspend and resume (the persist cache mode the handoff requires), and a handoff that reaches a decode engine still waking is queued and read into buffers the resume does not touch. In the weight synchronizer's sequence the kv_cache phase already wakes every engine at once, so the ordered wave never ran on the normal path and only shaped the restore after a failed suspend. Resume is now one wave in record order. The helper that picks the engines suspended after prefill now selects the decode role explicitly instead of "not prefill". Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
One shutdown failure-isolation bug needs a fix (C1): a failed coordinator-address lookup suppresses termination notices to healthy prefill engines.
Reviewed all six changed files and their directly affected refit, worker-control, liveness, and teardown paths. All three delegated inspections completed; two report bodies weren't delivered, so those topics were inspected directly. This was a static review: tests and linters weren't run. The upstream Megatron source and later stack heads weren't available for verification.
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 full review. Request a full review with /review reset=true.
…through live prefill - Refit pin wait: reads, liveness probes and sleeps share one deadline. A spent deadline, a pin read or a probe it cuts off raises PinnedHandoffTimeout with the last known counts. Every poll probes the fleet, so a dead engine or stopped endpoint fails the wait as itself. The counts are printed every 10 s while it waits. - PinnedHandoffTimeout is a RuntimeError, so the controller's refit await no longer replaces it with a "rank not answering" abort. - The wait's message and docs name both ways a pin is released: by the decode engine that claimed it, or by Megatron-LM's prefill coordinator once an unclaimed offer passes its 300 s timeout. - Shutdown: each prefill coordinator address is read separately, and attestation goes through a prefill engine that answered. Failed owner or address reads are logged and teardown continues. No prefill engine is asked when there is no decode owner to attest. - Worker: _pause, _sleep and _wake set their flags before the barrier, so a failed barrier does not leave the engine marked awake. - confirm_decode_terminated catches only the wait running out or being cancelled, and documents the precondition it is called under at shutdown. - Tests for each of the above, including Ray-gone shutdown, a pin read or probe cut off by the deadline, and a stopped endpoint mid-wait. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
Signed-off-by: Laura Dang <[email protected]>
Signed-off-by: Laura Dang <[email protected]> # Conflicts: # nemo_rl/models/generation/megatron/dynamo_generation.py
- The refit suspends prefill then decode directly instead of first holding prefill and waiting for decode to pull every KV block prefill still pins for a handoff. The engines run the `persist` KV cache, so suspend and resume leave the KV memory and the pinned blocks untouched and the transfer writes only parameters: decode reads the same bytes whenever it pulls a block. With a deep decode backlog the wait did not finish for over an hour, which tied every refit to decode capacity. The pin wait, its liveness probes and reports, and `PinnedHandoffTimeout` are removed. - The native refit fans out over every engine of the fleet: `swap_weights_via_reshard` reaches each engine's workers, and the Megatron weight synchronizer drives it end to end (tests cover a TP 2 prefill with TP 2 or TP 1 decode engines). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
Building a 64-engine fleet one engine at a time took about two hours. Every engine's cluster is still placed in order, and an engine split across nodes is now rejected there, before any engine is built. The MegatronGeneration builds then run up to 8 at a time, in rounds; a failed round submits nothing more. Engines are registered in launch order, so refit ranks are unchanged, and engines built before a failure are still shut down. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
terrykong
left a comment
There was a problem hiding this comment.
These comments come from the review of #4801, the first PR in this stack. They are staged here so they are not lost; please verify them before publishing.
Context. On main, the caller passes each control call its deadline: GenerationInterface takes timeout_s, and the SingleController fills it from async_rl.generation_fleet_health. #4801's C9 removes dynamo_cfg.control_timeout_s for that reason; main's outdated-config check already rejects the key. #5349 (open) runs fleet health behind the Dynamo frontends for vLLM.
- (C1) Use the caller's
timeout_sinstead ofcontrol_timeout_s. - (C2) Refuse
async_rl.generation_fleet_healthfor Megatron engines behind Dynamo.
Full review of this PR (C3–C8). Reviewed against #5023 (PR 3) only.
Thanks for the stack split and the clear diagrams. The persist-KV refit claims all hold against Megatron-LM e0a4bfed: suspend/resume keep the KV, the allocator and the pinned blocks; handoffs to a waking decode engine are queued; and the old-weights/new-weights mix is recorded per token, like the native path. The decode-first shutdown order, _start_engine building in parallel while registration stays in launch order, and moving swap_weights_via_reshard onto the record are all good choices.
- (C3) Drop the shutdown attestation: it releases nothing at full teardown and can stall shutdown once per decode engine.
- (C4) Remove the dead
pause_for_refit/ paused-state code left after the pin wait was removed. - (C5) Fix docstrings and comments that still describe the pin wait.
- (C6) Update the PR title and body.
- (C7) Delete the teardown loop that can no longer run.
- (C8) Add a test for engines built in a failed round.
Linter (ruff 0.9.9 check, isort, format) passes on all 7 files.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5024-fleet-order.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5024-shutdown-attest.html
Generated by Claude Code
terrykong
left a comment
There was a problem hiding this comment.
These comments come from the review of #4801, the first PR in this stack. They are staged here so they are not lost; please verify them before publishing.
Context. On main, the caller passes each control call its deadline: GenerationInterface takes timeout_s, and the SingleController fills it from async_rl.generation_fleet_health. #4801's C9 removes dynamo_cfg.control_timeout_s for that reason; main's outdated-config check already rejects the key. #5349 (open) runs fleet health behind the Dynamo frontends for vLLM.
- (C1) Use the caller's
timeout_sinstead ofcontrol_timeout_s. - (C2) Refuse
async_rl.generation_fleet_healthfor Megatron engines behind Dynamo.
Full review of this PR (C3–C8). Reviewed against #5023 (PR 3) only.
Thanks for the stack split and the clear diagrams. The persist-KV refit claims all hold against Megatron-LM e0a4bfed: suspend/resume keep the KV, the allocator and the pinned blocks; handoffs to a waking decode engine are queued; and the old-weights/new-weights mix is recorded per token, like the native path. The decode-first shutdown order, _start_engine building in parallel while registration stays in launch order, and moving swap_weights_via_reshard onto the record are all good choices.
- (C3) Drop the shutdown attestation: it releases nothing at full teardown and can stall shutdown once per decode engine. Stop the engines as vLLM does, with no role order.
- (C4) Remove the dead
pause_for_refit/ paused-state code left after the pin wait was removed. - (C5) Fix docstrings and comments that still describe the pin wait.
- (C6) Update the PR title and body.
- (C7) Delete the teardown loop that can no longer run.
- (C8) Add a test for engines built in a failed round.
- (C9) Suspend every engine in one wave, as resume does; the prefill-first order only served the removed pin wait.
- (C10) Build every engine at once instead of in rounds of 8 (about 3.8 h at 1,000 engines today).
- (C11) At shutdown, stop every engine at once (one cleanup call, at most 30 s, then kill), instead of one engine at a time.
Linter (ruff 0.9.9 check, isort, format) passes on all 7 files.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5024-fleet-order.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5024-shutdown-attest.html
nemo-rl-review: kind=expert harness=claude-code/2.1.330 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=9df434a
…one wave - Build every engine at once (one thread per engine), with each engine's placement-group reservation and node check on its own thread; register every engine that built when another fails, and stop an engine whose record could not be made. - Suspend every engine in one wave; after a failed suspend, resume every engine under a fresh deadline of the caller's length. - Take every control-call deadline from the caller's timeout_s (None waits without one); prepare_refit_info and set_rollout_weight_version have no deadline, as in VllmGeneration. Drop dynamo_cfg.control_timeout_s. Bound the readiness wait's liveness probes by startup_timeout_s. - Stop every engine at once at shutdown, like VllmGeneration.shutdown, with no role order and no decode-owner attestation; killing the workers ends the Dynamo endpoint, so stop_dynamo_endpoint goes. - Remove the worker's pause-only refit state (pause_for_refit, the paused flag, pinned_handoff_block_count) and the attestation helpers, which nothing calls once the pin wait is gone. - Fix docstrings and test names that still described the pin wait. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
…e old behaviour - Build a nine-engine fleet with barriers on placement, node discovery and the build itself, so a serial step or a pool smaller than the fleet fails. - Log ray.get waits next to the refit calls, so a suspend or resume that waits on one engine before sending the next fails. - Drive the hung-suspend test with a clock that runs out the suspend's deadline, so a restore reusing it fails. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Laura Dang <[email protected]>
| # Set before the barrier, as in _wake: the engine state is final once | ||
| # wait_until returned; the barrier only aligns the ranks. | ||
| self._inference_engine_asleep = True | ||
| torch.distributed.barrier() |
There was a problem hiding this comment.
C12 · 1 action item.
TL;DR — C4's last bullet is still open: this PR still moves where _sleep and _wake set the asleep flag, and adds a test for it. #4912 has since rewritten _sleep/_wake to follow the engine's state, so drop this change and take #4912's versions.
Follow-up to C4.
Fixed: pause_for_refit, _pause, the paused flag, pinned_handoff_block_count and their tests are gone (4840630).
Still open: C4 asked to "take _sleep and _wake from #4912 as they are, and drop this PR's change to where the flags are set". In _sleep and _wake, the PR still differs from its base only in that flag move:
_sleepL813-L816 and_wakeL836-L837 set the flag before the barrier.test_failed_barrier_after_suspend_leaves_the_engine_asleepand its_ControlSignalEngine/serving_workerhelpers test only that move.
#4912's head now drives _sleep/_wake from the engine's state through _finish_engine_transition, so a failed barrier no longer leaves a stale flag there. Keeping this PR's version means a conflict on restack and a test written for code #4912 replaces.
AI-1
Put the flag back after the barrier here, as in the base:
| # Set before the barrier, as in _wake: the engine state is final once | |
| # wait_until returned; the barrier only aligns the ranks. | |
| self._inference_engine_asleep = True | |
| torch.distributed.barrier() | |
| torch.distributed.barrier() | |
| self._inference_engine_asleep = True |
Do the same in _wake L836-L837 (barrier, then self._inference_engine_asleep = False). Then delete the test and its helpers and the asyncio and threading imports at L15 and L17, which only they use. Those are on other lines, so they can't be part of this suggestion.
What this changes
PR 4 of 6: keep in-flight KV handoffs intact during refit and release pinned prefill blocks when decode engines shut down. This extends the existing
MegatronDynamoGenerationinnemo_rl/models/generation/megatron/dynamo_generation.py; engine creation, endpoint registration, and refit fan-out are provided by the preceding PRs.Refit ordering
PinnedHandoffTimeout.prepare_for_generationalso wakes a paused engine.Shutdown and liveness
check_alive, alongside the existing endpoint-task checks.Diagrams come from the design doc "Megatron Prefill/Decode behind Dynamo in NeMo RL".
Stack
main ← PR 1 (#4801) ← PR 2 (#4912) ← PR 3 (#5023) ← PR 4 (#5024, this) ← PR 5 (#5025) ← PR 6 (#5097)
Review this PR against PR 3. The Dynamo generation switch remains guarded here; PR 5 wires rollouts through the frontend, and PR 6 adds NeMo-Gym serving.
Tests
Coverage is in the existing unit suites:
test_megatron_dynamo_generation.py: ordered pause/drain/suspend and one-wave resume, pinned-handoff timeout, recovery after suspension failure, shutdown/attestation order, partial-startup cleanup, dead actors, and bounded shutdown calls.test_megatron_dynamo_worker_mixin.py: coordinator attestation and worker event/engine state handling.test_megatron_generation.py: pause/suspend/wake state transitions, including abandoned pauses and untagged generation preparation.Before your PR is "Ready for review"