Stack: #4801 → #4912 → #5023 → #5024 → #5025 → #5097 · this page: part 3 of 6, reviewed against #4912 · code links pinned at 868942a0; the review comments are on head c396aafa, which adds merges from main, including the move to Dynamo 1.8
backend: megatron with dynamo: true; part 5 (#5025) turns it on. The review asks for one design change (C1: build the adapter on the same base as vLLM) and three smaller fixes (links below).Three pages for this PR. The ★ page links every page in the stack.
Background. Dynamo needs three services: etcd (where engines list themselves), NATS (events) and the frontend (HTTP). Each engine runs a Dynamo Worker wrapped around an adapter that knows how to talk to that engine. In prefill/decode serving, one engine reads the prompt (prefill) and hands its KV cache to a second engine that writes the answer (decode). Dotted words have a short explanation: hover or tap them.
vLLM already does this: once the engines load, the driver asks each data-parallel leader to start its endpoint, which wraps the engine in NeMo-RL's own adapter. A Megatron engine has no weights until the first refit, so this PR starts its endpoint in the first resume_after_refit. It also uses Megatron-LM's adapter, MegatronLLMEngine, which does not hold the engine. It waits for a "ready" message with the address of the engine's coordinator, then sends requests there. Example below: vLLM with 3 data-parallel leaders, and Megatron with 1 prefill engine (2 GPUs) and 1 decode engine (4 GPUs).
Inside ③ on the right, the second call in ② is attach_dynamo_events: rank 0 connects an event reporter to port 4000 and sends ready {coordinator_address}. Only after that does the adapter register the engine.
Where they become one. Both use the same ManagedDynamoRuntime.start for the services, the same wait_for_engines on the driver. That method is now a thin wrapper: it checks that etcd and NATS are still running, then calls wait_for_engine_registrations, the poll of each frontend's /health and /v1/models. This PR moved that poll out of the class for one reason: on the single controller, the first resume after a refit can also come from the controller's pickled copy, which owns no etcd or NATS process, so it can only run the poll. vLLM registers at setup on the driver, so it never needs that second entry point. They also share the same Dynamo Rust Worker. What still differs after that: the adapter class (NeMo-RL's vs. Megatron-LM's), when it starts (after load vs. at the first refit), how it reaches the engine (direct call vs. the coordinator), the component names, and how the plane and port settings are read.
| Question | vLLM | Megatron (this PR) |
|---|---|---|
| Who starts the endpoint? | The driver, right after the engines load. | Whoever makes the first resume_after_refit call: the driver at setup, or the controller's copy. A repeat call returns the first call's ports (L237-L246). |
| What crosses into the engine actor? | namespace, engine_env | Those, plus the model name, a start timeout and the ports other engines on the node took; back come the event and system ports and, for decode, a handoff owner id. |
| What tells the driver it failed? | dynamo_endpoint_error on each leader, polled during the wait. | The same, through check_alive, polled during the wait. A stopped endpoint cannot start again in that process. |
| Which adapter? | NeMo-RL's DynamoEngineAdapter, filled in by DynamoVllmAdapter. | Megatron-LM's own MegatronLLMEngine. The review (C1) asks for a NeMo-RL DynamoMegatronAdapter on the same base as vLLM instead, so both backends share one adapter shape. |
Controller: the first resume after a refit, before
# driver or controller copy; one call per training step def resume_after_refit(): errors = restore_engines() # every engine resumes, bounded by a deadline if errors: raise
After
# driver or controller copy; one call per training step def resume_after_refit(): errors = restore_engines() # every engine resumes, bounded by a deadline if errors: raise if fleet_ready: return # only the first resume does the rest for engine in engines: # in order, one deadline for all meta = engine.rank0.start_dynamo_endpoint(…) # {event_port: 4000, system_port: 4001} engine.all_ranks.attach_dynamo_events(meta.addr) # rank 0 sends "ready" wait({"prefill": 1, "backend": 1}, check_alive) fleet_ready = True
Engine rank 0: start_dynamo_endpoint (new)
# Ray call on rank 0; the adapter then runs as a task on the engine's inference loop def start_dynamo_endpoint(namespace, engine_env, …): if endpoint stopped: raise # one Worker per process if started: return same ports event, system = free ports in [4000, 4100) os.environ |= engine_env + {DYN_SYSTEM_PORT: system} cfg = Config(external mode, role, component, …) # C1: replace with a NeMo-RL adapter run on inference loop: Worker(MegatronLLMEngine(cfg)).run()
Real code: _await_dynamo_fleet_ready, start_endpoints, start_dynamo_endpoint, _report_dynamo_ready.
The shared parts hold up: the services are one class, the wait is one function both sides call (the controller's copy too), and the endpoint lifecycle has CPU tests. The main ask is the adapter in ③ (C1): build a NeMo-RL DynamoMegatronAdapter on main's DynamoEngineAdapter, as vLLM does, instead of hosting Megatron-LM's MegatronLLMEngine. The design and what the later PRs then do are on the one P/D interface page. The other three are small: the controller test's fake worker accepts any argument name (C2), after #4801, Megatron's config should not carry render_workers or session_affinity_ttl_secs (they do nothing until #5097 turns chat on), so each backend passes them to the runtime instead (C3), and two docstrings are stale (C4).
C1 · dynamo_worker_mixin.py:327 C2 · test_megatron_dynamo_generation.py:213 C3 · dynamo_config.py:78 C4 · dynamo_generation.py:1019