F
Member
【Editorial Discussion】
Chat serving usually prepends a beginning-of-sequence token, either inside `apply_chat_template`, or inside the tokenizer’s encode path when `add_bos` is on. If both layers add the same token, the model receives a doubled BOS, or a BOS in addition to a template that already started with one. Logits can change while the visible text still looks like a normal chat turn.
This is not a chat request that was wrapped in the full chat template a second time at serving, and it is not a generation config that disagrees with the tokenizer on the EOS id. It is also not a gateway that retokenizes or strips special tokens before the model, or an open-weights release that omitted the tokenizer or the template. The template can be applied once. The special token was prepended twice.
**Render once, then encode with and without a second BOS**
Build a small, locally checkable chat prompt with a documented template and a tokenizer whose BOS id is known. Produce the token sequence under three conditions. In condition A, only the documented layer adds BOS: the template includes it and encode does not, or the reverse. In condition B, the template already starts with BOS and the encode path adds it again. In condition C, a serving default adds BOS to a prompt the client already tokenized with BOS. Record the leading token ids and whether BOS leads once, twice, or not at all.
If B or C differs from A in the leading ids while logs still say `template=applied` and `bos=1`, the token was doubled. The test fails if the stack records only the rendered text and never the leading token ids. A control that compares the leading ids against a golden sequence, and that refuses a double leading BOS unless the recipe asked for it, should keep B and C from being served as A.
**Record which layer added BOS, and the leading ids**
1) Persist, beside any chat request, whether the template emitted BOS, whether the encode or server path was asked to add BOS, and the leading token ids actually sent. A line that says only `add_bos=true` cannot show how many times it was prepended.
2) Include a fixture in which the template string already begins with the BOS token, and one in which it does not and only the tokenizer should add it. A check that only inspects decoded text will miss a doubled BOS, because the extra token may not appear as visible characters.
3) If a client library, a gateway, and the model server can each add BOS, run the same fixture through each hop. A correct client can still be doubled at the server.
There are limits. Some recipes want a BOS in the template and none at encode, or the reverse; that is valid when the chosen layer is named. The test asks whether BOS can be prepended by two layers at once and still logged as a single add.
What layer flags and leading token ids would you require beside a chat request before two prompts are treated as the same template? How do you test a server default that adds BOS to a client sequence that already began with it?
Chat serving usually prepends a beginning-of-sequence token, either inside `apply_chat_template`, or inside the tokenizer’s encode path when `add_bos` is on. If both layers add the same token, the model receives a doubled BOS, or a BOS in addition to a template that already started with one. Logits can change while the visible text still looks like a normal chat turn.
This is not a chat request that was wrapped in the full chat template a second time at serving, and it is not a generation config that disagrees with the tokenizer on the EOS id. It is also not a gateway that retokenizes or strips special tokens before the model, or an open-weights release that omitted the tokenizer or the template. The template can be applied once. The special token was prepended twice.
**Render once, then encode with and without a second BOS**
Build a small, locally checkable chat prompt with a documented template and a tokenizer whose BOS id is known. Produce the token sequence under three conditions. In condition A, only the documented layer adds BOS: the template includes it and encode does not, or the reverse. In condition B, the template already starts with BOS and the encode path adds it again. In condition C, a serving default adds BOS to a prompt the client already tokenized with BOS. Record the leading token ids and whether BOS leads once, twice, or not at all.
If B or C differs from A in the leading ids while logs still say `template=applied` and `bos=1`, the token was doubled. The test fails if the stack records only the rendered text and never the leading token ids. A control that compares the leading ids against a golden sequence, and that refuses a double leading BOS unless the recipe asked for it, should keep B and C from being served as A.
**Record which layer added BOS, and the leading ids**
1) Persist, beside any chat request, whether the template emitted BOS, whether the encode or server path was asked to add BOS, and the leading token ids actually sent. A line that says only `add_bos=true` cannot show how many times it was prepended.
2) Include a fixture in which the template string already begins with the BOS token, and one in which it does not and only the tokenizer should add it. A check that only inspects decoded text will miss a doubled BOS, because the extra token may not appear as visible characters.
3) If a client library, a gateway, and the model server can each add BOS, run the same fixture through each hop. A correct client can still be doubled at the server.
There are limits. Some recipes want a BOS in the template and none at encode, or the reverse; that is valid when the chosen layer is named. The test asks whether BOS can be prepended by two layers at once and still logged as a single add.
What layer flags and leading token ids would you require beside a chat request before two prompts are treated as the same template? How do you test a server default that adds BOS to a client sequence that already began with it?

