convert: --chat-template, bake a template a release ships none of

DeepSeek's release carries no chat_template.jinja and its tokenizer_config.json
names none, so an HF-direct container answers /v1/chat/completions with 501
unless the serve passes --override-chat-template. The converter now takes the
template itself and bakes it into the vocab section, overriding whatever the
checkpoint carried or lacked. Trailing newlines are stripped as for a sibling
chat_template.jinja, and an unreadable or empty file is refused rather than
skipped. Both paths are covered: text_test reads the file, convert_test
converts the tiny checkpoint and reads the template back out of the container.

(cherry picked from commit 6381f61794cd61d1f86925fd23ea61e1b1544dfe)
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-28 13:50:16 +01:00
1 parent 73bee2dcc2
commit b64b0de7de
5 files changed
+90 -1

No files matched your search

+21
View File
@@ -638,6 +638,27 @@ void read_config(const std::string& dir, VocabBuild& out) {
} /* namespace */
int read_chat_template_path(const char* path, VocabBuild& out) {
if (!path) return RAD_E_INVAL;
std::ifstream f(path);
if (!f) {
RAD_ERR("tokenizer: cannot read chat template %s", path);
return RAD_E_IO;
}
std::ostringstream ss;
ss << f.rdbuf();
std::string t = ss.str();
while (!t.empty() && (t.back() == '\n' || t.back() == '\r')) t.pop_back();
if (t.empty()) {
RAD_ERR("tokenizer: chat template %s is empty", path);
return RAD_E_IO;
}
RAD_INFO("tokenizer: chat template from %s (%zu bytes), overriding the checkpoint's",
path, t.size());
out.chat_template = std::move(t);
return RAD_OK;
}
/* ================================================================== parse_tokenizer_json */
namespace {