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

+24
View File
@@ -12,6 +12,7 @@
#include "format/encoding.h"
#include "format/radfile.h"
#include "gen_config.h"
#include "text/tokenizer.h"
#include <sys/stat.h>
@@ -967,4 +968,27 @@ TEST(an_fp8_kv_cache_declares) {
CHECK(exists(d / "k.rad"));
}
/* --chat-template bakes a template into the container's vocab section, for a release that ships
* none (DeepSeek's). Without the flag the container carries what the checkpoint carried. A missing
* file is refused, not silently skipped. */
TEST(chat_template_flag_bakes_the_template) {
World& w = world();
REQUIRE(w.ok);
tiny::TempDir d("convert_ct");
const std::string tmpl = d / "chat_template.jinja";
REQUIRE(tiny::write_text(tmpl, "{%- raw %}{{ messages }}{%- endraw %}\n\n"));
std::string log;
REQUIRE_EQ(convert(w.ckpt, { "-o", d / "with.rad", "--recipe", w.recipe,
"--chat-template", tmpl }, &log), 0);
RadFile f;
REQUIRE_EQ(f.open((d / "with.rad").c_str()), RAD_OK);
VocabBuild vb;
REQUIRE_EQ(vocab_deserialize(f.base(), (uint64_t)f.size(), f.vocab().h, vb), RAD_OK);
CHECK_EQ(vb.chat_template, std::string("{%- raw %}{{ messages }}{%- endraw %}"));
std::string bad;
CHECK_EQ(convert(w.ckpt, { "-o", d / "bad.rad", "--recipe", w.recipe,
"--chat-template", d / "absent.jinja" }, &bad), 1);
}
RAD_TEST_MAIN()