Skip to content

Commit 3997b47

Browse files
committed
gpt-oss : clean up workarounds
1 parent 3b57133 commit 3997b47

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
@@ -1339,6 +1339,16 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
13391339
data.prompt = prompt;
13401340
data.format = COMMON_CHAT_FORMAT_GPT_OSS;
13411341

1342+
// These special tokens are required to parse properly, so we include them
1343+
// even if parse_tool_calls is false.
1344+
data.preserved_tokens = {
1345+
"<|channel|>",
1346+
"<|constrain|>",
1347+
"<|message|>",
1348+
"<|start|>",
1349+
"<|end|>",
1350+
};
1351+
13421352
if (inputs.tools.is_array() && !inputs.tools.empty()) {
13431353
data.grammar_lazy = inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_REQUIRED;
13441354
data.grammar = build_grammar([&](const common_grammar_builder & builder) {
@@ -1397,14 +1407,6 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
13971407
COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN,
13981408
"<\\|start\\|>assistant to"
13991409
});
1400-
1401-
data.preserved_tokens = {
1402-
"<|channel|>",
1403-
"<|constrain|>",
1404-
"<|message|>",
1405-
"<|start|>",
1406-
"<|end|>",
1407-
};
14081410
});
14091411
}
14101412

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)