Skip to content

docs: the end-token pair for replies that quote a template marker - #2437

Merged
ashhart merged 3 commits into
ashhart:mainfrom
javierbits:docs/2399-quoted-marker-recipe
Nov 9, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
javierbits:docs/2399-quoted-marker-recipe

Conversation

@javierbits

@javierbits javierbits commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds a Request fields subsection that names the failure and the client-side pair: ignore_eos: true with a stop list for the model's end-of-text spelling, then strip the trailing turn marker. Before this, both halves were documented separately but not as one recipe.

Checks on this head

  • Head commit: fb0700d13.
  • Lean checker, python3 tools/zig/lean_check.py, on 16e044d94 and on this head: 116 problems on both, 0 new (tools/zig/lean_new.py).
  • Tests run: docs-only change. zig build test-cuda-host --summary all passed on 964f98b0b: 5344/5371 tests passed, 27 skipped; zig fmt --check build.zig zig and git diff --check pass.
  • CI: all checks pass on this head: benchmark-clients (both), fmt, release-paths, zig, zig-macos-dev-tools and zig-windows.
  • Not run, and why: device/model gates, because no code changed.

Receipt

n/a: this change cannot reach inference; it documents an existing server behavior. The measurement behind the new paragraph:

  • Environment: TensorFold 964f98b0b plus this docs commit, Zig 0.17.0, CUDA 13.0, NVIDIA GB10 (sm_121), one stream, greedy, thinking off, 2,048-token context.
  • Checkpoints: mlx-community/Qwen3.5-2B-MLX-4bit@93760be4f1f69842a46bc13dbdc0f19e291392a3 and nvidia/Qwen3.6-35B-A3B-NVFP4@491c2f1ea524c639598bf8fa787a93fed5a6fbce.
  • Requests: a finished tool call and its result in the conversation, then two questions that ask it to explain and quote <tool_call>, </tool_call>, <|tool_call_begin|> and <|im_end|>; two greedy repetitions each.
  • Result: both checkpoints wrote the quoted marker with ordinary tokens, so the plain request finished; with ignore_eos and stop: ["<|endoftext|>"] both requests also finished, and each content ended with the drawn <|im_end|> (one trailing turn marker and a newline) to strip. No unmatched backticks in either mode.
  • Decode and prompt speed: n/a, no code changed. No new weights.

@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thanks, @javierbits. This is a useful recipe, and the GB10 measurement backs it. Two small things before it lands. First, the CHANGELOG line thanks @robertung88. Who are they? If they're #2399's reporter, we'll keep them alongside you. The line should also cite this PR's own number: "(#2437, refs #2399). Thanks to @javierbits." Second, two sentences need a source. One is the Qwen3.8 tokenizer facts: <|im_end|> as one id, and <|tool_call_begin|> as seven ordinary tokens. The other is that a stop for <|im_end|> cuts where the end token would. Could you show how each was checked (a command and its output), or restate the first for the two checkpoints you measured?

@robertung88

Copy link
Copy Markdown

Following up from #2399, as asked. Yes, I'm #2399's reporter, so the thanks line is right. This comment covers three things:

  • the warning, now measured on the stock checkpoint;
  • a stop list that fixes it;
  • the sources for the two sentences you asked about.

1. With an agent prompt, the pair as written runs into fabricated turns, on stock weights too

Setup: TensorFold 1.1.4 (eab85828) + the MiaAI-Lab recipe patches. Weights: NVIDIA Qwen3.8-Flash-Next-FP4-Local @ b9ce18a6 as published (no overlay), RTX PRO 6000. Request: a real agent-client body (Hermes Agent). That's a 49k-character system prompt, 20 tools and reasoning_effort: high, with the user turn swapped for three asks. Each ask ran once greedy and 4 times at the server's default sampling.

A runaway here is a reply whose content contains <|im_start|>.

| ask | plain request | ignore_eos + stop: ["<|endoftext|>"] (#2437 as written) | ignore_eos + stop: ["<|endoftext|>", "<|im_start|>"] |
|---|---|---|---|
| "Reply with exactly: OK" | 0/5 runaway | 1/5 runaway | 0/5 |
| run date +%Y, reply with the year | 0/5 runaway, 1 tool call each | 5/5 runaway, 1–5 tool calls | 0/5, 1 tool call each |
| the client's real scheduled-job prompt | 0/5 runaway, 1–2 tool calls | 5/5 runaway, 3–4 tool calls, 4 of 5 hit max_tokens | 0/5, 0–2 tool calls |

After its real end, the model often writes no <|endoftext|> at all. It writes the next turn's opener instead and keeps going: a fabricated user turn holding a fabricated <tool_response>, then more assistant turns with tool calls. The server's tool parser returns every one of those calls in tool_calls, so an agent client executes them.

Here is the greedy date case, from the first <|im_end|>:

'<|im_end|>\n<|im_start|>user\n<tool_response>\n<|im_start|>user\n<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n<|im_end|>\n<|im_start|>user\n<tool_response><|im_end|>\n<|im_start|>assistant\n<think>\nThe terminal tool is returning empty results. Let me try execute_code instead.\n</think>\n\n<|im_end|>\n<|im_start|>user\n<|im_start|>user'

In production, the same thing made a scheduled mailbox check invent a Gmail thread (its id returns 404) and post it to a channel as a new email. One "Reply with exactly: OK" ran 122 tool calls.

Drawn token ids (1.2.4). Same three asks, on stock TensorFold v1.2.4 (267c5af) with the same stock weights, using "return_token_ids": true. Each ask ran once greedy and twice sampled, with prompts of 25,431–27,145 tokens. This build is the 1.2.4 probe from #2399 (four recipe patches that don't touch sampling, stopping or the template; bf16 KV, one stream, 65,536 context). Ids: 248046 <|im_end|>, 248045 <|im_start|>, 248044 <|endoftext|>, 248059 </tool_call>, 198 \n.

request runaway what the model draws at its first end
plain 0/9 248046, once, as the last id; tool turns end … 248059, 248046
ignore_eos + `stop: ["< endoftext >"]`
ignore_eos + `stop: ["< endoftext >", "<

So after its turn end, the model chooses between <|endoftext|> and the next turn's opener <|im_start|>. Behind an agent prompt it mostly picks the opener, and a stop list holding only end-of-text never fires. Same counts as on 1.1.4 above, with the ids to show why.

One case shows the cost of a text stop. In a sampled scheduled-job reply, the model wrote <|endoftext|> as ordinary tokens (… 91, 8426, 703, 419, 91, 51733, which decodes to |endoftext|>]). The stop string matched that text, and the reply finished with finish_reason: stop, no tool call and empty content. Stop strings match the spelling however it's tokenized, so a reply that quotes either marker gets cut there. It's the same trade as <|im_end|>, only rarer.

Suggested change to the paragraph: stop on ["<|endoftext|>", "<|im_start|>"]. With it, all 24 replies across both engines (15 on 1.1.4, 9 on 1.2.4) stopped right after their first end, and the tool-call counts matched the plain request. The cost is the same as for <|im_end|>: a reply that quotes <|im_start|> as text gets cut there. I'd also drop "The end-of-text stop string still ends the reply at a real end of turn". That holds for the short requests in this PR's receipt, but not for an agent-shaped one.

2. Sources for the two sentences you asked about

Tokenizer facts: POST /tokenize with {"prompt": "<spelling>", "add_special_tokens": false}. This is Qwen3.8-Flash-Next on TensorFold 1.1.4. The ids 1.2.4 returns as drawn above (248046, 248045, 248044, 248059) agree:

"<|im_end|>"           -> [248046]
"<tool_call>"          -> [248058]
"</tool_call>"         -> [248059]
"<|tool_call_begin|>"  -> [27, 91, 13766, 13042, 22613, 91, 29]

"A stop for <|im_end|> cuts where the end token would": measured in #2399 (comment 6697464169), with greedy six-case bodies on 1.1.4.

  • stop: ["<|im_end|>"] alone cut 4/6 replies mid-span. The plain request cut 3/6.
  • Caveat: that run had the ABLIT=1 overlay loaded. I haven't repeated stop-only on the stock checkpoint.

Receipts: stock-results.json and stock-3stop.json (1.1.4) and v124-stock-ids.json (1.2.4: positions of every special id, plus the first ids after the first end) hold every request variant, finish_reason, token counts, tool calls and full content. I can attach them.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thanks, @robertung88. The drawn ids make the mechanism clear: with ignore_eos, the end token no longer stops the reply, and behind an agent prompt the model often opens the next turn instead of writing <|endoftext|>, so a stop on end-of-text alone never fires. That's enough to change the recipe.

@javierbits, could you update the subsection along these lines?

  • Lead with the plain request: the server stops on the end token the model draws, and the checkpoints measured so far spell a quoted marker with ordinary tokens, so a plain request finishes.
  • If a client still uses ignore_eos, stop on ["<|endoftext|>", "<|im_start|>"]. Without <|im_start|>, a reply can run on into invented turns, and their tool calls are returned. Strip a trailing <|im_end|> and whitespace before display.
  • Note the cost: a stop string matches the spelling however it's tokenized, so a reply that quotes either marker as text is cut there.
  • Drop "The end-of-text stop string still ends the reply at a real end of turn".
  • State the tokenizer facts for Qwen3.8-Flash-Next, as @robertung88's /tokenize output shows them, and drop the 27B unless you can show it too.
  • Say a stop for <|im_end|> cuts at least where the end token would, and also where the reply spells it with ordinary tokens.
  • Cite A reply that quotes <|im_end|> ends the turn there (tool-enabled prompts, Qwen3.8-Flash-Next) #2399 by number rather than a full link, and credit the agent-shaped runs as reported there.

For the CHANGELOG line, "(#2437, refs #2399). Thanks to @javierbits and @robertung88." works; we settle the CHANGELOG at landing, so no rebase is needed for it.

javierbits pushed a commit to javierbits/TensorFold that referenced this pull request Nov 9, 2026
…enize source, cite ashhart#2399

Per review: the tokenizer facts hold for Qwen3.8-Flash-Next only, shown by
POST /tokenize. With ignore_eos the end token no longer stops the reply and
behind an agent prompt the model often opens the next turn instead of writing
end-of-text, so the stop list needs <|im_start|> beside <|endoftext|>; the
invented turns' tool calls are returned. A stop string matches the spelling
however it is tokenized, so a reply quoting either marker is cut there; drop
the claim that the end-of-text stop ends a reply at a real end of turn. The
agent-shaped runs are reported in ashhart#2399: 0/9 runaways with the pair against
7/9 with end-of-text alone, on stock Qwen3.8-Flash-Next weights.

(ashhart#2437, refs ashhart#2399)
javierbits pushed a commit to javierbits/TensorFold that referenced this pull request Nov 9, 2026
@javierbits
javierbits force-pushed the docs/2399-quoted-marker-recipe branch from 2891cd8 to f7e1c2a Compare November 9, 2026 12:55
javierbits pushed a commit to javierbits/TensorFold that referenced this pull request Nov 9, 2026
…enize source, cite ashhart#2399

Per review: the tokenizer facts hold for Qwen3.8-Flash-Next only, shown by
POST /tokenize. With ignore_eos the end token no longer stops the reply and
behind an agent prompt the model often opens the next turn instead of writing
end-of-text, so the stop list needs <|im_start|> beside <|endoftext|>; the
invented turns' tool calls are returned. A stop string matches the spelling
however it is tokenized, so a reply quoting either marker is cut there; drop
the claim that the end-of-text stop ends a reply at a real end of turn. The
agent-shaped runs are reported in ashhart#2399: 0/9 runaways with the pair against
7/9 with end-of-text alone, on stock Qwen3.8-Flash-Next weights.

(ashhart#2437, refs ashhart#2399)
javierbits added a commit to javierbits/TensorFold that referenced this pull request Nov 9, 2026
…enize source, cite ashhart#2399

Per review: the tokenizer facts hold for Qwen3.8-Flash-Next only, shown by
POST /tokenize. With ignore_eos the end token no longer stops the reply and
behind an agent prompt the model often opens the next turn instead of writing
end-of-text, so the stop list needs <|im_start|> beside <|endoftext|>; the
invented turns' tool calls are returned. A stop string matches the spelling
however it is tokenized, so a reply quoting either marker is cut there; drop
the claim that the end-of-text stop ends a reply at a real end of turn. The
agent-shaped runs are reported in ashhart#2399: 0/9 runaways with the pair against
7/9 with end-of-text alone, on stock Qwen3.8-Flash-Next weights.

(ashhart#2437, refs ashhart#2399)
@javierbits
javierbits force-pushed the docs/2399-quoted-marker-recipe branch 3 times, most recently from 10e85b3 to a911c31 Compare November 9, 2026 13:02
@javierbits

Copy link
Copy Markdown
Contributor Author

All points addressed, on a911c31cc (rebased over f03e5aac1; CI green on this head, atc overlap --json reports the same pullFilesUnavailable/timeLimit limits as before, shared file still only CHANGELOG.md).

docs/api.md

  • The recipe now leads with the plain request: the checkpoints measured so far spell a quoted marker with ordinary tokens, and the server stops on the end token when the model draws it, so a plain request finishes.
  • The ignore_eos half now stops on ["<|endoftext|>", "<|im_start|>"] and says why: with ignore_eos the end token no longer stops the reply, and behind an agent prompt the model often opens the next turn instead of writing end-of-text, so a stop on end-of-text alone never fires; the invented turns run on and a tool parser returns their tool calls.
  • Dropped "The end-of-text stop string still ends the reply at a real end of turn".
  • The cost note now covers all three spellings: a stop string matches the spelling however it is tokenized, so a reply that quotes <|endoftext|>, <|im_start|> or <|im_end|> as text is cut there.
  • A stop for <|im_end|> is said to cut at least where the end token would, and also where the reply spells it with ordinary tokens.
  • The tokenizer facts are restated for Qwen3.8-Flash-Next only, sourced to POST /tokenize with {"prompt": "<spelling>", "add_special_tokens": false} as @robertung88's output shows them; the 27B claim is gone.
  • The measurement paragraph cites A reply that quotes <|im_end|> ends the turn there (tool-enabled prompts, Qwen3.8-Flash-Next) #2399 by number and credits the agent-shaped runs as reported there: 0/9 runaways with the pair against 7/9 with end-of-text alone, on stock Qwen3.8-Flash-Next weights.

CHANGELOG.md
The Unreleased line now reads "(#2437, refs #2399). Thanks to @javierbits and @robertung88.", and the recipe it names is the pair (end-of-text and next-turn-open spellings). I know you settle the CHANGELOG at landing — say the word if you'd rather drop that commit and take it from your own edit.

Thanks, @robertung88 — the drawn ids and the stop-list runs settled it.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thanks @javierbits. The recipe now leads with the plain request, the ignore_eos half stops on the pair and says why, and the cost note covers all three spellings. It reads clearly. It's on the landing queue now.

javierbits and others added 3 commits November 9, 2026 19:48
…enize source, cite ashhart#2399

Per review: the tokenizer facts hold for Qwen3.8-Flash-Next only, shown by
POST /tokenize. With ignore_eos the end token no longer stops the reply and
behind an agent prompt the model often opens the next turn instead of writing
end-of-text, so the stop list needs <|im_start|> beside <|endoftext|>; the
invented turns' tool calls are returned. A stop string matches the spelling
however it is tokenized, so a reply quoting either marker is cut there; drop
the claim that the end-of-text stop ends a reply at a real end of turn. The
agent-shaped runs are reported in ashhart#2399: 0/9 runaways with the pair against
7/9 with end-of-text alone, on stock Qwen3.8-Flash-Next weights.
@ashhart
ashhart force-pushed the docs/2399-quoted-marker-recipe branch from a911c31 to 22a7b37 Compare November 9, 2026 19:48
@ashhart
ashhart merged commit 949474e into ashhart:main Nov 9, 2026
4 of 10 checks passed
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thank you @javierbits. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants