vocab: every id the checkpoint's generation_config names as eos ends a generation

A checkpoint states the tokens a generation ends on in generation_config.json (eos_token_id, one
id or a list), and rad-convert already carries it into the container as
`generation.eos_token_id`. The vocabulary did not read it: it ended on eos, eot and a list of
known spellings. Gemma 4 names three, [1, 106, 50] -- <eos>, <turn|> and <|tool_response> -- and
the container's eos is only the first.

- <turn|> closes every turn. Without it a reply runs past its own end: a three-sentence answer
  stopped at max_tokens 400 after ~390 tokens of "---" lines instead of finish_reason "stop" at
  65 tokens.
- <|tool_response> is what the model writes after its calls, where it waits for the result.
  Greedy on the 31B QAT checkpoint (TP 2): after a finished call the next token is 50 with and
  without this change; without it generation goes on and writes the same call again until the
  token limit, with it the reply ends there (stop_type "eos", one token).

The engine reads `generation.eos_token_id` from the metadata before loading the vocabulary
(VocabBuild::eos_ids, not baked) and Vocab::load ends a generation on every id in range, logged
beside the spellings it adds.

text_test: ids in the list end a generation, an id naming no token is no id.
This commit is contained in:
keptn42 authored and sfjes committed 2026-10-10 08:08:44 -07:00
1 parent dbd4e164b3
commit 2c9ffc2888
4 files changed
+54

No files matched your search

+16
View File
@@ -621,6 +621,22 @@ int Vocab::load(VocabBuild b) {
RAD_INFO("vocab: end-of-generation also on %s (a control token the container declares "
"neither as eos nor eot; without this a turn ending on it runs on)",
added.c_str());
/* AND WHAT THE CHECKPOINT ITSELF NAMES. generation_config.json's eos_token_id is the
* model's own list of tokens a generation ends on, and the one that is not a guess:
* Gemma 4 names <|tool_response> there beside <eos> and <turn|>, because after its calls
* the model writes it and waits for the response -- a turn that runs past it answers
* its own call. Every id in range is honoured, as transformers honours them. */
std::string named;
for (int32_t id : b_.eos_ids) {
if (id < 0 || id >= (int32_t)b_.tokens.size()) continue;
if (std::find(eog_.begin(), eog_.end(), id) != eog_.end()) continue;
eog_.push_back(id);
named += (named.empty() ? "" : " ") + b_.tokens[id] + "=" + std::to_string(id);
}
if (!named.empty())
RAD_INFO("vocab: end-of-generation also on %s (named by the checkpoint's "
"generation_config.json)", named.c_str());
}
/* The encoder: the chain compiled and the tables flattened. A pattern the regex compiler