diff --git a/convert_hf_to_gguf.py b/convert_hf_to_gguf.py index 7ba6f6a742..c1737bb2c3 100755 --- a/convert_hf_to_gguf.py +++ b/convert_hf_to_gguf.py @@ -7472,7 +7472,7 @@ class Gemma4Model(Gemma3Model): special_vocab = gguf.SpecialVocab(self.dir_model, load_merges=True) special_vocab.add_to_gguf(self.gguf_writer) self.gguf_writer.add_add_space_prefix(False) - self.gguf_writer.add_add_bos_token(False) # already added via the chat template + self.gguf_writer.add_add_bos_token(True) def set_gguf_parameters(self): super().set_gguf_parameters() diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp index cb55b46b72..75dbaa91ee 100644 --- a/src/llama-vocab.cpp +++ b/src/llama-vocab.cpp @@ -2325,6 +2325,14 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) { if (ml.get_key(LLM_KV_TOKENIZER_ADD_SEP, temp, false)) { add_sep = temp; } + + // workaround for Gemma 4 + // ref: https://github.com/ggml-org/llama.cpp/pull/21500 + if (pre_type == LLAMA_VOCAB_PRE_TYPE_GEMMA4 && !add_bos) { + add_bos = true; + + LLAMA_LOG_WARN("%s: override '%s' to 'true' for Gemma4\n", __func__, kv(LLM_KV_TOKENIZER_ADD_BOS).c_str()); + } } // auto-detect special tokens by text