-
Notifications
You must be signed in to change notification settings - Fork 231
Remove default template and unify template loading #3722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mzegla
wants to merge
7
commits into
main
Choose a base branch
from
remove_default_template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−116
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b3fd085
init
mzegla b0f7b86
minor fixes
mzegla d1ca964
remove pre-checks in prepare_models scripts
mzegla eed6684
fix win prepare models script
mzegla c516f8f
keep dummy template as a file
mzegla dcc47b7
do not check dummy template
mzegla ff2925f
additional removals in llm template tests
mzegla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,15 +51,17 @@ | |||||||||||||||||||||||||||||||||||||
| namespace ovms { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| static const std::string CHAT_TEMPLATE_WARNING_MESSAGE = "Warning: Chat template has not been loaded properly. Servable will not respond to /chat/completions endpoint."; | ||||||||||||||||||||||||||||||||||||||
| static const std::string DEFAULT_CHAT_TEMPLATE = R"({% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] }}{% elif message['role'] == 'system' %}{{ '<|system|>\n' + message['content'] + eos_token }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% endif %}{% endfor %})"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void GenAiServableInitializer::loadChatTemplate(std::shared_ptr<GenAiServableProperties> properties, const std::string& chatTemplateDirectory) { | ||||||||||||||||||||||||||||||||||||||
| #if (PYTHON_DISABLE == 0) | ||||||||||||||||||||||||||||||||||||||
| ExtraGenerationInfo extraGenInfo = readExtraGenerationInfo(properties, chatTemplateDirectory); | ||||||||||||||||||||||||||||||||||||||
| loadPyTemplateProcessor(properties, extraGenInfo); | ||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||
| loadDefaultTemplateProcessorIfNeeded(properties); | ||||||||||||||||||||||||||||||||||||||
| if (properties->tokenizer.get_chat_template().empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_LOGGER_DEBUG(modelmanager_logger, CHAT_TEMPLATE_WARNING_MESSAGE); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||
| // In non-python build, GenAI handles chat template loading | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #if (PYTHON_DISABLE == 0) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,29 +125,37 @@ ExtraGenerationInfo GenAiServableInitializer::readExtraGenerationInfo(std::share | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void GenAiServableInitializer::loadPyTemplateProcessor(std::shared_ptr<GenAiServableProperties> properties, const ExtraGenerationInfo& extraGenInfo) { | ||||||||||||||||||||||||||||||||||||||
| // GGUF models specific validation | ||||||||||||||||||||||||||||||||||||||
| if (extraGenInfo.isGgufModel) { | ||||||||||||||||||||||||||||||||||||||
| bool errorFound = false; | ||||||||||||||||||||||||||||||||||||||
| if (extraGenInfo.eosTokenFromTokenizer.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("Tokenizer eos token not found in tokenizer nor in vocabulary but required for GGUF models."); | ||||||||||||||||||||||||||||||||||||||
| errorFound = true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (extraGenInfo.bosTokenFromTokenizer.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("Tokenizer bos token not found in tokenizer nor in vocabulary but required for GGUF models."); | ||||||||||||||||||||||||||||||||||||||
| errorFound = true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (extraGenInfo.chatTemplateFromTokenizer.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("Tokenizer chat template not found in tokenizer but required for GGUF models."); | ||||||||||||||||||||||||||||||||||||||
| errorFound = true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (errorFound) | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| // At this point tokenizer cannot be uninitialized as we need to access its methods for prepare for chat template processing | ||||||||||||||||||||||||||||||||||||||
| if (properties->tokenizer == ov::genai::Tokenizer()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_LOGGER_ERROR(modelmanager_logger, "Tokenizer is not initialized. Cannot load chat template processor."); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| std::string chatTemplate = properties->tokenizer.get_original_chat_template(); | ||||||||||||||||||||||||||||||||||||||
| std::string bosToken = properties->tokenizer.get_bos_token(); | ||||||||||||||||||||||||||||||||||||||
| std::string eosToken = properties->tokenizer.get_eos_token(); | ||||||||||||||||||||||||||||||||||||||
| if (bosToken.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("BOS token was not found in model files."); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (eosToken.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("EOS token was not found in model files."); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (chatTemplate.empty()) { | ||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("Chat template was not found in model files."); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+137
to
+145
|
||||||||||||||||||||||||||||||||||||||
| SPDLOG_ERROR("BOS token was not found in model files."); | |
| return; | |
| } | |
| if (eosToken.empty()) { | |
| SPDLOG_ERROR("EOS token was not found in model files."); | |
| return; | |
| } | |
| if (chatTemplate.empty()) { | |
| SPDLOG_ERROR("Chat template was not found in model files."); | |
| SPDLOG_ERROR("BOS token was not found in model files. {}", CHAT_TEMPLATE_WARNING_MESSAGE); | |
| return; | |
| } | |
| if (eosToken.empty()) { | |
| SPDLOG_ERROR("EOS token was not found in model files. {}", CHAT_TEMPLATE_WARNING_MESSAGE); | |
| return; | |
| } | |
| if (chatTemplate.empty()) { | |
| SPDLOG_ERROR("Chat template was not found in model files. {}", CHAT_TEMPLATE_WARNING_MESSAGE); |
mzegla marked this conversation as resolved.
Show resolved
Hide resolved
mzegla marked this conversation as resolved.
Show resolved
Hide resolved
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] }}{% elif message['role'] == 'system' %}{{ '<|system|>\n' + message['content'] + eos_token }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% endif %}{% endfor %} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Comparing tokenizer equality against a default-constructed instance may not reliably detect uninitialized state. Consider adding an explicit
is_initialized()oris_valid()method to the Tokenizer class, or check for null/empty internal state instead.