Repository navigation
Description
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Terminal (the strata command)
What happened
Every follow-up turn in a conversation re-reads the whole prompt from scratch. On a ~22.9K-token conversation each reply takes ~55 s on this Mac, even though the new prompt is the previous prompt plus the previous answer (replayed verbatim, finish_reason: stop) plus a short question. For agent clients, which resend a growing 10-40K-token history on every step, that is a full cold read per step.
Measured with the OpenAI endpoint, temperature 0, one slot (the default):
| turn | prompt_tokens | cached_tokens | wall |
|---|---|---|---|
| 0 (cold, 22.9K) | 22,853 | 0 | 61.7 s |
| 1 (+ answer + short question) | 22,918 | 0 | 55.7 s |
| 2 (+ answer + short question) | 22,937 | 0 | 56.6 s |
prompt_tokens_details.cached_tokens is 0 on every turn, and GET /metrics showed reused: null on every request of a second 3-turn run (see Logs). Cold prefill is ~440-470 tok/s here, so ~55 s is a full re-read, not a partial one.
What I think causes it (from reading the code, please correct me):
- The model writes hidden reasoning even at the forced effort
none: a one-word answer ("Red") reportscompletion_tokens: 51. The server drops that span on purpose (inkling_dialect.py#L189, andtemplate_kwargsforcesreasoning_effort="none"), so the client never receives it. - The engine's slot keeps prompt + every generated token, the hidden reasoning included in
cached_prefix, and reuses only when that WHOLE list is a prefix of the next prompt; any partial match resets to 0 because SWA/ShortConv state can't rewind (ink_serve.h#L475-L487). - The next prompt contains the visible answer but not the hidden reasoning, so the match always fails at the start of the previous answer, and reuse drops to 0 instead of to the end of the previous prompt.
So the reuse can never fire in a normal multi-turn chat. An exact repeat of the same request doesn't reuse either.
Expected: a follow-up that extends the previous prompt reuses at least the previous prompt (the KV/state at the end of the previous prompt), as the Qwen path's conversation cache does. A possible fix: snapshot the slot's SWA/ShortConv state at the end of the prompt (before generation) and resume from that point when the next prompt matches up to there. Alternatively, return the reasoning so clients can replay it, but agent clients usually drop reasoning from history, so the snapshot is the robust fix.
Single-request numbers are great (prefill ~450 tok/s, the 4-task agent check I use passed as well as my current local default in half the time), which is why I'd like to use it as an agent model.
Smallest steps or command that reproduce it
strata install --family inkling-2-mini --model SQ-15 --context 65536 --vision yes --no-start --yesstrata launch --model sq-15 --family inkling-2-mini --context 64k --vision on --tune skip --access local --port 8190 --no-tui- POST /v1/chat/completions with a ~20K-token user message ending in a question; wait for
finish_reason: stop. - POST again with the same messages +
{"role":"assistant","content":<the exact answer>}+ a short new user question. - Step 4 has
prompt_tokens_details.cached_tokens: 0and takes as long as step 3's prefill. Repeat for more turns: same every time.
Quick check that hidden reasoning is generated: ask "Name a color. One word." -> content "Red", completion_tokens: 51.
Reproduction status
Reproduced locally
Strata version
Strata 0.2.19 · Terminal build 0.1.65 · strata-inkling 0.1.65 (macos-arm64-metal)
Graphics card, memory and system
Apple M4 Pro (MacBook Pro) · 48 GB unified memory · macOS 26.6.2
Model, size and settings
Inkling-2-Mini SQ-15 + Vision pack · 64K context · pictures on · DSpark on (defaults)
Logs
Engine log (strata launch):
[strata] engine started: .../components/shapes/inkling2/engine/0.1.65-macos-arm64-metal/strata-inkling --serve --native .../Inkling-2-Mini-SQ-15.strata --max-context 65536 --vision .../Inkling-2-Mini-Vision.strata --draft dspark
[ink_metal] loaded .../Inkling-2-Mini-SQ-15.strata (build=SQ-15, minor=1, 13.36 GiB, trunk=646, dspark=54, experts=3072, vram_order=3072) in 0.09s (workSet=37.4 GiB, maxBuf=28.1 GiB)
[ink_metal] runner ready: slots=1 ctx=65536 batch=512 dspark=1 vision=1 mpp=1(trunk=1,hot=0) | KV=2208.0 MiB SC=3.7 MiB TotalAlloc=18.86 GiB
/metrics requests (newest first) for a second 3-turn run on a ~3.6K-token prompt (turns stopped at max_tokens 200), plus an exact repeat of the last request: reused null on all, prompt_tokens 3599 -> 3612 -> 3622 -> 3622, live.slots[0].held_tokens stayed at 14 (the warm-up request) throughout.
Activity
ggfunnn commentedon Nov 22, 2026
Same on AMD/HIP, so it's not Metal-specific.
Environment: Strata 0.2.19 · strata-inkling 0.1.65 (
linux-x86_64-hip-rx6000) · Radeon RX 6800 16 GB (gfx1030) · 24 GB RAM · Linux Mint 22.3 · SQ-15 · 128K ·--kv k8v4· parallel 1 · DSpark on · reproduced locallyAgent client (Hermes Agent, chat completions), four consecutive turns of one conversation:
Two-turn test (second request = first conversation + 16 tokens): 5,098 tokens, 38.4 s, reused 0 → 5,114 tokens, 38.5 s, reused 0. An exact repeat of a ~6K prompt: 41.6 s, then 43.0 s.
grep -c RESUMEon the engine log: 0. Cold prefill about 135 tok/s on this card.The engine also accepts no cache option:
--prompt-cache,--conversation-cache-miband--kv-streamingeach stop it with "unknown option" (ink_main.cppparses none). So there's no workaround from the launch side either. PR #6520's conversation cache (a checkpoint at each prompt end) looks like the fix you describe.martinshane commentedon Nov 22, 2026
Follow-up with a working fix, tested on the same M4 Pro (built from
26350e4with the engine's own CMake, Metal backend).Engine-side prompt checkpoint (diff below, +83 lines in 3 files). When a slot finishes reading a prompt, it copies the slot's position-dependent state: the SWA ring KV of the 40 SWA visits, the ShortConv history, and the DSpark f_rnn. Global-attention KV is append-only and needs no copy. On admission, if the new prompt diverges from
cached_prefixinside the previous reply but still contains the whole previous prompt, it restores that checkpoint and resumes atckpt_leninstead of resetting to 0. It also resets DSpark's adaptive draft shape on restore, asreset_slotdoes. Other backends get no-op defaults inink_backend.h, so they are unchanged. Host memory is ~160 MiB per slot; I capped it atmax_slots <= 4.Results (SQ-15, 64K ctx, default DSpark):
max_tokens=1first request), 3/3 at ~4K, 9K and 17K tokens, with DSpark on and off. Before I added the DSpark adaptive-state reset, 1 of 3 differed with DSpark on; with drafting off it was already 3/3. Note that both resume paths, the existing one included, differ from a cold read after the first few dozen characters at temperature 0. That's chunk-boundary numerics, not this change: cold vs cold is deterministic here.The diff (
engine/src/inkling2):engine-prompt-checkpoint.diff
A complementary server-side option I'm also running locally. The server keeps, per finished reply, (client prompt, engine prompt, raw generated ids). When a later request starts with that client prompt and then carries the reply's visible turn, the server swaps the visible turn for the raw ids (hidden reasoning included), so the engine's existing full-prefix match fires and nothing is re-read. Since the template supports assistant
reasoning_content, the model then sees its earlier reasoning, which is a behaviour change. With the engine checkpoint alone it doesn't. So the checkpoint is the one I'd suggest upstream; happy to share the server patch too if useful.Thanks for the quick Inkling support, the single-request speed on this Mac is excellent.
jbox5 commentedon Nov 22, 2026
HIP fix in #6665, and impact on an agent loop
I opened #6665 (draft) with a HIP implementation of the three checkpoint hooks, on top of @martinshane's
ink_backend.h/ink_serve.hchanges from this thread.Environment: Strata 0.2.19,
strata-inkling0.1.65, Radeon AI PRO R9700 32 GB (gfx1201), Linux x86_64, Inkling-2-Mini SQ-20, 128K context,parallel 1. Reproduced locally.Impact before the fix
I replayed a 26-step agent session with tool calls. The history grows from 4K to 82K tokens, and the client sends no reasoning back.
strata-inklingSQ-20, unpatchedDecode speed isn't the cause:
strata-inklingwrites faster in the same run. Every step re-reads the full history.Results with #6665
--kv fp8.--draft offand with--kv fp8.cached_tokensand DSpark's accepted drafts show up in the API (49-61% accepted here, which may help with [Engine] Inkling-2-Mini (.strata): DSpark speculative decoding never engages (drafting: off, drafts_offered: 0) #6633).Still open
prompt_len - 1, which is below the checkpoint atprompt_len. Taking the checkpoint atprompt_len - 1would cover them.#6612 explains why the match fails on every turn: the model writes a
<|content_thinking|>span even at effort 0, and the serve discards it.pixlatdguardian commentedon Nov 22, 2026
I tested the reasoning-replay idea as a server-only change on Windows/CUDA: RTX 5090, engine 0.1.65, SQ-20, 64K context, one slot.
In
InklingDialect._emit_typed, I made theself.state == "think"branch append("reasoning", chunk)before returning instead of dropping the span.InklingOutputParseralready emits that asreasoning_content, and the chat template rendersreasoning_contentback in the same position before the tool call. So a client that replays it produces a prompt that extendscached_prefixexactly.Here is a 4-turn tool-calling loop with a ~13.5K-token prompt, replaying
reasoning_content, compared with the same loop on the unpatched server:pi's
openai-completionsprovider already replaysreasoning_content, and a pi session showed the same reuse.Caveats:
inkling2: accelerate Unsloth GGUF quants and fix issues Niko1221#6580/N…
Merge upstream v0.2.20 into memory-core: the 4-tier MoE planner, and …
pixlatdguardian commentedon Nov 23, 2026
Retested on 0.2.20 (Control/Terminal 0.1.66, strata-inkling 0.1.66) on Windows/CUDA (RTX 5090, SQ-15, 96K,
--kv fp8, DSpark, one slot). Plain chat now reuses the prefix, but requests that includetoolsstill reuse nothing. Agent clients always send tools, so every agent turn still re-reads the whole conversation.Two-turn probe, ~12.5K-token prompt, temperature 0. Turn 2 resends turn 1 plus the assistant reply as returned, plus one new message (a tool result when tools are on):
cached_tokensIn a real agent session (pi, the same coding task as before), each turn re-read the full prompt: about 15 s per turn at 60K tokens. The task took 606 s of GPU time, against 147 s on 0.2.19 with the reasoning-replay patch from my earlier comment.
Cause: with tools,
finish_promptends the prompt with an empty thinking block,<|message_model|><|content_thinking|><|end_message|>. The template only renders a thinking block for an assistant message whenreasoning_contentis non-empty (chat_template.jinja, themessage.reasoning_contentbranch). So when that turn comes back as history, the empty block is gone, and the next prompt stops matching at exactly that point.I rendered both turns with
serve.frontend.ChatTemplate+inkling_dialect.prepare_messages/template_kwargs/finish_prompt. Turn 2 shares 421 of turn 1's 456 characters, and the first difference is right after the<|message_model|>that opens turn 1's empty thinking block:Workaround that fixes it here: in the pack's
tokenizer/chat_template.jinja, replay the same empty block for assistant turns that have no reasoning when tools are present:With that change, turn 2 renders as an exact extension of turn 1. On the live server, the tools probe reused 12,573 of 12,629 tokens, and the no-tools case was unchanged (12,537 of 12,548). The same result could also come from the server side (marking those assistant messages before rendering) instead of from the template.
Separate note on 0.2.20 with tools, in case it is useful for #6612: after the forced empty block, the model often writes its own
<|content_thinking|>block before the tool call, and the server discards it. Mostly this is short, but twice in one agent session it ran to the token limit (once to 8,192 tokens), and those replies came back empty.inkling2/hip: implement the prompt checkpoint hooks (Niko1221#6627)