Add to_jinja() to PromptFormatter for programmatic chat template generation#15616
Closed
DongjiGao wants to merge 1 commit into
Closed
Conversation
…ration Add classmethod to_jinja() that generates Jinja2 chat templates matching the training prompt format. Ensures consistency between NeMo training and vLLM inference prompts. - Base PromptFormatter.to_jinja() raises NotImplementedError - QwenPromptFormatter.to_jinja(): ChatML format, multimodal support - NemotronNanoV3PromptFormatter.to_jinja(): auto empty system turn, enable_thinking toggle, multimodal support - 14 unit tests validating template output Signed-off-by: Dongji Gao <dongjig@nvidia.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
to_jinja()classmethod toPromptFormatterbase class and two subclasses for programmatic Jinja2 chat template generationPromptFormatter.to_jinja()raisesNotImplementedErrorto enforce subclass implementationChanges
nemo/collections/common/prompts/formatter.pyto_jinja(cls, audio_token, **kwargs) -> strclassmethod (raisesNotImplementedError)nemo/collections/common/prompts/qwen.pyQwenPromptFormatter.to_jinja(): ChatML format (<|im_start|>/<|im_end|>), multimodal audio support, no system rolenemo/collections/common/prompts/nemotron_nano_v3.pyNemotronNanoV3PromptFormatter.to_jinja(): auto-inserts empty system turn if missing,enable_thinkingtoggle for<think>tags, multimodal supporttests/collections/speechlm2/test_chat_template.pyTest plan
pytest tests/collections/speechlm2/test_chat_template.py— 14 tests passMade with Cursor