How one Megatron rollout reaches the engine: directly, or through the Dynamo frontend

NVIDIA-NeMo/RL · #4801 → #4912 → #5023 → #5024 → #5025 → #5097 · this page: PR #5025, reviewed against #5024 · permalinks at head 00d52a2c, base 9df434a7

Before
With backend: megatron and dynamo: true, startup refused the config: the prefill and decode engines were built and registered with the Dynamo frontend, but nothing sent them rollouts.
This PR
Turns the switch on. Each rollout is posted to the frontend as one HTTP completion request with token IDs in and token IDs plus log-probabilities out.
Status
New path, turned on by this PR. Review open. The output matches the direct path where the trainer reads it. The open items are a second rollout client next to main's (C1), a Megatron-LM pin that lacks a field every Dynamo engine needs (C17), a wrong startup error for Gym configs (C7), and no CI run of the new path (C3, C16). See the end of the page.

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

Background. A rollout is one prompt sent to the inference engine to get a completion back, with the log-probability of each new token. Dynamo's frontend can split one request across two engines: a prefill engine reads the prompt and builds its KV cache, then hands that cache to a decode engine over NIXL, which writes the answer. PRs 1–4 of this stack built those engines. Dotted words have a short explanation: hover or tap them.

Two paths to one Megatron rollout

Both paths start from the same call, generate_async, made by the trainer's rollout loop for one prompt. The direct path makes a Ray call to one Megatron worker, which runs prefill and decode in one engine. The new path builds an OpenAI completion request in generate_through_frontend and posts it over HTTP. The two meet again in the rollout loop, which reads only the new tokens and their log-probabilities. The example below is the PR's own unit test: prompt [1, 2, 3] padded to 4, one new token 8 with log-probability -0.5.

Direct: backend: megatron (one engine) This PR: megatron + dynamo: true (prefill → decode) driver process (rollout loop) driver process (rollout loop) ① MegatronGeneration.generate_async in: input_ids [[1,2,3,0]] input_lengths [3] → Ray streaming call to worker 0 ① MegatronDynamoGeneration.generate_async in: input_ids [[1,2,3,0]] input_lengths [3] → generate_through_frontend(), one prompt Megatron worker (Ray actor, GPU) still the driver: builds the HTTP body ② _build_sampling_params SamplingParams(temperature=1.0, top_k=0, top_p=1.0, num_tokens=16, termination_id=eod) ② completion_payload {prompt:[1,2,3], max_tokens:2, temperature:1.0, top_k:-1, logprobs:0, stop_token_ids:[2]} POST /v1/completions, ≤3 tries ③ one Megatron engine: prefill + decode generated_tokens [8] generated_log_probs [-0.5] no HTTP, no retry Dynamo frontend process + 2 engine worker groups (GPU) frontend prefill engine KV/NIXL decode engine {choices:[{finish_reason:"stop", logprobs: {token_logprobs:[-0.5]}}], nvext:{completion_token_ids:[8]}} ④ _parse_result_to_batched_data_dict output_ids [[1,2,3,8,0]] width 4 padded + 1 logprobs [[0,0,0,-0.5,0]] unpadded_sequence_lengths [4] (no truncated) ④ parse_completion_response + single_sample_output output_ids [[1,2,3,8]] width 3 + 1 logprobs [[0,0,0,-0.5]] unpadded_sequence_lengths [4] truncated [False] ⑤ both meet in the rollout loop (rollout_manager.py) output_ids[0, 3:4] → [8] logprobs[0, 3:4] → [-0.5] same on both paths ■ green = the two paths agree here ■ red = differs between the paths dashed box = one OS process or group of them

max_tokens:2 is the configured 16 cut to what fits: the test's max_model_len is 5 and the prompt is 3 tokens (allowed_new_tokens). top_k:-1 and top_k=0 both mean "off" in their own API.

The change, as pseudocode

Rollout call, before (#5024)

# driver, rollout event loop
async def generate_async(data):
    raise NotImplementedError("do not serve rollouts yet")

Rollout call, after

# driver, rollout event loop; one call per prompt, many run at once
async def generate_async(data):
    raise NotImplementedError("do not serve rollouts yet")
    if data is empty: return
    url = random.choice(frontend_urls)                 # every frontend reaches the whole fleet
    out = await generate_through_frontend(cfg, url, data)
    out["gen_leader_worker_idx"] = [0]                    # same as the direct path
    yield 0, out

# generate_through_frontend, same event loop
body = completion_payload(prompt ids, max_tokens = min(16, 5 - 3))
for attempt in 1..3:                                    # post_completion
    resp = await POST url + "/completions"               # new aiohttp session each try
    if not is_retryable(resp): break                # C1: timeouts retried, unlike main's client
    sleep 1 s
ids, lps, truncated = parse(resp)                      # nvext.completion_token_ids, token_logprobs
return single_sample_output(...)

Real code: async_http_post_json, parse_completion_response, single_sample_output. The vLLM Dynamo path already has its own client for this in rollout_client.py.

Startup check, before → after

# driver, setup_single_controller(), before anything is built
validate_single_controller_config(cfg)                 # C7: its penalty checks call should_use_nemo_gym()
...
if token_capture.enabled and not should_use_nemo_gym(cfg): …  # C7: asserts expose_http_server first
...
MegatronDynamoGeneration.validate_settings(cfg)       # moved up from after the Gym check
    raise NotImplementedError("not served by MegatronGeneration yet")
    if env.should_use_nemo_gym:            raise NotImplementedError  # follow-up PR 6
    if policy.is_vlm:                       raise ValueError
    if router_replay:                       raise ValueError          # kept from #5024
    if storage units on "inference":        raise ValueError
use_nemo_gym = should_use_nemo_gym(cfg)

Where they meet, and what still differs

The trainer only reads output_ids and logprobs between the prompt length and unpadded_sequence_lengths, so the narrower output width on the Dynamo path changes nothing. These do differ after the two paths meet:

WhatDirectThrough Dynamo
truncatednot setset from finish_reason == "length" (noted in the author's own review)
ignore_eos: truehonoured with termination_id=-1dropped from the request (covered by C1)
a failed requesta Ray errorretried up to 3 times, timeouts too; C1 asks to use main's rollout client instead
CIrun in L1functional test written, not in any lane until the Megatron-LM pin moves (C3); its preflight still expects ai-dynamo 1.5.1 (C16)
So what. The new path gives the trainer the same tokens and log-probabilities as the direct one, so a reviewer can judge it as "the same rollout, over HTTP". Before merge: the pinned Megatron-LM has no InferenceConfig.disaggregation_role, so a run dies at the first refit; make the worker's startup check catch that (C17), and add the 3-GPU functional test to L1 once the pin moves (C3). Move the startup check to the start of setup, so Gym configs get the clear error (C7). Send rollouts through main's rollout client and delete this module (C1), so retries, errors and sampling settings match native Megatron generation. Fix the functional test's ai-dynamo version check first, since the base now pins 1.8 (C16).

Review comments: C1 · dynamo_rollouts.py:309 C17 · dynamo_generation.py:334 C7 · setup.py:1831 C3 · L1_Functional_Tests_Dynamo.sh:54 C16 · functional test:39-40

These links open for everyone once the review is published.