[DSv4] add jinja chat template support#1153
Conversation
|
Thanks for the contribution! For vLLM & SGLang, please ensure that your recipes is similar to the official vLLM recipes and/or the SGLang cookbook If it is not, please create a PR first before we can merge your PR into the master branch. Let's ensure that the documentation is first class such that the entire ML community can benefit from your hard work! Thank you PR authors are responsible for ensuring that after merging, all GitHub Action jobs fully pass. A lot of the time, failures are just flakes and simply re-running the failed jobs will fix it. If re-running failed jobs is attempted, PR authors are responsible for ensuring it passes. See GitHub's docs on re-running failed jobs: https://docs.github.com/en/actions/how-tos/manage-workflow-runs/re-run-workflows-and-jobs#re-running-failed-jobs-in-a-workflow As a rule of thumb, generally, PR authors should request a review & get a PR approval from the respective companies' CODEOWNERS before requesting a review from core maintainers. If additional help is needed, PR authors can reach out to core maintainers over Slack. |
|
@claude please generate a PR description |
|
Claude finished @kedarpotdar-nv's task in 1m 0s —— View job PR Description Generated
PR description has been updated with a summary of the changes, including details on the new |
|
@claude please review code |
|
Claude finished @kedarpotdar-nv's task in 1m 25s —— View job Code Review: [DSv4] Jinja Chat Template Support
SummaryThis PR adds a Below are the issues and suggestions, ordered by severity. Issues1. Bare
|
Summary
Adds a self-contained Jinja chat template encoder for DeepSeek-V4 (
encoding_dsv4.py) and wires it into the benchmark serving pipeline as an alternative to the tokenizer's built-in chat template.Changes
utils/bench_serving/encoding_dsv4.py(new, ~744 lines): Standalone DeepSeek-V4 encoding/decoding module that implements:<bos><User>...<Assistant><think>framing)"chat"vs"thinking") with configurable reasoning effortutils/bench_serving/benchmark_serving.py: Integrates the new encoder:--dsv4CLI flag (under a newDeepSeek-V4 chat template optionsargument group)_apply_chat_template()helper that dispatches to eitherencoding_dsv4.encode_messagesor the tokenizer's built-in jinja templatedsv4flag throughsample_random_requestsand its multiprocessing worker chunks--dsv4requires--use-chat-templatebenchmarks/benchmark_lib.sh: Adds--dsv4as an optional flag torun_benchmark_serving():--use-chat-templatewhen--dsv4is passedMotivation
The HuggingFace tokenizer's built-in Jinja chat template may not perfectly match the prompt format DeepSeek-V4 expects (especially for thinking mode and tool-calling scenarios). This PR provides a faithful, self-contained encoder that reproduces the exact prompt structure the model was trained with, ensuring accurate benchmarking results.