Skip to content

server: opt-in committed token IDs on chat and completion streams - #3285

Merged
ashhart merged 1 commit into
mainfrom
lead/exo-token-stream
Nov 14, 2026
Merged

ashhart merged 1 commit into
mainfrom
lead/exo-token-stream

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

An engine integration needs the committed token IDs while a stream runs, and the semantic deltas can't give them: one chunk can merge several tokens, split a UTF-8 character, or leave out reasoning and tool syntax, and retokenizing text is not exact. exo's TensorFold backend (proposed, not yet opened upstream) is the first user.

A client opts in with stream_options.tensorfold_token_stream_version: 1 on a streaming chat or completions request. The stream then interleaves tensorfold.token.chunk events (offset, token_ids) with the usual chunks, and every chunk carries tensorfold_stream (token_count, the last token_id, and logprob_positions when it has logprob entries: each entry's raw token position, shaped like the chunk's logprobs with content, reasoning_content and tool_calls groups). capabilities --json lists token_stream_versions: [1]. Unknown versions, non-streaming requests and Cortheon multi-round replies get a 400 before admission. Without the option the wire output is unchanged and the sink's token callback is null, so the default path does no extra work. docs/api.md documents the contract.

Checked on macOS (M5 Max):

  • zig build test-token-stream-host: 27/27 on this head.

  • zig build -Dfixed-cpu test-server-cpu: passes apart from test-server-deepseek-chat-host, which fails the same way on main at 948e748 (a DeepSeek V4.1 namespace prompt pin), so it is not from this change.

  • The same change on ab78aef (this head differs only by main's .asked = input.cancel on the same line of chat.zig), built as the Metal native binary, served mlx-community/Qwen3.5-2B-MLX-4bit through exo. At temperature 0 the exo path and direct TensorFold gave the same output hash, single and concurrent, and a stream dropped mid-reply released the native request within 0.2 s.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/exo-token-stream branch 2 times, most recently from 526328b to d3acbec Compare November 14, 2026 02:20
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

CUDA check on an NVIDIA GB10 (sm_121), built from this change's previous head 526328b (the current head only moves the sink callback from openai.zig into token_stream.zig):

  • capabilities --json: chip nvidia-sm121, backend cuda, token_stream_versions: [1], qwen3_5 with mlx-q4g64.

  • Served mlx-community/Qwen3.5-2B-MLX-4bit at revision 93760be4 over a Unix socket. With the option, the tensorfold.token.chunk batches were contiguous, matched the final tensorfold.token_ids, and the last anchor equalled the last ID. Without it the stream had no anchors, the same text and the same IDs. Version 2 got a 400.

  • exo's proposed TensorFold backend on the same box placed the model, and at temperature 0 its replies hashed the same as direct TensorFold. A dropped stream left 0 live connections on the native server.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/exo-token-stream branch from d3acbec to be07074 Compare November 14, 2026 05:55
@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main d6e9820 as be07074, keeping #3206's logprobs as they are.

#3206 projects logprob entries onto prose, reasoning and tool calls, and a token shown in parts gets one entry per part, so one offset plus a run of IDs no longer describes a chunk's entries. The anchor now carries logprob_positions instead: each entry's raw token position, shaped like the chunk's logprobs (content, reasoning_content, and tool_calls groups in the last chunk). Without the token stream option, the output is byte for byte what #3206 sends: a test compares the same tool-call request with the option on and off, and logprob_positions never appears in a delta.

Host checks on the new head: test-token-stream-host and test-logprob-offers-host pass, the lean check shows 0 new problems, and zig fmt --check is clean. The rest of test-server-cpu passes too, apart from the DeepSeek chat goldens, which also fail on clean main on this Mac.

  • Synthena (Ash's Agent)

A stream that sends stream_options.tensorfold_token_stream_version: 1
interleaves tensorfold.token.chunk events (offset and committed IDs)
with the usual chunks, and each chunk carries a tensorfold_stream anchor
(token count, last ID, and each logprob entry's raw token position,
shaped like the chunk's logprobs). Engine integrations such as exo's
proposed TensorFold backend need the real IDs while generation runs,
without retokenizing text that merges UTF-8 pieces, reasoning or tool
syntax. capabilities --json advertises token_stream_versions [1].
Without the option the wire output is unchanged.
@ashhart
ashhart force-pushed the lead/exo-token-stream branch from 9baaafd to 9276208 Compare November 14, 2026 17:03
@ashhart
ashhart merged commit c331d07 into main Nov 14, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/exo-token-stream branch November 14, 2026 17:03
ashhart added a commit to ashhart/exo that referenced this pull request Nov 15, 2026
TensorFold 1.2.9 ships token stream protocol version 1 (ashhart/TensorFold#3285). Point the requirement at the release and show where to get tensorfold-native: the release archives, or Homebrew on macOS.
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.

1 participant