-
Notifications
You must be signed in to change notification settings - Fork 240
Chat template from chat_template.jinja for all possible paths #4055
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,21 @@ Status ContinuousBatchingServableInitializer::initialize(std::shared_ptr<GenAiSe | |
| properties->schedulerConfig, properties->device, | ||
| properties->pluginConfig, properties->tokenizerPluginConfig); | ||
| properties->tokenizer = properties->pipeline->get_tokenizer(); | ||
|
|
||
| // Override chat template from chat_template.jinja file if present in model directory | ||
| std::filesystem::path chatTemplateJinjaPath = std::filesystem::path(parsedModelsPath) / "chat_template.jinja"; | ||
| if (std::filesystem::exists(chatTemplateJinjaPath)) { | ||
| std::ifstream chatTemplateFile(chatTemplateJinjaPath); | ||
| if (chatTemplateFile.is_open()) { | ||
| std::string chatTemplateContent((std::istreambuf_iterator<char>(chatTemplateFile)), | ||
| std::istreambuf_iterator<char>()); | ||
| if (!chatTemplateContent.empty()) { | ||
|
Comment on lines
+218
to
+221
|
||
| properties->tokenizer.set_chat_template(chatTemplateContent); | ||
| } | ||
| } else { | ||
| SPDLOG_LOGGER_WARN(llm_calculator_logger, "Failed to open chat template file: {}", chatTemplateJinjaPath.string()); | ||
| } | ||
| } | ||
| } catch (const std::exception& e) { | ||
| SPDLOG_ERROR("Error during llm node initialization for models_path: {} exception: {}", parsedModelsPath, e.what()); | ||
| return StatusCode::LLM_NODE_RESOURCE_STATE_INITIALIZATION_FAILED; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||||||||||||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||||||||||||||||||
| //***************************************************************************** | ||||||||||||||||||||||||||||||||||
| #include <fstream> | ||||||||||||||||||||||||||||||||||
| #include <memory> | ||||||||||||||||||||||||||||||||||
| #include <stdexcept> | ||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||
|
|
@@ -100,6 +101,22 @@ Status LegacyServableInitializer::initialize(std::shared_ptr<GenAiServable>& ser | |||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| properties->pipeline = std::make_shared<ov::genai::LLMPipeline>(parsedModelsPath, properties->device, properties->pluginConfig); | ||||||||||||||||||||||||||||||||||
| properties->tokenizer = properties->pipeline->get_tokenizer(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Override chat template from chat_template.jinja file if present in model directory | ||||||||||||||||||||||||||||||||||
| std::filesystem::path chatTemplateJinjaPath = std::filesystem::path(parsedModelsPath) / "chat_template.jinja"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| std::filesystem::path chatTemplateJinjaPath = std::filesystem::path(parsedModelsPath) / "chat_template.jinja"; | |
| std::filesystem::path modelsPathFs(parsedModelsPath); | |
| std::filesystem::path chatTemplateDir = | |
| std::filesystem::is_directory(modelsPathFs) ? modelsPathFs : modelsPathFs.parent_path(); | |
| std::filesystem::path chatTemplateJinjaPath = chatTemplateDir / "chat_template.jinja"; |
Copilot
AI
Mar 12, 2026
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.
This block uses std::istreambuf_iterator (and std::filesystem::path), but the file doesn’t include the corresponding standard headers (<iterator> / <filesystem>). Please add the missing includes to avoid relying on transitive headers (can break on different libstdc++/libc++ versions).
Copilot
AI
Mar 12, 2026
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.
The same “read chat_template.jinja and set tokenizer chat template” logic is duplicated across multiple servable initializers in this PR. To prevent drift (e.g., different logging/edge-case handling), consider extracting it into a shared helper (e.g., on GenAiServableInitializer).
| // Override chat template from chat_template.jinja file if present in model directory | |
| std::filesystem::path chatTemplateJinjaPath = std::filesystem::path(parsedModelsPath) / "chat_template.jinja"; | |
| if (std::filesystem::exists(chatTemplateJinjaPath)) { | |
| std::ifstream chatTemplateFile(chatTemplateJinjaPath); | |
| if (chatTemplateFile.is_open()) { | |
| std::string chatTemplateContent((std::istreambuf_iterator<char>(chatTemplateFile)), | |
| std::istreambuf_iterator<char>()); | |
| if (!chatTemplateContent.empty()) { | |
| properties->tokenizer.set_chat_template(chatTemplateContent); | |
| SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Loaded custom chat template from: {}", chatTemplateJinjaPath.string()); | |
| } | |
| } else { | |
| SPDLOG_LOGGER_WARN(llm_calculator_logger, "Failed to open chat template file: {}", chatTemplateJinjaPath.string()); | |
| } | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //***************************************************************************** | ||
| #include <fstream> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
@@ -84,6 +85,22 @@ Status VisualLanguageModelLegacyServableInitializer::initialize(std::shared_ptr< | |
| try { | ||
| properties->pipeline = std::make_shared<ov::genai::VLMPipeline>(parsedModelsPath, properties->device, properties->pluginConfig); | ||
| properties->tokenizer = properties->pipeline->get_tokenizer(); | ||
|
|
||
| // Override chat template from chat_template.jinja file if present in model directory | ||
| std::filesystem::path chatTemplateJinjaPath = std::filesystem::path(parsedModelsPath) / "chat_template.jinja"; | ||
| if (std::filesystem::exists(chatTemplateJinjaPath)) { | ||
| std::ifstream chatTemplateFile(chatTemplateJinjaPath); | ||
| if (chatTemplateFile.is_open()) { | ||
| std::string chatTemplateContent((std::istreambuf_iterator<char>(chatTemplateFile)), | ||
| std::istreambuf_iterator<char>()); | ||
| if (!chatTemplateContent.empty()) { | ||
|
Comment on lines
+90
to
+96
|
||
| properties->tokenizer.set_chat_template(chatTemplateContent); | ||
| SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Loaded custom chat template from: {}", chatTemplateJinjaPath.string()); | ||
| } | ||
| } else { | ||
| SPDLOG_LOGGER_WARN(llm_calculator_logger, "Failed to open chat template file: {}", chatTemplateJinjaPath.string()); | ||
| } | ||
| } | ||
| } catch (const std::exception& e) { | ||
| SPDLOG_ERROR("Error during llm node initialization for models_path: {} exception: {}", parsedModelsPath, e.what()); | ||
| return StatusCode::LLM_NODE_RESOURCE_STATE_INITIALIZATION_FAILED; | ||
|
|
||
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.
chatTemplateJinjaPathis derived asparsedModelsPath / "chat_template.jinja". SinceparseModelsPath()accepts.gguffiles as a validmodels_path, this won’t locate a template stored next to a GGUF file (it will incorrectly search under<file>.gguf/chat_template.jinja). Consider basing the search directory onparsedModelsPathif it’s a directory, otherwise useparent_path().