Skip to content

Commit 806446e

Browse files
committed
gpt-oss : clean up workarounds
1 parent 2ab97b6 commit 806446e

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

common/chat.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,16 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
13151315
data.prompt = prompt;
13161316
data.format = COMMON_CHAT_FORMAT_GPT_OSS;
13171317

1318+
// These special tokens are required to parse properly, so we include them
1319+
// even if parse_tool_calls is false.
1320+
data.preserved_tokens = {
1321+
"<|channel|>",
1322+
"<|constrain|>",
1323+
"<|message|>",
1324+
"<|start|>",
1325+
"<|end|>",
1326+
};
1327+
13181328
if (inputs.tools.is_array() && !inputs.tools.empty()) {
13191329
data.grammar_lazy = inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_REQUIRED;
13201330
data.grammar = build_grammar([&](const common_grammar_builder & builder) {
@@ -1373,14 +1383,6 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
13731383
COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN,
13741384
"<\\|start\\|>assistant to"
13751385
});
1376-
1377-
data.preserved_tokens = {
1378-
"<|channel|>",
1379-
"<|constrain|>",
1380-
"<|message|>",
1381-
"<|start|>",
1382-
"<|end|>",
1383-
};
13841386
});
13851387
}
13861388

src/llama-vocab.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,13 +2339,6 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
23392339
}
23402340
}
23412341

2342-
// @ngxson : quick hack for gpt-oss, always render these tokens
2343-
for (const auto & t : token_to_id) {
2344-
if (t.first == "<|channel|>" || t.first == "<|message|>" || t.first == "<|start|>" || t.first == "<|constrain|>") {
2345-
id_to_token[t.second].attr = LLAMA_TOKEN_ATTR_USER_DEFINED;
2346-
}
2347-
}
2348-
23492342
// sanity checks
23502343
if (special_eos_id != LLAMA_TOKEN_NULL && special_eog_ids.count(special_eos_id) == 0) {
23512344
special_eog_ids.insert(special_eos_id);
@@ -2388,7 +2381,6 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
23882381

23892382
if (has_return && has_call && has_end) {
23902383
special_eog_ids.erase(end_id);
2391-
id_to_token[end_id].attr = LLAMA_TOKEN_ATTR_USER_DEFINED;
23922384
LLAMA_LOG_WARN("%s: special_eog_ids contains both '<|return|>' and '<|call|>' tokens, removing '<|end|>' token from EOG list\n", __func__);
23932385
}
23942386
}

0 commit comments

Comments
 (0)