Stack: #4801 → #4912 → #5023 → #5024 → #5025 → #5097 · main at 5e271174, this PR at c396aafa, the C1 draft at d40ae141
DynamoMegatronAdapter on the same base class as vLLM, calling the native Megatron worker. A draft shows it as real code: terrykong/RL#58.Three pages for this PR. The ★ page links every page in the stack.
Background. Dynamo's frontend sends each request to a Worker running inside an engine process. The Worker hands it to an adapter, the class that knows how to run a request on that engine. On main, NeMo-RL writes that class once (DynamoEngineAdapter) and vLLM fills in four methods. In prefill/decode serving, one engine reads the prompt and hands its KV cache to a second engine that writes the answer; the handoff is the step this stack adds. Dotted words have a short explanation: hover or tap them.
Same example in all three columns: one completion request, prompt token ids [1, 2, 3], 2 new tokens. The Megatron columns use one prefill and one decode engine.
| vLLM on main | Megatron in this PR | Megatron after C1 | |
|---|---|---|---|
| Who owns the adapter class | NeMo-RL | Megatron-LM; #5097 subclasses it | NeMo-RL, same base as vLLM |
| How a request reaches the engine | direct call into the worker | through the coordinator, over sockets | direct call into the worker |
| Steps to register | 1 | 2 (start, then attach + "ready") | 1 |
| Ports NeMo-RL picks | none | 2 per engine, picked then bound later (C5) | none |
| Capture, routed experts, cuts | native worker | outside the native worker; routed experts and cuts refused in #5097 | native worker, so the same as Megatron without Dynamo (which does not return routed experts today either) |
| Where P/D handoff lives | (no P/D on main) | inside Megatron-LM's adapter | three hooks on the shared base; Megatron-LM's KV functions called from them |
Rank 0 serves the engine — this PR
# Ray call on rank 0; the adapter runs as a task on the engine's inference loop def start_dynamo_endpoint(namespace, engine_env, …): event, system = pick free ports in [4000, 4100) # released, bound later (C5) os.environ |= engine_env + {DYN_SYSTEM_PORT: system} cfg = Config(external mode, role, event port, …) run on inference loop: Worker(MegatronLLMEngine(cfg)).run() # second Ray call, every rank def attach_dynamo_events(addr): reporter.connect(addr); reporter.send("ready", coordinator address)
After C1 (draft)
# Ray call on rank 0; same function vLLM registers through def start_dynamo_endpoint(namespace, engine_env, …): event, system = pick free ports in [4000, 4100) cfg = Config(external mode, role, event port, …) adapter = DynamoMegatronAdapter(self, role) # calls this worker directly engine_adapter.start_dynamo_endpoint(adapter, engine_env) # DYN_SYSTEM_PORT stays "0" def attach_dynamo_events(addr): … # gone: no event socket
Real code: this PR's start_dynamo_endpoint; main's start_dynamo_endpoint; the draft's diff.
C1 asks for the right-hand column: one adapter shape for every backend, so Megatron runs capture and generation cuts through its own worker the way vLLM does, and the later PRs shrink (#5025 uses main's rollout_client, #5097 drops its two refusals). C5 asks that the two picked ports not come along. The draft PR is there so the difference is visible as code, not to be merged.
What in the draft is real and what is not: start, serve_rollout (plain and decode-with-handoff), serve_prefill, abort and kv_event_sources call real Megatron code. Two steps are stubs, release_handoff and the decode-side claim, because Megatron-LM keeps the RELEASE_KV / CLAIM_KV messages in private methods of MegatronLLMEngine; the draft names them, and they need one small upstream change that turns them into functions. The CPU unit tests pass (75) against stand-ins for the Linux-only Dynamo package; nothing ran on a GPU.
C1 · dynamo_worker_mixin.py:327 C5 · dynamo_worker_mixin.py:264 draft · terrykong/RL#58 design · one P/D interface