feat: Add DeepSeek R1 and distilled model chat format support#1
Open
feat: Add DeepSeek R1 and distilled model chat format support#1
Conversation
- Update llama.cpp submodule to latest (b8184) for full DeepSeek R1/V2/V3 architecture support - Add 'deepseek-r1' chat format with correct special tokens (<|User|>, <|Assistant|>, <|begin▁of▁sentence|>, <|end▁of▁sentence|>) - Add 'deepseek-r1-distill-qwen' and 'deepseek-r1-distill-llama' chat format aliases for distilled model variants - Add DEEPSEEK_R1_CHAT_TEMPLATE constant from official HuggingFace tokenizer config - Update guess_chat_format_from_gguf_metadata() to auto-detect DeepSeek R1 models via template matching and heuristic token detection - Handle </think> reasoning content stripping for multi-turn conversations - Bump version to 0.3.17 Closes abetlen#1952
The format_deepseek_r1 function already includes the BOS token (<|begin▁of▁sentence|>) in the formatted prompt, but was not setting added_special=True in the ChatFormatterResponse. This caused chat_formatter_to_chat_completion_handler to pass add_bos=True to the tokenizer, resulting in a duplicate BOS token. Also adds comprehensive tests for: - Single-turn and multi-turn conversations - System message handling - </think> reasoning content stripping - Distilled model aliases (qwen/llama) - Auto-detection via exact match and heuristic
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
Add native chat format support for DeepSeek R1 and its distilled model variants (Qwen-based and Llama-based), including auto-detection from GGUF metadata.
Closes abetlen#1952
Changes
Chat Format (
llama_chat_format.py)deepseek-r1chat format with correct special tokens (<|User|>,<|Assistant|>,<|begin▁of▁sentence|>,<|end▁of▁sentence|>)deepseek-r1-distill-qwenanddeepseek-r1-distill-llamachat format aliases for distilled model variantsDEEPSEEK_R1_CHAT_TEMPLATEconstant sourced from the official HuggingFace tokenizer config</think>reasoning content stripping for multi-turn conversations so chain-of-thought tokens don't leak into contextadded_special=TrueinChatFormatterResponseto prevent double BOS token insertionAuto-Detection (
guess_chat_format_from_gguf_metadata)<|User|>and<|Assistant|>tokens in the templateSubmodule Update
vendor/llama.cppsubmodule to latest (3191462) for full DeepSeek R1/V2/V3 architecture supportVersion Bump
0.3.17Tests (
test_llama_chat_format.py)</think>reasoning content strippingTesting
Co-Authored-By: Oz oz-agent@warp.dev