Repository navigation
server: every chat request records where each message starts in the prompt, at exact token boundaries (#3617 step 0) - #3679
Merged
Merged
Conversation
Owner
Author
|
/atc exchange 0bb53970548e4699e60dc285551abc3d1b5465c81a62895a44a54eef6571120f |
ashhart
force-pushed
the
lead/message-starts-0
branch
from
November 17, 2026 14:22
7eefca0 to
6ce768a
Compare
…k plan (#3617 step 0) The chat template's render records where each request message's own output begins: an iteration of a loop over the message, or one that sets it to a name or passes it to a macro (GLM-5.3 writes a run of tool results in the first one's iteration), counts only if it writes top-level output (eval.zig Marks; template.renderMarked). prompt.renderStarts maps those bytes to tokens, keeping a start only where the piece before it encodes to the request's own ids (message_starts.zig), and prepare returns them as Rendered.message_starts when the prompt cache or a prefill step can use them. They travel as api.Request.message_starts to lanes.Stream.message_starts. Nothing reads them yet: Request.chunks, every family's prefill cuts and the cache store's starts are unchanged, so every reply is token-identical. Raw completions, image prompts, video-replaced text and segment or native renderers (Kimi, DeepSeek) carry no starts. Tests: every message of Qwen3.8's and GLM-5.3's own templates, and of Gemma 4, Llama 3 and Nemotron turn formats (system, user, assistant, two tool turns, all closer than min_chunk), starts at one whose segment holds that message's text alone; a request's chunk plan is pinned to main's; a raw completion has no starts.
… text (#3617 step 0) The template's marks for a message now follow captured output (set blocks, macro bodies, scoped blocks, ~ and + joins) to where that exact string is written, and are dropped when the string is changed or never written. A binding made inside a capture no longer marks the iteration, and keyword macro arguments bind as positional ones do. Message lookup is a hash map. A byte start is kept only where the tokens before it spell the text before it exactly, token by token, and the text on each side re-encodes alone to exactly its ids; a fused unknown or a normalized byte drops it. The cost is one walk of the ids and one more encode of the text in total. The checker's chunk test now passes an empty fields object, which chat.prepare requires. Request.chunks, family cuts and the prompt cache store are unchanged.
ashhart
force-pushed
the
lead/message-starts-0
branch
from
November 17, 2026 18:05
6ce768a to
7b5f8c4
Compare
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
8 tasks done
mrv777
added a commit
to mrv777/TensorFold
that referenced
this pull request
Nov 24, 2026
…ind TF_QWEN27_MESSAGE_STARTS (ashhart#3617) With TF_QWEN27_MESSAGE_STARTS=1 a chat request plans prompt states at up to four of its latest message starts (the exact token offsets ashhart#3679 records), and the rewind state moves back to the last user message's start, role header included. A later request that edits a tool result or replaces a message in that history resumes from that message's start instead of re-reading the whole prompt. The starts only take room the cache can already promise beside the request's own endpoint: they never displace another kept state, and under pressure the reservation trims them before the pass. Unset or 0 leaves every plan as on main. Raw prompts carry no starts and are unchanged.
mrv777
added a commit
to mrv777/TensorFold
that referenced
this pull request
Nov 25, 2026
…ind TF_QWEN27_MESSAGE_STARTS (ashhart#3617) With TF_QWEN27_MESSAGE_STARTS=1 a chat request plans prompt states at up to four of its latest message starts (the exact token offsets ashhart#3679 records), and the rewind state moves back to the last user message's start, role header included. A later request that edits a tool result or replaces a message in that history resumes from that message's start instead of re-reading the whole prompt. The starts only take room the cache can already promise beside the request's own endpoint: they never displace another kept state, and under pressure the reservation trims them before the pass. Unset or 0 leaves every plan as on main. Raw prompts carry no starts and are unchanged.
ashhart
pushed a commit
to mrv777/TensorFold
that referenced
this pull request
Nov 25, 2026
…ind TF_QWEN27_MESSAGE_STARTS (ashhart#3617) With TF_QWEN27_MESSAGE_STARTS=1 a chat request plans prompt states at up to four of its latest message starts (the exact token offsets ashhart#3679 records), and the rewind state moves back to the last user message's start, role header included. A later request that edits a tool result or replaces a message in that history resumes from that message's start instead of re-reading the whole prompt. The starts only take room the cache can already promise beside the request's own endpoint: they never displace another kept state, and under pressure the reservation trims them before the pass. Unset or 0 leaves every plan as on main. Raw prompts carry no starts and are unchanged.
ashhart
pushed a commit
that referenced
this pull request
Nov 25, 2026
…ind TF_QWEN27_MESSAGE_STARTS (#3617) With TF_QWEN27_MESSAGE_STARTS=1 a chat request plans prompt states at up to four of its latest message starts (the exact token offsets #3679 records), and the rewind state moves back to the last user message's start, role header included. A later request that edits a tool result or replaces a message in that history resumes from that message's start instead of re-reading the whole prompt. The starts only take room the cache can already promise beside the request's own endpoint: they never displace another kept state, and under pressure the reservation trims them before the pass. Unset or 0 leaves every plan as on main. Raw prompts carry no starts and are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 0 of #3617: every chat request now records where each message starts in the rendered prompt, as exact token offsets, beside the chunk plan. Nothing reads these starts yet, so every reply is token-identical to main. The next steps use them to keep prompt states at message starts on each family.
What a start is. The token offset where a message's own part of the prompt begins. The list is sorted; it may leave a message out, but every start it gives is exact:
setblock, a macro body or a scoped block carries its mark with it, through~and+joins, to where the string is finally written. A mark whose text is never written is dropped.Cost. About one more encode of the text, and constant time per message lookup. A test renders 400 messages through Qwen3.8's template and fails if the time is more than twice the plain render.
Unchanged.
Request.chunks, every family's prompt cuts and the prompt cache store.Tests (
test-server-cpu): template marks through captures, macros and joins (message_marks_test.zig); token-boundary proofs with realtokenizer.jsonfiles (message_starts_proof_test.zig); the prepared chunk plan compared with main's; and the cost bound. The proof and cost tests fail on the first version of this change and pass here.Checks:
test-server-cpu(only the knownslide_forget_testfails, as on main),test-golden0 unexpected differences,test-server-security28 passed,test-template-limits-host,test-lane-strand-hostandtest-lane-api-host(only the knownoriginals_testfailures). Files stay at 600 lines or fewer; lean findings are level with main.