Skip to content

Commit a8d440c

Browse files
aldehirArberSephirotheca
authored andcommitted
vocab : remove </s> eog token if gemma4 (ggml-org#21492)
1 parent 01a79ce commit a8d440c

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/llama-vocab.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,8 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
25582558
|| t.first == "[EOS]" // Kimi-K2
25592559
|| t.first == "<|end_of_text|>"
25602560
|| t.first == "<end_of_utterance>" // smoldocling
2561-
|| t.first == "<turn|>" // gemma4
2561+
|| t.first == "<eos>" // gemma4
2562+
|| t.first == "<turn|>" // gemma4
25622563
|| t.first == "<|tool_response>" // gemma4
25632564
|| t.first == "<|end▁of▁sentence|>" // deepseek-ocr
25642565
) {
@@ -2645,6 +2646,33 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
26452646
LLAMA_LOG_WARN("%s: special_eog_ids contains both '<|return|>' and '<|call|>', or '<|calls|>' and '<|flush|>' tokens, removing '<|end|>' token from EOG list\n", __func__);
26462647
}
26472648
}
2649+
2650+
// workaround for gemma4 and paddleocr: do not include </s> as an eog token
2651+
{
2652+
bool has_tool_response = false;
2653+
bool has_s = false;
2654+
2655+
llama_token s_id = LLAMA_TOKEN_NULL;
2656+
2657+
for (auto tid : special_eog_ids) {
2658+
const auto & text = id_to_token[tid].text;
2659+
if (text == "<|tool_response>") {
2660+
has_tool_response = true;
2661+
} else if (text == "</s>") {
2662+
has_s = true;
2663+
s_id = tid;
2664+
}
2665+
}
2666+
2667+
if (has_tool_response && has_s) {
2668+
special_eog_ids.erase(s_id);
2669+
2670+
auto & attr = id_to_token[s_id].attr;
2671+
attr = LLAMA_TOKEN_ATTR_NORMAL;
2672+
2673+
LLAMA_LOG_WARN("%s: special_eog_ids contains '<|tool_response>', removing '</s>' token from EOG list\n", __func__);
2674+
}
2675+
}
26482676
}
26492677

26502678
// build special tokens cache

0 commit comments

Comments
 (0)