NVIDIA-NeMo/RL #5138 · depends on Gym #5771 · permalinks pinned to head 439d37b0
allow_system_suffix for forest training on native vLLM, and adds an RL check: reuse the saved tokens only if the full prompt starts with the history exactly as rendered on its own. Otherwise, start a new root, quietly.Dotted words have a short explanation: hover or tap them.
Some chat templates move every system message to the top of the prompt. If a system message arrives after the answer, the template renders it before the history. Counting end-of-turn tokens then cuts in the wrong place: the system message is cut away and the history appears twice. The PR's fix is one comparison in _render_chat_call: does the full render start with the history render? Only decide_capture_input reads the answer, and only when the new messages include a system message.
Lane A and the red box use the PR's own test, test_system_suffix_checks_rendered_prefix_before_capture, with token ids written as words. The review ran the red box's case on this PR and on its base, and both give exactly that prompt. The green dashed box is what the review asks for; it is not in the PR.
Render step, before (base 9a7640c)
# vLLM chat server, once per chat call (event loop); Dynamo's render pool runs the same method def _render_chat_call(request, messages, admission): full = render(messages) if managed_capture: decision = resolve_capture_input(admission, messages) # Gym never sent a system suffix if decision.serving.mode == "token_in": # only calls that will splice history = render(messages[:last_answer + 1]) return full, history, decision
Render step, after
# same place, same thread def _render_chat_call(request, messages, admission): full = render(messages) if admission.mode in ("candidate", "token_in"): # moved up: now before the decision history = render(messages[:last_answer + 1]) if managed_capture: stable = bool(history) and full[:len(history)] == history # the new check decision = resolve_capture_input(admission, messages, stable) if decision.serving.mode == "token_in": history = render(...) return full, history, decision
Decision, after (new lines only)
# called from the render step above def decide_capture_input(admission, messages, rendered_prefix_is_stable=False): ... # text mode, missing proof → root (unchanged) suffix_roles = roles of the new messages if "system" in suffix_roles and not rendered_prefix_is_stable: warn("rewrites the rendered prefix"); return root # root keeps any checkpoint cut ... # boundary check, then token_in (unchanged)
Gym startup config, after
# Gym actor startup (one Ray actor per Gym stack) def _spinup(): token_id_capture = {..., parent_resolution: "source_history" if forest else "fingerprint"} if forest_training and backend == "vllm_worker": # the only pair Gym #5771 accepts token_id_capture["allow_system_suffix"] = True # C1: the pinned Gym rejects this key
Real code: _render_chat_call, decide_capture_input / resolve_capture_input, _spinup.
The check matches what Gym #5771 asks of the serving side (Gym doc). Gym admits a call when every new message is a user, tool or system message. RL runs the check whenever a system message is among them, in any order. If the first len(history) tokens are unchanged, a moved system message would have to sit after the history, so the splice cannot cut it away. A template that renders the last answer differently once something follows it (Qwen3 with empty reasoning adds an empty think block only when the answer is last) fails the check and starts a new root. That is safe, and no worse than before.
The asks are about landing, tests and docs, plus what to do when the template and the harness disagree:
allow_system_suffix is set.system_message_reordered) if it is dropped or moved before the history. The check renders a copy of the messages with plain markers in place of the content, through the same vLLM render, and compares marker positions in the text. It never decodes tokens. In non-forest mode this also fixes the red box, which happens today on both this PR and its base.🔴 C1 — nemo_gym.py:1429 C2 — nemo_gym.py:1433 C3 — context-compaction.md:100 C4 — chat_server.py:262 C5 — capture_context.py:71