X280-6: on-card detokenizer and stop-string matching #307

Open
opened 2026-10-23 10:01:02 +02:00 by Grok · 0 comments
Owner

X280-6 — Tokenizer/detokenizer and stop-string matching on card

Type: latency/host-relief lever (smallest) · Stage: C (cheap, parallel with X280-3)
Effort (after X280-0): 3–5 weeks
Depends on: X280-0 · Independent of X280-2/3/4

1. TL;DR

Every step, the host turns ids into text in Python: output plumbing 2.38 ms and output-token bookkeeping 1.76 ms at B=8 in the host-tail audit — on a 4-core, 15.9 GB box that is also running vLLM's scheduler, the HTTP server and the sampler.

The X280 has a scalar pipeline, a 256 KiB private L2 per hart and 2 MiB L3/LIM per cluster. A 248,320-entry byte-level BPE vocabulary, plus an incremental UTF-8 + stop-string matcher per request, is a few MB of tables and a few hundred bytes of state per stream — that is X280-shaped work, not Tensix-shaped work (Tensix is bad at variable-length byte scanning and branchy table lookup).

Pre-registered target: host output path ≤ 0.5 ms/step (from ~4.1), X280 detok ≤ 0.5 ms/step at B=8, streamed text byte-identical to today.

2. Why

  • docs/LEVERS.md / docs/notes/decode-nondram-audit-2026-09-27.md §2 host tail: dispatch-outside-trace 2.56, output plumbing 2.38, host greedy sampling 2.29 (already removed by device argmax), output tokens 1.76, host RoPE 1.29, f32 upcast 1.02 — ~15 ms diffuse at a 64.8 ms step, and every item above 2 ms was worth attacking.
  • The host is 4 cores (docs/HARDWARE.md). At B=8 with 8 concurrent streams, Python detok + stop-string scan is per-token, per-stream work that competes with vLLM's scheduler for GIL time.
  • Unlike the sampler (X280-1) this is not a cliff — it is a constant tax. That is why it ranks after the flagship items, but it is cheap enough to run in parallel.

3. What exists today

Host-side, per output token, per request: tokenizers incremental decode for one id, byte-fallback buffering for incomplete UTF-8, stop-string search across the decoded suffix, finish_reason bookkeeping, and the token→text append into the streaming response. The HTTP/SSE layer stays on the host regardless.

4. Design

4.1 Split

Work Where
id → bytes (vocabulary table) X280
byte-fallback / partial UTF-8 assembly X280 (per-stream state, ~64 B)
stop-string search over the incremental suffix X280
finish_reason, request accounting host (vLLM semantics)
SSE / HTTP host (unchanged)

4.2 Data flow

device argmax / X280 sampler
  └─ sampled id (4 B)
       ├─ host ring (today's path, unchanged for the fallback)
       └─ X280 detok hart:
            vocab table (DRAM, local channel) → id's byte string (1–4 B)
            append to the per-stream buffer (LIM)
            UTF-8 boundary check → emit only complete code points
            stop-string Aho–Corasick / memmem over the last (max_stop_len) bytes
            → write {emitted_bytes, done_flag, finish_len} to the D2H ring
  host: reads ready text chunks (coalesced, not per token) and forwards them

Coalescing matters as much as placement: today the host is woken per token. The D2H ring can deliver one wake per N ms or per M bytes, which removes per-token Python overhead even if the detok itself stayed on the host. Measure that variant first — it may capture most of the win with no X280 at all (P0).

4.3 Sizing

Object Size Placement
vocabulary byte strings, 248,320 ids, avg ~6 B + offsets ~2–4 MB local DRAM channel
added-token / special-token table < 64 KB LIM
per-stream state (partial UTF-8, stop-string prefix state, buffer) ~256 B × 8 LIM
stop-string set < 2 KB LIM

5. Numeric targets and kill criteria

ID Metric Target
T6.1 host output path per step, B=8 ≤ 0.5 ms (from ~4.1)
T6.2 X280 detok time, B=8, 1 token/stream/step ≤ 0.5 ms
T6.3 streamed text byte-identical to the host detokenizer on a 5,000-response corpus, including invalid UTF-8 and byte-fallback ids
T6.4 finish_reason / stop-position identical on 1,000 stop-string cases incl. cross-token boundaries and overlapping stops
T6.5 TG tok/s per user +1…3% at B=8 (the host tail is partly overlapped)
K6.1 if T6.3 cannot be made byte-exact for byte-fallback ids after two rounds close; keep host detok
K6.2 if P0's coalesced-wake host variant already reaches ≤ 1 ms build that instead; close this issue as superseded
K6.3 if T6.5 is 0 in every cell keep as host-relief only, do not ship a served risk for 0

6. Quality gates

Gate What must pass
G0 QWEN36_X280_DETOK=1; flag off = host; banner; ttx lint
G1 host unit tests against a golden corpus; must-fail: a deliberately truncated multi-byte sequence must not be emitted
G2 QEMU/Spike: 5,000-response corpus, byte-identical output and stop positions
G3 on-card: detok latency at B=1/4/8, 4k/32k
G4 served boot + a streaming client that compares byte streams against the CONTROL arm
G5 ttx A/B (TG + a TTFT check, since the first token's detok is on TTFT)
G6 text equivalence is the gate; no sampling change, so numerics are untouched
G7 ship + docs

7. Work breakdown

Phase Work Exit
P0 Coalesced D2H wake + batched detok on the host — the cheapest 60% of the win T6.1 partial
P1 Vocabulary table generation + byte-exact reference implementation on host, then in QEMU G1/G2
P2 X280 detok hart + per-stream state + stop matcher G3
P3 Served streaming A/B G5
P4 Ship or close G7

P0 is deliberately first and may end the issue. If waking the host once per 8 ms instead of once per token recovers most of the 4.1 ms, the X280 version buys a fraction of a percent for a served-risk increase — say so and stop.

8. Risks

  1. Byte-exactness is harder than it looks. Byte-level BPE + invalid UTF-8 + special tokens + the tokenizer's own normalization: the reference is whatever tokenizers does, bugs included. Golden-corpus testing, not reasoning, is the only way.
  2. It does not remove the host from the API path. SSE framing, HTTP, and vLLM's RequestOutput construction stay. The claim is ≤ 0.5 ms of detok, not "no host work".
  3. Small win, served risk. This is the one issue in the milestone where the cost/benefit is genuinely marginal. It is filed because it is cheap and parallel, not because it is important.

9. Anti-goals

  • Not moving the HTTP server, SSE framing, or vLLM's output objects.
  • Not a new tokenizer implementation with different semantics.
  • Not touching prompt tokenization (once per request, not on the hot path).

10. Open questions

  • Q1: does the plugin already batch detok per step? If it does, P0 may already be done and this issue's win is smaller than estimated.
  • Q2: how much of the 1.76 ms "output tokens" line is RequestOutput construction (host-only, immovable) vs detok (movable)?

11. References

  • docs/notes/decode-nondram-audit-2026-09-27.md §2 — host tail itemisation (2.38 + 1.76 ms).
  • docs/LEVERS.md — device argmax as the precedent for removing host output work.
  • X280 DS 21G3 p.4 — private 256 KiB L2 per hart, System/Peripheral ports for uncached tables.
# X280-6 — Tokenizer/detokenizer and stop-string matching on card **Type:** latency/host-relief lever (smallest) · **Stage:** C (cheap, parallel with X280-3) **Effort (after X280-0):** 3–5 weeks **Depends on:** X280-0 · **Independent of** X280-2/3/4 ## 1. TL;DR Every step, the host turns ids into text in Python: output plumbing **2.38 ms** and output-token bookkeeping **1.76 ms** at B=8 in the host-tail audit — on a **4-core, 15.9 GB** box that is also running vLLM's scheduler, the HTTP server and the sampler. The X280 has a scalar pipeline, a 256 KiB private L2 per hart and 2 MiB L3/LIM per cluster. **A 248,320-entry byte-level BPE vocabulary, plus an incremental UTF-8 + stop-string matcher per request, is a few MB of tables and a few hundred bytes of state per stream** — that is X280-shaped work, not Tensix-shaped work (Tensix is bad at variable-length byte scanning and branchy table lookup). **Pre-registered target:** host output path **≤ 0.5 ms/step** (from ~4.1), X280 detok **≤ 0.5 ms/step at B=8**, streamed text **byte-identical** to today. ## 2. Why - `docs/LEVERS.md` / `docs/notes/decode-nondram-audit-2026-09-27.md` §2 host tail: dispatch-outside-trace 2.56, **output plumbing 2.38**, host greedy sampling 2.29 (already removed by device argmax), **output tokens 1.76**, host RoPE 1.29, f32 upcast 1.02 — ~15 ms diffuse at a 64.8 ms step, and every item above 2 ms was worth attacking. - The host is **4 cores** (`docs/HARDWARE.md`). At B=8 with 8 concurrent streams, Python detok + stop-string scan is per-token, per-stream work that competes with vLLM's scheduler for GIL time. - Unlike the sampler (X280-1) this is not a *cliff* — it is a constant tax. That is why it ranks after the flagship items, but it is cheap enough to run in parallel. ## 3. What exists today Host-side, per output token, per request: `tokenizers` incremental decode for one id, byte-fallback buffering for incomplete UTF-8, stop-string search across the decoded suffix, `finish_reason` bookkeeping, and the token→text append into the streaming response. The HTTP/SSE layer stays on the host regardless. ## 4. Design ### 4.1 Split | Work | Where | |---|---| | id → bytes (vocabulary table) | **X280** | | byte-fallback / partial UTF-8 assembly | **X280** (per-stream state, ~64 B) | | stop-string search over the incremental suffix | **X280** | | `finish_reason`, request accounting | host (vLLM semantics) | | SSE / HTTP | host (unchanged) | ### 4.2 Data flow ``` device argmax / X280 sampler └─ sampled id (4 B) ├─ host ring (today's path, unchanged for the fallback) └─ X280 detok hart: vocab table (DRAM, local channel) → id's byte string (1–4 B) append to the per-stream buffer (LIM) UTF-8 boundary check → emit only complete code points stop-string Aho–Corasick / memmem over the last (max_stop_len) bytes → write {emitted_bytes, done_flag, finish_len} to the D2H ring host: reads ready text chunks (coalesced, not per token) and forwards them ``` Coalescing matters as much as placement: today the host is woken per token. The D2H ring can deliver **one wake per N ms or per M bytes**, which removes per-token Python overhead even if the detok itself stayed on the host. **Measure that variant first — it may capture most of the win with no X280 at all (P0).** ### 4.3 Sizing | Object | Size | Placement | |---|---|---| | vocabulary byte strings, 248,320 ids, avg ~6 B + offsets | ~2–4 MB | local DRAM channel | | added-token / special-token table | < 64 KB | LIM | | per-stream state (partial UTF-8, stop-string prefix state, buffer) | ~256 B × 8 | LIM | | stop-string set | < 2 KB | LIM | ## 5. Numeric targets and kill criteria | ID | Metric | Target | |---|---|---| | **T6.1** | host output path per step, B=8 | **≤ 0.5 ms** (from ~4.1) | | **T6.2** | X280 detok time, B=8, 1 token/stream/step | **≤ 0.5 ms** | | **T6.3** | streamed text | **byte-identical** to the host detokenizer on a 5,000-response corpus, including invalid UTF-8 and byte-fallback ids | | **T6.4** | `finish_reason` / stop-position | identical on 1,000 stop-string cases incl. cross-token boundaries and overlapping stops | | **T6.5** | TG tok/s per user | +1…3% at B=8 (the host tail is partly overlapped) | | **K6.1** | if T6.3 cannot be made byte-exact for byte-fallback ids after two rounds | **close**; keep host detok | | **K6.2** | if P0's coalesced-wake host variant already reaches ≤ 1 ms | build that instead; close this issue as superseded | | **K6.3** | if T6.5 is 0 in every cell | keep as host-relief only, do not ship a served risk for 0 | ## 6. Quality gates | Gate | What must pass | |---|---| | **G0** | `QWEN36_X280_DETOK=1`; flag off = host; banner; `ttx lint` | | **G1** | host unit tests against a golden corpus; **must-fail**: a deliberately truncated multi-byte sequence must **not** be emitted | | **G2** | QEMU/Spike: 5,000-response corpus, byte-identical output and stop positions | | **G3** | on-card: detok latency at B=1/4/8, 4k/32k | | **G4** | served boot + a streaming client that compares byte streams against the CONTROL arm | | **G5** | `ttx` A/B (TG + a TTFT check, since the first token's detok is on TTFT) | | **G6** | text equivalence is the gate; no sampling change, so numerics are untouched | | **G7** | ship + docs | ## 7. Work breakdown | Phase | Work | Exit | |---|---|---| | P0 | Coalesced D2H wake + batched detok **on the host** — the cheapest 60% of the win | T6.1 partial | | P1 | Vocabulary table generation + byte-exact reference implementation on host, then in QEMU | G1/G2 | | P2 | X280 detok hart + per-stream state + stop matcher | G3 | | P3 | Served streaming A/B | G5 | | P4 | Ship or close | G7 | **P0 is deliberately first and may end the issue.** If waking the host once per 8 ms instead of once per token recovers most of the 4.1 ms, the X280 version buys a fraction of a percent for a served-risk increase — say so and stop. ## 8. Risks 1. **Byte-exactness is harder than it looks.** Byte-level BPE + invalid UTF-8 + special tokens + the tokenizer's own normalization: the reference is whatever `tokenizers` does, bugs included. Golden-corpus testing, not reasoning, is the only way. 2. **It does not remove the host from the API path.** SSE framing, HTTP, and vLLM's `RequestOutput` construction stay. The claim is ≤ 0.5 ms of *detok*, not "no host work". 3. **Small win, served risk.** This is the one issue in the milestone where the cost/benefit is genuinely marginal. It is filed because it is cheap and parallel, not because it is important. ## 9. Anti-goals - Not moving the HTTP server, SSE framing, or vLLM's output objects. - Not a new tokenizer implementation with different semantics. - Not touching prompt tokenization (once per request, not on the hot path). ## 10. Open questions - Q1: does the plugin already batch detok per step? If it does, P0 may already be done and this issue's win is smaller than estimated. - Q2: how much of the 1.76 ms "output tokens" line is `RequestOutput` construction (host-only, immovable) vs detok (movable)? ## 11. References - `docs/notes/decode-nondram-audit-2026-09-27.md` §2 — host tail itemisation (2.38 + 1.76 ms). - `docs/LEVERS.md` — device argmax as the precedent for removing host output work. - X280 DS 21G3 p.4 — private 256 KiB L2 per hart, System/Peripheral ports for uncached tables.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
bitpartner/tt-stack#307
No description provided.