Skip to content

[Engine] Inkling-2-Mini: multi-turn chats never reuse the prefix, so every turn re-reads the whole conversation (hidden thinking is in the slot but never in the next prompt) #6627

Closed

Description

@martinshane

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):

  1. The model writes hidden reasoning even at the forced effort none: a one-word answer ("Red") reports completion_tokens: 51. The server drops that span on purpose (inkling_dialect.py#L189, and template_kwargs forces reasoning_effort="none"), so the client never receives it.
  2. 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).
  3. 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

  1. strata install --family inkling-2-mini --model SQ-15 --context 65536 --vision yes --no-start --yes
  2. strata launch --model sq-15 --family inkling-2-mini --context 64k --vision on --tune skip --access local --port 8190 --no-tui
  3. POST /v1/chat/completions with a ~20K-token user message ending in a question; wait for finish_reason: stop.
  4. POST again with the same messages + {"role":"assistant","content":<the exact answer>} + a short new user question.
  5. Step 4 has prompt_tokens_details.cached_tokens: 0 and 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

  1. ggfunnn commented on Nov 22, 2026

    @ggfunnn

    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 locally

    Agent client (Hermes Agent, chat completions), four consecutive turns of one conversation:

    Prompt Reused Duration
    13,568 0 102.6 s
    13,590 0 105.4 s
    13,845 0 105.5 s
    15,442 0 122.4 s

    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 RESUME on the engine log: 0. Cold prefill about 135 tok/s on this card.

    The engine also accepts no cache option: --prompt-cache, --conversation-cache-mib and --kv-streaming each stop it with "unknown option" (ink_main.cpp parses 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.

  2. martinshane commented on Nov 22, 2026

    @martinshane
    Author

    Follow-up with a working fix, tested on the same M4 Pro (built from 26350e4 with 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_prefix inside the previous reply but still contains the whole previous prompt, it restores that checkpoint and resumes at ckpt_len instead of resetting to 0. It also resets DSpark's adaptive draft shape on restore, as reset_slot does. Other backends get no-op defaults in ink_backend.h, so they are unchanged. Host memory is ~160 MiB per slot; I capped it at max_slots <= 4.

    Results (SQ-15, 64K ctx, default DSpark):

    • 22.9K-token conversation, follow-up turns: ~56 s -> 2.5-3.0 s (turn 0 is still a cold read).
    • 15K-token agent loop with tools (tool call -> tool result -> answer -> next question, client resends no reasoning): 7 of 7 follow-ups at 1.1-2.6 s instead of ~30 s.
    • Exactness: resuming from the checkpoint gives byte-identical greedy output to the engine's existing full-prefix resume at the same position (max_tokens=1 first 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
    diff --git a/engine/src/inkling2/ink_backend.h b/engine/src/inkling2/ink_backend.h
    index f55425a21..eecb2cd88 100644
    --- a/engine/src/inkling2/ink_backend.h
    +++ b/engine/src/inkling2/ink_backend.h
    @@ -62,6 +62,12 @@ public:
         // Speculative rollback: restore KV + ShortConv state to `keep_len` (requires snapshot taken before verify!)
         virtual void snapshot_slot(int slot) = 0;
         virtual void rollback_slot(int slot, int keep_len) = 0;
    +    // Prompt checkpoint (#6627): save the slot's position-dependent state (SWA ring KV, ShortConv history, DSpark
    +    // f_rnn) right after a prompt is fully read, so a later prompt that extends it can resume there even when it
    +    // does not carry the generated tokens (hidden reasoning).  Global-attention KV is append-only and needs no copy.
    +    virtual bool checkpoint_slot(int /*slot*/) { return false; }
    +    virtual bool restore_checkpoint(int /*slot*/) { return false; }
    +    virtual void drop_checkpoint(int /*slot*/) {}
     
         // Batched 48-visit forward across 1..64 active slots!
         // logits_out: [batch.count_logits(), vocab_unpadded] FP32 (already softcapped by 30*tanh(z/30) and sliced to 200058).
    diff --git a/engine/src/inkling2/ink_serve.h b/engine/src/inkling2/ink_serve.h
    index 5ad35ef0f..9c12c2303 100644
    --- a/engine/src/inkling2/ink_serve.h
    +++ b/engine/src/inkling2/ink_serve.h
    @@ -327,6 +327,7 @@ struct ActiveReq {
         std::vector<int32_t> hist;
         std::vector<int32_t> gen_ids;
         std::vector<int32_t> cached_prefix;  // tokens currently resident in slot KV
    +    int ckpt_len = 0;                    // #6627: tokens covered by the slot's prompt checkpoint (0 = none)
         double t_start = 0.0;
         double prompt_ms = 0.0;
         double decode_t0 = 0.0;
    @@ -478,12 +479,22 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
                 const int lim = std::min(static_cast<int>(rq.cached_prefix.size()), rq.prompt_len - 1);
                 while (reuse < lim && rq.cached_prefix[reuse] == rq.prompt_ids[reuse]) ++reuse;
                 if (reuse != static_cast<int>(rq.cached_prefix.size())) {
    -                reuse = 0;  // Safe reset when SWA/ShortConv state diverged
    +                // #6627: the new prompt left the slot's history inside the previous reply (a client never resends
    +                // hidden reasoning).  Resume from the end of the previous prompt when it is still a prefix.
    +                if (rq.ckpt_len > 0 && reuse >= rq.ckpt_len && backend.restore_checkpoint(rq.slot)) {
    +                    reuse = rq.ckpt_len;
    +                    rq.cached_prefix.resize(static_cast<size_t>(reuse));
    +                    proto("INFO prompt-checkpoint resume %d", reuse);
    +                } else {
    +                    reuse = 0;  // Safe reset when SWA/ShortConv state diverged
    +                }
                 }
             }
             if (reuse == 0) {
                 backend.reset_slot(rq.slot);
    +            backend.drop_checkpoint(rq.slot);
                 rq.cached_prefix.clear();
    +            rq.ckpt_len = 0;
             } else {
                 proto("RESUME %d", reuse);
             }
    @@ -538,7 +549,9 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
                     std::string cerr;
                     if (s >= 0 && s < P && !reqs[s].active && parse_id_list(line.substr(sp + 1), cids, cerr)) {
                         backend.reset_slot(s);
    +                    backend.drop_checkpoint(s);
                         reqs[s].cached_prefix.clear();
    +                    reqs[s].ckpt_len = 0;
                         proto("BCOK %d %zu", s, cids.size());
                     }
                 }
    @@ -806,6 +819,12 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
                     rq.prefill_pos += prefill_fed[s];
                     rq.cur_pos = rq.prefill_pos;
                     rq.prompt_ms += step_ms;
    +                if (rq.prefill_pos == rq.prompt_len && rq.prompt_img_idx.end() ==
    +                        std::find_if(rq.prompt_img_idx.begin(), rq.prompt_img_idx.end(), [](int32_t x) { return x >= 0; })) {
    +                    // #6627: the whole prompt is read: checkpoint before any generated token enters the slot
    +                    if (backend.checkpoint_slot(s)) rq.ckpt_len = rq.prompt_len;
    +                    else rq.ckpt_len = 0;
    +                }
                     if (rq.is_solo || !rq.admitted) {
                         const double ppts = step_ms > 0.0 ? (prefill_fed[s] * 1000.0 / step_ms) : 0.0;
                         proto("PP %d %d %.1f %.1f", rq.prefill_pos, rq.prompt_len, rq.prompt_ms, ppts);
    diff --git a/engine/src/inkling2/metal/ink_metal_backend.mm b/engine/src/inkling2/metal/ink_metal_backend.mm
    index 2d2db81a6..7b529ab73 100644
    --- a/engine/src/inkling2/metal/ink_metal_backend.mm
    +++ b/engine/src/inkling2/metal/ink_metal_backend.mm
    @@ -152,6 +152,62 @@ void snapshot_slot(int slot) override {
             }
         }
     
    +    bool checkpoint_slot(int slot) override {
    +        if (slot < 0 || slot >= runner_.max_slots || runner_.max_slots > 4) return false;   // host RAM: ~160 MiB per slot
    +        if ((int)ckpts_.size() < runner_.max_slots) ckpts_.resize(runner_.max_slots);
    +        auto& ck = ckpts_[slot];
    +        const auto& c = mod_.man.c;
    +        const size_t row = (size_t)c.n_kv * c.head_dim * sizeof(uint16_t);
    +        ck.k.resize(c.n_visits); ck.v.resize(c.n_visits);
    +        for (int v = 0; v < c.n_visits; ++v) {
    +            const int stride = runner_.visit_kv_stride[v];
    +            if (stride >= runner_.max_ctx) { ck.k[v].clear(); ck.v[v].clear(); continue; }   // global: append-only
    +            const size_t bytes = (size_t)stride * row, off = (size_t)slot * bytes;
    +            ck.k[v].resize(bytes); ck.v[v].resize(bytes);
    +            std::memcpy(ck.k[v].data(), runner_.kv_k[v].as<uint8_t>() + off, bytes);
    +            std::memcpy(ck.v[v].data(), runner_.kv_v[v].as<uint8_t>() + off, bytes);
    +        }
    +        runner_.snapshot_slot(slot, ck.sc);
    +        if (runner_.use_dspark) {
    +            const size_t D = (size_t)c.hidden;
    +            ck.frnn.resize(D);
    +            std::memcpy(ck.frnn.data(), runner_.dsp_frnn_slot.as<float>() + (size_t)slot * D, D * 4);
    +        }
    +        ck.valid = true;
    +        return true;
    +    }
    +
    +    bool restore_checkpoint(int slot) override {
    +        if (slot < 0 || slot >= (int)ckpts_.size() || !ckpts_[slot].valid) return false;
    +        auto& ck = ckpts_[slot];
    +        const auto& c = mod_.man.c;
    +        const size_t row = (size_t)c.n_kv * c.head_dim * sizeof(uint16_t);
    +        for (int v = 0; v < c.n_visits; ++v) {
    +            if (ck.k[v].empty()) continue;
    +            const size_t bytes = ck.k[v].size(), off = (size_t)slot * (size_t)runner_.visit_kv_stride[v] * row;
    +            std::memcpy(runner_.kv_k[v].as<uint8_t>() + off, ck.k[v].data(), bytes);
    +            std::memcpy(runner_.kv_v[v].as<uint8_t>() + off, ck.v[v].data(), bytes);
    +        }
    +        runner_.restore_slot(slot, ck.sc);
    +        if (runner_.use_dspark && !ck.frnn.empty()) {
    +            const size_t D = (size_t)c.hidden;
    +            std::memcpy(runner_.dsp_frnn_slot.as<float>() + (size_t)slot * D, ck.frnn.data(), D * 4);
    +        }
    +        if (slot < (int)slot_beam_depth_.size()) {   // DSpark's adaptive draft shape restarts as for a fresh prompt
    +            slot_beam_depth_[slot] = runner_.is_apple10 ? 5 : 4;
    +            slot_ema_gain_[slot] = 1.15;
    +            slot_cooldown_[slot] = 0;
    +            slot_cd_len_[slot] = 8;
    +        }
    +        if (last_ver_slot_ == slot) last_ver_slot_ = -1;
    +        if (last_tree_slot_ == slot) last_tree_slot_ = -1;
    +        return true;
    +    }
    +
    +    void drop_checkpoint(int slot) override {
    +        if (slot >= 0 && slot < (int)ckpts_.size()) ckpts_[slot].valid = false;
    +    }
    +
         void rollback_slot(int slot, int keep_len) override {
             if (slot < 0 || slot >= (int)snaps_.size()) return;
             // O(1) ZERO-REPLAY partial-accept rollback via ShortConv verify ring (linear verify!)
    @@ -445,6 +501,13 @@ bool selfcheck(std::string& err) override {
         ink_metal::InkMetalRunner runner_;
         std::vector<ink_metal::InkMetalRunner::SlotSconvSnap> snaps_;
         std::vector<std::vector<float>> frnn_snaps_;
    +    struct PromptCkpt {
    +        bool valid = false;
    +        std::vector<std::vector<uint8_t>> k, v;          // [visit] SWA ring bytes for the slot (empty: global visit)
    +        ink_metal::InkMetalRunner::SlotSconvSnap sc;
    +        std::vector<float> frnn;
    +    };
    +    std::vector<PromptCkpt> ckpts_;
         std::vector<uint8_t> slot_used_;
         std::vector<int> slot_beam_depth_;
         std::vector<double> slot_ema_gain_;

    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.

  3. jbox5 commented on Nov 22, 2026

    @jbox5

    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.h changes from this thread.

    Environment: Strata 0.2.19, strata-inkling 0.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.

    Engine on the same card Median time to first token Model time for the session
    strata-inkling SQ-20, unpatched 103.1 s 2,447 s
    llama.cpp b12613, IQ4_NL GGUF 3.15 s 399 s

    Decode speed isn't the cause: strata-inkling writes faster in the same run. Every step re-reads the full history.

    Results with #6665

    • Prompt read on later turns: 17,798 ms becomes 149 ms on a 19,758-token chat, and 216 ms with --kv fp8.
    • Exactness: the state the engine resumes from is byte-identical to the state of the existing exact-prefix resume. I checked this by hashing it at about 5K, 20K and 80K tokens, with DSpark on, with --draft off and with --kv fp8.
    • Greedy output: this can't show exactness on this card. Identical requests to the unpatched engine already diverge after 4 to 171 tokens. I'll file that separately.
    • Reporting: the PR also makes cached_tokens and 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

    #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.

  4. pixlatdguardian commented on Nov 22, 2026

    @pixlatdguardian

    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 the self.state == "think" branch append ("reasoning", chunk) before returning instead of dropping the span. InklingOutputParser already emits that as reasoning_content, and the chat template renders reasoning_content back in the same position before the tool call. So a client that replays it produces a prompt that extends cached_prefix exactly.

    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:

    turn prompt_ms unpatched prompt_ms patched
    1 ~2,350 59
    2 (+1.3K-token tool result) ~250–330 (no thought in turn 1, so it hit) 303
    3 ~2,640 63

    pi's openai-completions provider already replays reasoning_content, and a pi session showed the same reuse.

    Caveats:

    • This also feeds the earlier reasoning back into the model's context.
    • Clients that don't replay it still miss, so the prompt checkpoint discussed above is the general fix.
  5. added a commit that references this issue on Nov 22, 2026
    4aaa1cb
  6. pixlatdguardian commented on Nov 23, 2026

    @pixlatdguardian

    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 include tools still 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):

    turn 2 cached_tokens turn 2 time to first token
    no tools 12,541 of 12,552 0.09 s
    with tools 0 of 12,626 3.98 s

    In 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_prompt ends the prompt with an empty thinking block, <|message_model|><|content_thinking|><|end_message|>. The template only renders a thinking block for an assistant message when reasoning_content is non-empty (chat_template.jinja, the message.reasoning_content branch). 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:

    turn 1 ends:  ...open setup.py<|end_message|><|message_model|><|content_thinking|><|end_message|>
    turn 2 has:   ...open setup.py<|end_message|><|message_model|>read_file<|content_invoke_tool_json|>{...}
    

    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:

    {%- if message.role == "assistant" and message.reasoning_content is defined and message.reasoning_content -%}
        {{- rtok ~ "<|content_thinking|>" ~ message.reasoning_content ~ "<|end_message|>" -}}
    {%- elif message.role == "assistant" and tools -%}
        {{- "<|message_model|><|content_thinking|><|end_message|>" -}}
    {%- endif -%}

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions