Every class between a rollout and the engine: vLLM today, Megatron in this PR, Megatron after C1, and the author's counterproposal

Stack: #4801 → #4912 → #5023 → #5024 → #5025 → #5097 · main at 5e271174, this PR at 88fe34ee (the C1 draft is on c396aafa), #5097 at 751efd79, the C1 draft at d40ae141 · Megatron-LM pin e0a4bfed, Dynamo 1.8.0.dev20261117, vLLM 0.33.0

vLLM today
NeMo-RL's adapter lives in the engine actor, holds the worker, and calls the same worker method native generation uses.
This PR
Megatron-LM's adapter lives in the engine actor but holds no worker. It reaches the engine through a second client to the coordinator, and gets the engine's events back over a socket pair inside the same process. The engine actor is the native MegatronPolicyWorker: #4912 removed the separate Dynamo worker class.
Author's proposal
Proposed in the C1 thread, not written yet. Column D is column B today; everything drawn on top of it is proposed. It keeps Megatron-LM's adapter and asks for four Megatron-LM changes. Sharing vLLM's base class comes in a follow-up PR.
After C1
Proposed, not in the PR. Column C has the same shape as column A. The comments are in a pending review, so their links open only after it is published.

Three pages for this PR. The ★ page links every page in the stack.

How to read the figure. This is a composition diagram, the containment half of a UML class diagram. A dashed box is a process: purple for a Ray actor, gray for a plain OS process. A solid box inside it is one object. A line field ──▶ Type means "this object holds a pointer to a Type in that field" (has-a). A hollow triangle ▷ Base means "this class is a subclass of Base" (is-a). The colored chip at a box's top right says which repo the class's code lives in: pink NeMo-RL, yellow Megatron-LM, gray Dynamo, brown vLLM. Column D is the author's counterproposal from the C1 thread: an outlined MLM change badge marks a Megatron-LM change it needs (proposed, not in Megatron-LM yet), a struck-through row is what that change would remove, and the box with a dotted gray border is what it leaves for a follow-up PR (tap it for pseudocode). Every name is a permalink. Each process row starts at the same height in every column, but the boxes inside do not line up, so the fill does the comparing: green means the same class is also in another column, hatched green means another column has a different class in the same role, and a plain box with a dark border exists only in this column. A teal dash-dot inner line with a ↻ #5097 badge marks a class that #5097 moves out of dynamo/vllm/ and reshapes; hover or tap it to see how, as before → after pseudocode. The border color is a separate signal: what the review asks to change, and every ask names the PR its comment is on (#5023 C1 is for this PR; #4912 C10 and #5097 C5 are for the PRs below and above). An outlined chip such as #5025 or #5097 marks a box or line that a PR above this one adds; the Show: up to #5023 button fades them so you see this PR alone. A box with a dashed inner panel shows the one object whose class a later PR swaps (is-a, not a second object).

The classes, side by side

Show: Hover, tap or tab to a box to light up its twins in the other columns.
A · vLLM on mainat 5e271174layers: 4 written for Dynamo · 2 shared with nativeB · Megatron in #5023 (+ #5097)at 88fe34ee (head) / 751efd79layers: 5 written for Dynamo · 1 shared · 1 socket pairC · Megatron after C1 (draft)at terrykong/RL d40ae141 (on c396aafa)layers: 4 written for Dynamo · 3 shared with nativedriver: GRPO / SingleController processVllmGenerationNeMo-RLGenerationInterfaceworker_groupRayWorkerGroup_dynamo_runtimeManagedDynamoRuntimedynamo_frontend_urlstuple[str]① _generate_through_dynamo → post_rollout()ManagedDynamoRuntimeNeMo-RL_etcd_process_ServiceProcess (etcd)_nats_process_ServiceProcess (NATS)_frontend_hosts[FrontendHost actor]serves_chatbooldriver: GRPO / SingleController processMegatronDynamoGenerationNeMo-RLGenerationInterface_engines[MegatronGeneration]P + D_engine_handles[MegatronDynamoEngineHandle]_dynamo_runtimeManagedDynamoRuntime① generate_async: NotImplementedError① then generate_through_frontend()#5025MegatronGeneration (one per engine)NeMo-RL_policyPolicyPolicy.worker_groupRayWorkerGroupManagedDynamoRuntimeNeMo-RL_etcd/_nats_process_ServiceProcess_frontend_hosts[FrontendHost actor]serves_chatFalse hereC3 mootdriver: GRPO / SingleController processMegatronDynamoGenerationNeMo-RLGenerationInterface_engines[MegatronGeneration]P + D_engine_records[MegatronDynamoEngine]_dynamo_runtimeManagedDynamoRuntime① generate_through_frontend()#5025unchanged by C1MegatronGeneration (one per engine)NeMo-RL_policyPolicyPolicy.worker_groupRayWorkerGroupManagedDynamoRuntimeNeMo-RL_etcd/_nats_process_ServiceProcesschat_render_workersint | None#5023 C3session_affinity_ttl_secsint | None#5023 C3#5023 C3 ask, not in the draft: replaces serves_chatFrontendHost Ray actor (0 GPU) × num_frontendsFrontendHostNeMo-RL_process_ServiceProcessstarts: python -m dynamo.frontendOS process: python -m dynamo.frontendHTTP server + KV routerDynamo (Rust)② picks an engine by KV-cache overlap↻ #5097ChatEngineFactoryNeMo-RL_capture_CaptureSource (TQ read)_early_poolRenderPoolmade by provider() at launch↻ #5097NemoRLChatEngineNeMo-RL_poolRenderPool_routed_engineDynamo's router_capture_CaptureSourcecalls vLLM helpers directly↻ #5097RenderPoolNeMo-RL_executorprocesses × render_workersbuilds _Worker, which is vLLM-only↻ #5097_Worker (one per render process)NeMo-RLonline_rendererFrontendRenderervLLMserving_chatFrontendServingChatvLLMFrontendHost Ray actor (0 GPU) × num_frontendsFrontendHostNeMo-RL_process_ServiceProcessstarts: python -m dynamo.frontendOS process: python -m dynamo.frontendHTTP server + KV routerDynamo (Rust)② prefill engine first, then decode#5097↻ChatEngineFactoryNeMo-RL_backendMegatronChatBackend_capture_CaptureSource (TQ read)_early_poolRenderPoolmade by provider() at launch#5023 serves no chat; #5097 turns it on#5097↻NemoRLChatEngineNeMo-RL_poolRenderPool_routed_engineDynamo's router_capture_CaptureSource_backendChatBackend protocolcalls backend.prepare_prompt(), …#5097↻RenderPoolNeMo-RL_executorprocesses × render_workersloads backend.renderer by name#5097MegatronRenderer (render process)NeMo-RLRenderWorker protocolchatChatRendererMegatron-LMChatRenderer is not in the pinned Megatron-LMFrontendHost Ray actor (0 GPU) × num_frontendsFrontendHostNeMo-RL_process_ServiceProcessstarts: python -m dynamo.frontendOS process: python -m dynamo.frontendHTTP server + KV routerDynamo (Rust)② prefill engine first, then decode#5097↻ChatEngineFactoryNeMo-RL_backendMegatronChatBackend_capture_CaptureSource (TQ read)_early_poolRenderPoolmade by provider() at launchsame as #5097: C1 does not touch the frontend#5097↻NemoRLChatEngineNeMo-RL_poolRenderPool_routed_engineDynamo's router_capture_CaptureSource_backendChatBackend protocolcalls backend.prepare_prompt(), …#5097↻RenderPoolNeMo-RL_executorprocesses × render_workersloads backend.renderer by name#5097MegatronRenderer (render process)NeMo-RLRenderWorker protocolchatChatRendererMegatron-LMengine Ray actor (GPU) × enginesVllmAsyncGenerationWorkerNeMo-RL…WorkerImplBaseVllmGenerationWorkerllmAsyncLLM_dynamo_endpoint_taskWorker(...).run()start_dynamo_endpoint(adapter, engine_env)WorkerDynamoengineDynamoVllmAdapter③ takes the request off the request planeDynamoVllmAdapterNeMo-RLDynamoEngineAdapterLLMEngineBaseEngine_hostthe worker above_llmAsyncLLMhandlers: rollout, Gym call, generation cut④ serve_rollout → ⑤ host._serve_rollout()⑤ is the same worker method native generate_async runsAsyncLLMvLLMthe engine; it runs vLLM's own engine-core processengine Ray actor (GPU) × ranks; rank 0 shownMegatronPolicyWorkerNeMo-RL…PolicyWorkerImplMegatronDynamoGenerationMixindynamic_inference_engineDynamoDynamic…Engineinference_clientInferenceClient #1_dynamo_event_reporterEngineEventReporter_dynamo_endpoint_futureWorker(...).run()start_dynamo_endpoint: picks 2 portsattach_dynamo_events: starts reporter#4912 C10 done: one worker class (via main)no role in its config: the mixin falls back to plainWorkerDynamoengineMegatronLLMEngine③ takes the request off the request planeMegatronLLMEngine (at #5023)Megatron-LMMegatron-LM's Dynamo adapter: serves token-id rolloutsLLMEngineBaseEngineclientInferenceClient #2_event_receiverEngineEventReceiver_publisherKvEventPublisherconfigConfig (external mode)↳ _event_receiver binds a picked port · #5023 C5④ generate → client → coordinatorholds no pointer to the worker#5097 buildsNemoRLMegatronLLMEngine#5097NeMo-RL subclass that adds Gym chat calls: samplingfrom the chat, TQ staging, chat settings. Megatron-LMcan't know about these.MegatronLLMEngine_hostthe worker (Gym staging)instead: same object, a subclass, not a wrapperhow #5097 changes this ▸EngineEventReporterMegatron-LMenginethe engineZMQ PUSH threadEngineEventReceiver↳ connects to that picked port · #5023 C5same process: KV events and 'ready' go over a socketDynamoDynamicInferenceEngineMegatron-LMStateHandoff…EngineDynamicInferenceEnginethe engine; every rank has oneengine Ray actor (GPU) × ranks; rank 0 shownMegatronPolicyWorker (the native one)NeMo-RLMegatronPolicyWorkerImpl…DynamoGenerationMixindynamic_inference_engineDynamoDynamic…Engineinference_clientInferenceClient (only one)_dynamo_endpoint_futureWorker(...).run()main's start_dynamo_endpoint(adapter)#4912 C10: mixin on the Impl, one class#4912 C10 is on main now; the draft predates itWorkerDynamoengineDynamoMegatronAdapter③ takes the request off the request planeDynamoMegatronAdapterNeMo-RLDynamoEngineAdapterLLMEngineBaseEngine_hostthe worker above#5023 C1④ serve_rollout → ⑤ host._generate_with…()serve_prefill / release_handoff (stub)kv events: engine listener, no socket⑤ is the native step; it uses the one client#5097Gym-call handler (added by #5097)NeMo-RLa Gym entry in _handlers(), as vLLMchat settings in start()'s runtime_dataasked in #5097 C5at #5023 the adapter serves rollouts onlyDynamoDynamicInferenceEngineMegatron-LMStateHandoff…EngineDynamicInferenceEnginethe engine; every rank has onegone after the askslist, not a classMegatronDynamoPolicyWorker (#4912 C10, done)MegatronLLMEngine + its Config (#5023 C1)NemoRLMegatronLLMEngine (#5097 C5)InferenceClient #2 (#5023 C1)EngineEventReporter / Receiver (#5023 C1)2 picked ports (#5023 C5)vLLM engine-core process (started by AsyncLLM)EngineCore (vLLM's, not NeMo-RL's)vLLMsame in native generationcoordinator process (spawned by rank 0)DataParallelInferenceCoordinatorMegatron-LM⑥ both clients and every rank connect over ZMQcoordinator process (spawned by rank 0)DataParallelInferenceCoordinatorMegatron-LM⑥ one client and every rank connectD · the author's proposalNow = column B unchanged; the rest is proposedlayers now = B · struck + badge = proposed MLM changedriver: GRPO / SingleController processMegatronDynamoGenerationNeMo-RLGenerationInterface_engines[MegatronGeneration]P + D_engine_handles[MegatronDynamoEngineHandle]_dynamo_runtimeManagedDynamoRuntime① generate_async: NotImplementedError① then generate_through_frontend()#5025MegatronGeneration (one per engine)NeMo-RL_policyPolicyPolicy.worker_groupRayWorkerGroupManagedDynamoRuntimeNeMo-RL_etcd/_nats_process_ServiceProcess_frontend_hosts[FrontendHost actor]serves_chatFalse hereC3 mootFrontendHost Ray actor (0 GPU) × num_frontendsFrontendHostNeMo-RL_process_ServiceProcessstarts: python -m dynamo.frontendOS process: python -m dynamo.frontendHTTP server + KV routerDynamo (Rust)② prefill engine first, then decode#5097↻ChatEngineFactoryNeMo-RL_backendMegatronChatBackend_capture_CaptureSource (TQ read)_early_poolRenderPoolmade by provider() at launch#5023 serves no chat; #5097 turns it on#5097↻NemoRLChatEngineNeMo-RL_poolRenderPool_routed_engineDynamo's router_capture_CaptureSource_backendChatBackend protocolcalls backend.prepare_prompt(), …#5097↻RenderPoolNeMo-RL_executorprocesses × render_workersloads backend.renderer by name#5097MegatronRenderer (render process)NeMo-RLRenderWorker protocolchatChatRendererMegatron-LMChatRenderer is not in the pinned Megatron-LMengine Ray actor (GPU) × ranks; rank 0 shownMegatronPolicyWorkerNeMo-RL…PolicyWorkerImplMegatronDynamoGenerationMixindynamic_inference_engineDynamoDynamic…Engineinference_clientInferenceClient #1_dynamo_event_reporterEngineEventReporter_dynamo_endpoint_futureWorker(...).run()start_dynamo_endpoint: picks 2 portsattach_dynamo_events: starts reporterMLM changeMLM changeMLM change#4912 C10 done: one worker class (via main)no role in its config: the mixin falls back to plainWorkerDynamoengineMegatronLLMEngine③ takes the request off the request planeMegatronLLMEngine (at #5023)Megatron-LMMegatron-LM's Dynamo adapter: serves token-id rolloutsLLMEngineBaseEngineclientInferenceClient #2_event_receiverEngineEventReceiver_publisherKvEventPublisherconfigConfig (external mode)↳ _event_receiver binds a picked port · #5023 C5④ generate → client → coordinatorMLM changeMLM changeresult hook: return engine_data.rolloutMLM changesampling hook: build_sampling_paramsMLM changecarry prompt routes in the handoffMLM changeattached mode: no event socket, no portsMLM changeall four: proposed by the author, not in Megatron-LM yetholds no pointer to the worker#5097 buildsNemoRLMegatronLLMEngine#5097NeMo-RL subclass that adds Gym chat calls: samplingfrom the chat, TQ staging, chat settings. Megatron-LMcan't know about these.MegatronLLMEngine_hostthe worker (Gym staging)instead: same object, a subclass, not a wrapperhow #5097 changes this ▸EngineEventReporterMegatron-LMenginethe engineZMQ PUSH threadEngineEventReceiver↳ connects to that picked port · #5023 C5MLM changesame process: KV events and 'ready' go over a socketDynamoDynamicInferenceEngineMegatron-LMStateHandoff…EngineDynamicInferenceEnginethe engine; every rank has oneDynamoMegatronAdapter (follow-up PR)NeMo-RLDynamoEngineAdapterLLMEngine_mlmMegatronLLMEngine (the box above)serve(): streams self._mlm.generate(…)base gains one serve() slot; vLLM unchangedno copied handoff code; one more layer#5097's Gym subclass: the proposal does not saythe follow-up, as pseudocode ▸coordinator process (spawned by rank 0)DataParallelInferenceCoordinatorMegatron-LM⑥ both clients and every rank connect over ZMQowner chipNeMo-RLMegatron-LMDynamovLLM= the repo the class's code lives in; NeMo-RL builds or calls classes from the others, it doesn't copy themRay actor (its own process)plain OS processholds a pointer (field → type)is a subclass of①–⑥ = one rollout, in orderfill = samenesssame class in another columnsame role, different classonly in this columnsame class, reshaped by #5097 (↻; tap it)border = reviewchips = stack#5097added by a PR above #5023 (faded by "up to #5023")↻ #5097reshaped by #5097how #5097 changes this ▸tap: before → after popovernew in C1#5097 C5 (added by #5097)asked by a comment, not in the draftremovedMLM changeneeds a Megatron-LM change (proposed)follow-up PR in the author's proposal

Scroll sideways on a phone. Not drawn: etcd and NATS (two plain processes the runtime starts in the driver), and the other model-parallel ranks, which hold an engine and an inference client but no Dynamo objects.

What #5097 refactors in the frontend (the ↻ boxes; same classes, new shape)

before (main)after (#5097)why
NemoRLChatEngine, ChatEngineFactory in dynamo/vllm/chat_engine.py; _serve calls on_policy_sampling and prepare_prompt directly Same classes in dynamo/chat_engine.py; _serve calls backend.checked_sampling, backend.prepare_prompt, backend.engine_options One chat engine serves vLLM and Megatron; the engine-specific steps sit behind ChatBackend.
RenderPool in dynamo/vllm/render_pool.py builds _Worker (vLLM objects) RenderPool in dynamo/render_pool.py imports a RenderWorker by name: VllmRenderer or MegatronRenderer The same pool runs Megatron's renderer.
prepare_prompt, PreparedPrompt in vllm/prompt_and_capture.py prepare_prompt, PreparedPrompt in gym_prompt.py; vLLM keeps a thin wrapper that adds its max-token clamp The prefix splice is not vLLM-specific.
CHAT_PROCESSOR points at the vLLM module CHAT_PROCESSOR points at the shared module; ChatProcessorOptions.chat_backend names the backend The frontend launch is the same for both engines.

Every layer a rollout passes through

One rollout, from the driver to the engine. "Dynamo-only" is code that exists only for the Dynamo path. "Shared with native" is code that native generation runs too, so it gets token capture, refit and routed experts for free.

layerA · vLLM mainB · #5023 (+#5097)C · after C1D · author's proposalkind
â‘  HTTP client in the driverpost_rolloutgenerate_through_frontend (#5025; #5023 has none)generate_through_frontend (#5025)generate_through_frontend (#5025)Dynamo-only
â‘¡ Dynamo frontend (Rust): HTTP + KV router1 engineprefill engine, then decode engineprefill engine, then decode engineprefill engine, then decode engineDynamo-only
③ Dynamo Worker in the engine actor✓✓ (rank 0)✓ (rank 0)✓ (rank 0)Dynamo-only
â‘£ adapter (the LLMEngine)DynamoVllmAdapterMegatronLLMEngine; from #5097 the subclass NemoRLMegatronLLMEngineDynamoMegatronAdapternow: MegatronLLMEngine plus 4 Megatron-LM hooks; follow-up: a DynamoMegatronAdapter that holds itDynamo-only
⑤ worker method native generation runs_serve_rolloutskipped_generate_with_persistent_engineskipped (Megatron-LM's generate runs the request)shared with native
client to the enginenone (AsyncLLM is in the actor)InferenceClient #2 Dynamo-onlyinference_client (the worker's)InferenceClient #2 Dynamo-onlyshared with native
â‘¥ engine's own extra processvLLM engine corecoordinatorcoordinatorcoordinatorshared with native
side channelnoneEngineEventReporter → ZMQ → EngineEventReceiver, 2 picked portsnoneas B today; none once attached mode lands (a proposed Megatron-LM change)Dynamo-only
total between caller and engine6 (4 Dynamo-only)6 (5 Dynamo-only, + a socket pair)7 (4 Dynamo-only)6 today, same as B (+ the socket pair); no socket pair after attached mode; 7 after the follow-up

C has one more layer than A or B, the native worker step. That layer is why C1 exists: it is how vLLM gets capture, routed experts and generation cuts without writing them again. D today is B. Its proposed Megatron-LM changes drop only the socket pair; its follow-up adds a wrapper layer, not the native step.

C vs D, in one line each. Both end with a DynamoMegatronAdapter under DynamoEngineAdapter. C fills the base class's existing slots (serve_prefill, serve_rollout, release_handoff), so NeMo-RL re-does Megatron-LM's handoff code. D adds one serve slot and hands the whole request to Megatron-LM's generate. What is open is timing (this PR or a follow-up) and the four Megatron-LM changes D needs. The staged reply (C6, not published yet) asks for D's follow-up shape in this PR.

commentfix it inwhat changes in the picture
#5023 C1this PRIn the engine actor, Megatron-LM's MegatronLLMEngine is replaced by a NeMo-RL DynamoMegatronAdapter on vLLM's base class. It holds the worker (_host), like DynamoVllmAdapter, and calls the native step. The second InferenceClient and the event socket pair go away. Draft: terrykong/RL#58.
author's reply on C1this PR + a follow-upColumn D. Keep Megatron-LM's MegatronLLMEngine; add a result hook, a sampling hook, routes in the handoff and an attached mode to Megatron-LM; later give DynamoEngineAdapter a serve slot so a thin DynamoMegatronAdapter can hold Megatron-LM's adapter. Declines the C1 draft because it copies Megatron-LM's handoff protocol (serve_prefill, _decode_from, _publish_kv_event, about 70 lines of private HandoffChannel code) and does not unblock routed experts or generation cuts, which native Megatron refuses too.
#5023 C5this PRThe two ports picked in start_dynamo_endpoint go away. With no event socket there is no event port, and DYN_SYSTEM_PORT stays "0" as main sets it. Still open at 88fe34ee: both ports are picked early, and the DYN_SYSTEM_PORT override is at L335. The author's plan removes them with attached mode in Megatron-LM, later.
#5023 C3this PRNo longer needed. Main now gives Megatron the shared DynamoCfg (read here), which has both render_workers and session_affinity_ttl_secs. serves_chat=False stays. A one-line reply saying so is staged.
#5097 C5#5097, aboveNemoRLMegatronLLMEngine (a subclass of Megatron-LM's class that overrides its private _stream_chunks) folds into C1's adapter: a Gym-call entry in _handlers() and the chat settings in start(), the way vLLM's adapter does it.
#4912 C10#4912, belowDone. The engine actor is the native MegatronPolicyWorker; MegatronDynamoGenerationMixin sits on MegatronPolicyWorkerImpl, and MegatronDynamoPolicyWorker is gone. #4912 merged that way, and it reached this PR with the merge of main at 4965ccf. The C1 draft is older (c396aafa) and still has the old class.
#5023 C2 · #5023 C4this PRFixed. No class changes: a test fake's signature (C2, 46f214f) and two stale docstrings (C4, 8014411). Both threads resolved.

What the author already changed (checked against the code at 88fe34ee)

commentstatuswhere
#4912 C10 one worker classaccepted#4912 merged with the mixin on the native worker (75d9ebc); reached this PR via the merge of main (4965ccf)
#5023 C2 test fake signaturefixed46f214f; thread resolved
#5023 C4 stale docstringsfixed8014411; thread resolved
#5023 C3 frontend config fieldsno longer neededmain's shared DynamoCfg has both fields; thread open until the staged reply is published
#5023 C5 picked portsopenno reply, no code change; ports picked at L319-L335. The author's plan: attached mode in Megatron-LM, later
#5023 C1 NeMo-RL adapterdeclined for nowher reply: keep Megatron-LM's adapter now, four Megatron-LM changes and a serve slot later (column D)

Design smell: what mirrors and what doesn't

The shape test: in a good design, swapping the engine changes only the boxes that touch the engine. After #5097 that holds for the frontend. In this PR it does not hold for the engine actor, where four objects (an adapter, a client, a reporter and a receiver) differ from vLLM's one. C1 brings it back to one. D brings it back to one too, but only after the follow-up and the four Megatron-LM changes.

C1 · dynamo_worker_mixin.py:327 C3 · dynamo_config.py:78 C5 · dynamo_worker_mixin.py:264 #5097 C5 · adapter.py #4912 C10 · megatron_policy_worker.py draft · terrykong/RL#58 author's reply · C1 thread