Skip to content

fix(data): render evaluation chat prompts as complete conversations - #4193

Merged
ZhiyuLi-Nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
yuchenwang3:fix/eval-chat-template-4185
Oct 11, 2026
Merged

ZhiyuLi-Nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
yuchenwang3:fix/eval-chat-template-4185

Conversation

@yuchenwang3

@yuchenwang3 yuchenwang3 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Render the optional system prompt and user prompt together in math_data_processor and multichoice_qa_processor, matching math_hf_data_processor.

For example, with Qwen2.5-Math and an explicit system prompt, independently rendering the user turn inserts another default system block (45 tokens instead of 25 in the issue's example). Templates that prepend BOS can duplicate that token too. Store the complete rendered conversation and its tokens in one user entry so the text joined by evaluation and the flattened token IDs describe the same prompt.

The existing user-prompt formatting, answer/subject/task metadata, and math length-masking condition are retained. The math length field still records the pre-truncation length.

Issues

Closes #4185. Thanks to @Alvorecer721 for the diagnosis, reproduction, and earlier implementation in 8dae172bd (September 3). This PR follows the same single-call rendering approach and adds coverage for both evaluation processors. Alvorecer721 is credited as a co-author.

Usage

No configuration changes. Evaluation with a configured system_prompt_file now renders the system and user turns as one conversation.

Validation

Current head: b7ffd3d6d374c30329239aee59b8c94e3924c4ac, built on Zhiyu's rebase at 6aa7d786.

  • 34 non-gated tests passed on macOS CPU (Python 3.13.14, Torch 2.13.0, Transformers 5.12.1). These include the 22 toy-tokenizer evaluation cases. The run used --confcutdir=tests/unit/data to exclude global Ray/GPU telemetry fixtures.
  • 33 real-tokenizer evaluation cases passed with Qwen2.5-Math-1.5B-Instruct (aafeb0fc), Qwen3-0.6B (c1899de2), and DeepSeek-R1-Distill-Qwen-1.5B (ad9f0ae0). The final run used the existing tokenizer cache offline and checks rendered text, token IDs, metadata, and math length boundaries.
  • The fixture now covers the 10 real chat templates suggested by @ZhiyuLi-Nvidia. With the normal project conftest, the default route selects 34 tests; --hf-gated selects 198, including 132 new evaluation cases (110 real-template and 22 toy-template cases). This is collection/routing verification, not a local run of all 198 cases.
  • Zhiyu's nightly-container validation reported 132 new cases and 198 total cases passing with this fixture; the base plus fixture had 83 failures and 49 passes. Those are his results, not a second full run here.
  • Formatting, import, whitespace, and recipe checks passed. Full Pyrefly has the same 34 diagnostics on 6aa7d786 and this patch (identical normalized JSON), including missing optional dependencies; the full project type-check is not clean in this local environment.
  • Full gated CI and GPU tests remain pending. The earlier CI run skipped tests because the PR lacked a CI:L* label.

AI assistance: OpenAI Codex implemented the tests and ran the local checks. The real-template fixture was suggested by ZhiyuLi-Nvidia, who is credited on the new commit.

Pre-checks

  • Read the contributor guidelines.
  • Added regression tests and ran the focused CPU tests.
  • No documentation/config changes are needed for this bug fix.
  • Full GPU unit/functional suite (requires CI).

@yuchenwang3
yuchenwang3 requested review from a team as code owners September 18, 2026 05:58
@copy-pr-bot

copy-pr-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Alvorecer721

Alvorecer721 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for picking this up, and for the thorough tests.

For context: I work on Project Apertus at the ETH AI Center, and we collaborate with the NeMo RL team on this codebase. In our biweekly meeting we agreed that we upstream the fixes from our fork, and this one was next on my list. I had it on our fork before filing the issue: 8dae172bd from Sep 3, tracked in Alvorecer721/Nemo-RL#48, which is cross-referenced on #4185. It takes the same approach: one chat-template call with the system and user messages, matching math_hf_data_processor, plus a regression test with a template that injects a default system block.

Your PR is further along on tests, so I'd rather not open a competing one. Since the fix follows the approach proposed in the issue and the earlier commit, would you be willing to add me as a co-author?

Co-authored-by: Alvorecer721 <[email protected]>

Happy to review here as well.

@yuchenwang3
yuchenwang3 force-pushed the fix/eval-chat-template-4185 branch from ce1332e to 551991a Compare September 20, 2026 04:14
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

Thanks @Alvorecer721 for the context, the original fix, and the reproduction. I have added you as a co-author and linked your September 3 implementation in the PR description. Apologies for overlooking that earlier work when preparing this PR. I appreciate your willingness to review here!

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 22, 2026
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

@Alvorecer721 Could you review the evaluation chat-template fix when you have a chance? Your co-author credit is included, and the current head is 551991a1155d91f04948f1ee4e14d3569da2a1b8. The regression tests cover templates with and without a default system block; there has not been a new review or functional CI run.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 4, 2026
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

@aroshanghias-nvd Could you help route this to CI when you have a chance, with CI:L0 and approval for 551991a11? It fixes duplicate system/BOS tokens caused by rendering evaluation turns separately. The CPU and real-tokenizer results are in the description, but no unit-test CI has run for this head yet. Thanks!

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Oct 9, 2026
@ZhiyuLi-Nvidia ZhiyuLi-Nvidia self-assigned this Oct 9, 2026
Assisted-by: OpenAI Codex
Signed-off-by: Yuchen Wang <[email protected]>
Co-authored-by: Alvorecer721 <[email protected]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the fix/eval-chat-template-4185 branch from 551991a to 6aa7d78 Compare October 9, 2026 17:43
@Alvorecer721

Copy link
Copy Markdown
Contributor

LGTM @yuchenwang3, sorry I was on holiday, and thanks @ZhiyuLi-Nvidia for taking care!

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test 6aa7d78

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Suggestion: also run the new eval tests against the real chat templates from #4185 (hf_gated, so CI's --hf-gated data lane picks them up).

Verified in the nightly container with an HF token:

new eval cases full test_data_processor.py
this PR + suggestion 132 passed 198 passed
base 30a32dd2 + suggestion 83 failed / 49 passed (every failure has a system prompt) —

Extra runtime is ~15 s with a warm HF cache (one tokenizer load per model; ~0.02 s per case).

The toy-only system: / assistant: / <bos> / Default instruction. assertions are dropped because rendered == expected_text already implies them, and they don't apply to real templates.

-@pytest.fixture(params=[False, True], ids=["default-system", "default-system-bos"])
+# Real chat templates from issue #4185. Two-call rendering changes the prompt for
+# each of them; Qwen3 keeps the same token IDs and only checks the joined text.
+_EVAL_CHAT_TOKENIZERS = [
+    "Qwen/Qwen2.5-Math-1.5B-Instruct",
+    "moonshotai/Moonlight-16B-A3B-Instruct",
+    "openai/gpt-oss-20b",
+    "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
+    "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
+    "meta-llama/Llama-3.2-1B-Instruct",
+    "microsoft/Phi-4-mini-instruct",
+    "mistralai/Mistral-Nemo-Instruct-2407",
+    "zai-org/GLM-4.5-Air",
+    "Qwen/Qwen3-0.6B",
+]
+
+
+# Module scope loads each tokenizer once and keeps one in memory at a time.
+@pytest.fixture(
+    scope="module",
+    params=[
+        "default-system",
+        "default-system-bos",
+        *(
+            pytest.param(name, marks=pytest.mark.hf_gated)
+            for name in _EVAL_CHAT_TOKENIZERS
+        ),
+    ],
+)
 def eval_chat_tokenizer(request: pytest.FixtureRequest) -> PreTrainedTokenizerFast:
+    if not request.param.startswith("default-system"):
+        return get_tokenizer(
+            TokenizerConfig(name=request.param, chat_template="default")
+        )
     backend = Tokenizer(
@@
-    if request.param:
+    if request.param == "default-system-bos":
         template = "{{ bos_token }}" + template
@@ def test_eval_processors_render_complete_conversation(
     assert rendered == expected_text
     assert token_ids.tolist() == expected_ids
-    assert rendered.count("system:") == 1
-    assert rendered.count("assistant:") == 1
-    assert rendered.count("<bos>") == expected_text.count("<bos>")
-    assert ("Default instruction." in rendered) == (not with_system)
     assert result["length"] == len(expected_ids)

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Just a nit, looks good to me elsewhere.

Use the module-scoped fixture suggested by ZhiyuLi-Nvidia for the ten
chat templates from NVIDIA-NeMo#4185. Keep the toy tokenizers and drop assertions
that only apply to their template strings.

Assisted-by: OpenAI Codex
Co-authored-by: Zhiyu Li <[email protected]>
Signed-off-by: Yuchen Wang <[email protected]>

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yuchenwang3 @Alvorecer721 for the finding and fix.

LGTM!

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia enabled auto-merge (squash) October 9, 2026 23:22
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Oct 10, 2026
@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added Run CICD CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Oct 10, 2026
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test b7ffd3d

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia merged commit c58ad32 into NVIDIA-NeMo:main Oct 11, 2026
94 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) community-request Run CICD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluation-path processors render a duplicated default system block (two chat-template calls)

4 participants