Repository navigation
fix(data): render evaluation chat prompts as complete conversations - #4193
Conversation
|
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: 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? Happy to review here as well. |
ce1332e to
551991a
Compare
|
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! |
|
@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 |
|
@aroshanghias-nvd Could you help route this to CI when you have a chance, with |
Assisted-by: OpenAI Codex Signed-off-by: Yuchen Wang <[email protected]> Co-authored-by: Alvorecer721 <[email protected]>
551991a to
6aa7d78
Compare
|
LGTM @yuchenwang3, sorry I was on holiday, and thanks @ZhiyuLi-Nvidia for taking care! |
|
/ok to test 6aa7d78 |
|
Suggestion: also run the new eval tests against the real chat templates from #4185 ( Verified in the nightly container with an HF token:
Extra runtime is ~15 s with a warm HF cache (one tokenizer load per model; ~0.02 s per case). The toy-only -@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) |
|
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
left a comment
There was a problem hiding this comment.
Thank you @yuchenwang3 @Alvorecer721 for the finding and fix.
LGTM!
|
/ok to test b7ffd3d |
What does this PR do?
Render the optional system prompt and user prompt together in
math_data_processorandmultichoice_qa_processor, matchingmath_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
lengthfield 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_filenow renders the system and user turns as one conversation.Validation
Current head:
b7ffd3d6d374c30329239aee59b8c94e3924c4ac, built on Zhiyu's rebase at6aa7d786.--confcutdir=tests/unit/datato exclude global Ray/GPU telemetry fixtures.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.--hf-gatedselects 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.6aa7d786and this patch (identical normalized JSON), including missing optional dependencies; the full project type-check is not clean in this local environment.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