Skip to content

Commit 7a22c32

Browse files
ggerganovicex
authored andcommitted
convert : set "add bos" == True for Gemma 4 (ggml-org#21500)
* convert : set "add bos" == True for Gemma 4 * cont : handle old GGUFs
1 parent 8590cbf commit 7a22c32

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

convert_hf_to_gguf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7472,7 +7472,7 @@ def set_vocab(self):
74727472
special_vocab = gguf.SpecialVocab(self.dir_model, load_merges=True)
74737473
special_vocab.add_to_gguf(self.gguf_writer)
74747474
self.gguf_writer.add_add_space_prefix(False)
7475-
self.gguf_writer.add_add_bos_token(False) # already added via the chat template
7475+
self.gguf_writer.add_add_bos_token(True)
74767476

74777477
def set_gguf_parameters(self):
74787478
super().set_gguf_parameters()

src/llama-vocab.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,14 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
23252325
if (ml.get_key(LLM_KV_TOKENIZER_ADD_SEP, temp, false)) {
23262326
add_sep = temp;
23272327
}
2328+
2329+
// workaround for Gemma 4
2330+
// ref: https://github.com/ggml-org/llama.cpp/pull/21500
2331+
if (pre_type == LLAMA_VOCAB_PRE_TYPE_GEMMA4 && !add_bos) {
2332+
add_bos = true;
2333+
2334+
LLAMA_LOG_WARN("%s: override '%s' to 'true' for Gemma4\n", __func__, kv(LLM_KV_TOKENIZER_ADD_BOS).c_str());
2335+
}
23282336
}
23292337

23302338
// auto-detect special tokens by text

0 commit comments

Comments
 (0)