PR #5097 (part 6 of 6, reviewed against #5025 at 62868966) · permalinks at head e6beabe5, base e85af6c2
backend: megatron and dynamo: true, NeMo-Gym could not run: setup refused expose_http_server: true (base check). Only vLLM served Gym's chat calls behind Dynamo, through a chat engine that lived in dynamo/vllm/.dynamo/, behind backend hooks, and adds a Megatron backend. It renders and builds replies with Megatron-LM's ChatRenderer, and serves Gym's decode leg in a subclass of Megatron-LM's Dynamo adapter.ChatRenderer (C1). Three steps behave differently from vLLM or from Megatron-LM's own endpoint (C3, C4, C5). Server faults reach Gym as "bad request" (C2, second page).Four pages for this PR, one question each: this one compares the backends. The first two chips are earlier parts of the same stack.
Background. NeMo-Gym runs agent environments. Its agents call the policy model over an OpenAI-style chat API. To keep training exact, NeMo RL turns each chat into token ids itself and pastes in the model's own token ids from earlier turns (token capture). Dynamo's frontend is one HTTP server in front of a prefill engine and a decode engine. Dotted words have a short explanation: hover or tap them.
Both backends now run through one function, NemoRLChatEngine._serve. It calls the backend at four points: the sampling check ②, the render ③ (in render worker processes), the prompt preparation ④, and the reply ⑨. The final token ids go through Dynamo's router to the engines, whose adapter on rank zero runs the call and writes the capture to TQ once. The numbers below are the PR's own unit-test values: chat template [1,7,2,3,4], EOS id 2, context limit 16 tokens.
| Step | vLLM | Megatron (new) | Same? |
|---|---|---|---|
| ② sampling | on_policy_sampling refuses a trained call whose sampling is off the train/validation profile | fills omitted fields only; min_p, penalties and logit_bias are dropped | No · C3 |
| â‘¢ render | vLLM's own renderer | Megatron-LM's ChatRenderer.render | Same token ids for the same chat |
| ④ prepare | One function for both, gym_prompt.prepare_prompt: splice, then clamp. Megatron adds its BOS rule through the finish_prompt hook, the same order as Megatron-LM's endpoint. | Yes, except add_BOS can never be sent · C5 | |
| ⑦ decode | the engine's own finish_reason | finish_reason guessed from the token count; any ValueError is answered as 400 | No · C4, C2 |
| ⑨ reply | vLLM's chat serving | ChatRenderer.build_response | Same reply shape |
The two paths share code up to prepare_prompt and the wire format (ForwardedCall, GymEngineReply). Render and reply stay per backend on purpose: each one must match its own native server, so Gym gets the same reply with or without Dynamo.
The chat engine, before (vLLM only, base)
# Dynamo frontend process, one task per call async def _serve(request): body.update(on_policy_sampling(body)) # vLLM's check, imported directly rendered = await pool.render(body) # vLLM renderer in worker processes plan = await prepare_prompt(rendered) # vllm/prompt_and_capture.py data = await call_engine(plan.token_ids) # router → prefill → decode return await pool.respond(data)
After (both backends)
# Dynamo frontend process, one task per call async def _serve(request): body.update(backend.checked_sampling(body)) # Megatron: fills defaults only (C3) rendered = await pool.render(body) # the backend's RenderWorker class plan = await backend.prepare_prompt(rendered) # shared splice + clamp; Megatron adds BOS data = await call_engine(plan.token_ids) # Megatron: NemoRLMegatronLLMEngine return await pool.respond(data) # Megatron: ChatRenderer.build_response
Real code: MegatronChatBackend, MegatronRenderer, NemoRLMegatronLLMEngine, VllmChatBackend.
ChatRenderer. Today every render worker fails with AttributeError, and the tests that would catch this are skipped (C1). Then the three red steps above need to match vLLM (C3, C4, C5).