[GH-ISSUE #5515] [Engine] serve: an in-place retune (TUNE) and per-shape conversation-cache routing #5486

Open
opened 2026-11-08 01:47:42 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @rwkeyes on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5515

Summary

Two proposals that belong together, both about settings that can only change at start-up today:

  1. An in-place retune. --prompt-cache, --prompt-cache-every, --short-read, --spec-min-p,
    --pcie-frac, prefill_chunk and the adapt_* family are all read out of the engine's options at
    the moment the engine uses them, but the only way to change one is to restart the engine — which on
    a real config also means a model load (93–100 s on the box I measure on). Measuring one value costs
    a start; measuring six costs six.
  2. Conversation-cache routing. With the cache on (--prompt-cache 6), a single-shot request that
    will never reuse its context still pays the parking cost. On this box that is +10.1 % prefill on a
    3.5 k code prompt and +4.0 % on 4.0 k prose
    with the cache off; short single-shot prompts went from
    0.522 s to 0.239 s TTFT in an in-place A/B. A repeated context, on the other hand, goes from
    5.3 s to 0.3 s, so the cache is right for chat/agent traffic and wrong for a batch of one-shot
    prompts. The traffic shape is knowable per request from the message list.

Proposed shape (implemented, see the draft PR): a TUNE k=v ... line on the serve pipe, answered
TUNED k=v ... with a refused: tail, handled between requests after the QUIT check and before the
request's busy scope; POST /v1/tune in front of it; and --conv-route off|shadow|on (default off)
that switches prompt_cache per traffic shape. shadow only labels and logs, so a deployment can
measure its own mix first.

Measurement (before/after, same engine, same config, one Arc Pro B70)

Qwen3.8-Flash-Next GSQ-RCO Coder IQ1_M, engine 0.1.58 SYCL build (bmg-g31 AOT), Chat Completions,
streaming, temperature 0, one request at a time, unique prompts:

lane cache ON (current) cache OFF (proposed for that shape)
3.5 k code prefill 1 306 tok/s 1 438 tok/s (+10.1 %)
4.0 k prose prefill 1 442 tok/s 1 499 tok/s (+4.0 %)
short single-shot TTFT 0.522 s 0.239 s
a repeated context (must not regress) 0.190 s / 20 575 tok/s 0.192 s / 20 374 tok/s

What I am asking for

Scope agreement for the shape above — one engine feature (a retune line) plus one opt-in server
policy — before it is reviewed as a PR. Two things are a maintainer's call, and I would rather ask
than guess:

  • Whether the retune belongs in the engine's serve protocol at all, or should stay a calibration-only
    tool. The same line would let tools/calibrate.py sweep a value without a restart, which is the
    feature the measurement cost is really blocking.
  • Which key set the retune should accept. Mine is "only what is read out of the options when used":
    adapt_every/adapt_swaps/adapt_decay/adapt_min_gain, pcie_frac, spec_min_p, prompt_cache,
    prompt_cache_every, short_read, and prefill_chunk downward only. Everything that sizes memory
    or the session at load (--spec, --kv*, --max-context, --expert-cache, the resident tiers,
    --pcie-mode, graph/native flags) is deliberately excluded.

Draft PR with the implementation, the tests and the full validation: link in the first comment.

AI assistance was used for the implementation and the measurement runs; the numbers above are from
runs on the hardware named.

Originally created by @rwkeyes on GitHub (Nov 7, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5515 ## Summary Two proposals that belong together, both about settings that can only change at start-up today: 1. **An in-place retune.** `--prompt-cache`, `--prompt-cache-every`, `--short-read`, `--spec-min-p`, `--pcie-frac`, `prefill_chunk` and the `adapt_*` family are all read out of the engine's options at the moment the engine uses them, but the only way to change one is to restart the engine — which on a real config also means a model load (93–100 s on the box I measure on). Measuring one value costs a start; measuring six costs six. 2. **Conversation-cache routing.** With the cache on (`--prompt-cache 6`), a single-shot request that will never reuse its context still pays the parking cost. On this box that is **+10.1 % prefill on a 3.5 k code prompt and +4.0 % on 4.0 k prose** with the cache off; short single-shot prompts went from **0.522 s to 0.239 s TTFT** in an in-place A/B. A repeated context, on the other hand, goes from 5.3 s to 0.3 s, so the cache is right for chat/agent traffic and wrong for a batch of one-shot prompts. The traffic shape is knowable per request from the message list. Proposed shape (implemented, see the draft PR): a `TUNE k=v ...` line on the serve pipe, answered `TUNED k=v ...` with a `refused:` tail, handled between requests after the QUIT check and before the request's busy scope; `POST /v1/tune` in front of it; and `--conv-route off|shadow|on` (default off) that switches `prompt_cache` per traffic shape. `shadow` only labels and logs, so a deployment can measure its own mix first. ## Measurement (before/after, same engine, same config, one Arc Pro B70) Qwen3.8-Flash-Next GSQ-RCO Coder IQ1_M, engine 0.1.58 SYCL build (`bmg-g31` AOT), Chat Completions, streaming, temperature 0, one request at a time, unique prompts: | lane | cache ON (current) | cache OFF (proposed for that shape) | |---|---:|---:| | 3.5 k code prefill | 1 306 tok/s | **1 438 tok/s (+10.1 %)** | | 4.0 k prose prefill | 1 442 tok/s | 1 499 tok/s (+4.0 %) | | short single-shot TTFT | 0.522 s | **0.239 s** | | a repeated context (must not regress) | 0.190 s / 20 575 tok/s | 0.192 s / 20 374 tok/s | ## What I am asking for Scope agreement for the shape above — one engine feature (a retune line) plus one opt-in server policy — before it is reviewed as a PR. Two things are a maintainer's call, and I would rather ask than guess: * Whether the retune belongs in the engine's serve protocol at all, or should stay a calibration-only tool. The same line would let `tools/calibrate.py` sweep a value without a restart, which is the feature the measurement cost is really blocking. * Which key set the retune should accept. Mine is "only what is read out of the options when used": `adapt_every/adapt_swaps/adapt_decay/adapt_min_gain`, `pcie_frac`, `spec_min_p`, `prompt_cache`, `prompt_cache_every`, `short_read`, and `prefill_chunk` downward only. Everything that sizes memory or the session at load (`--spec`, `--kv*`, `--max-context`, `--expert-cache`, the resident tiers, `--pcie-mode`, graph/native flags) is deliberately excluded. Draft PR with the implementation, the tests and the full validation: _link in the first comment_. AI assistance was used for the implementation and the measurement runs; the numbers above are from runs on the hardware named.
Author
Owner

@rwkeyes commented on GitHub (Nov 7, 2026):

Draft PR with the implementation, tests and the full validation: https://github.com/Niko1221/Strata/pull/5516 — draft until the two scope questions in the report above are answered.

<!-- gh-comment-id:6711564854 --> @rwkeyes commented on GitHub (Nov 7, 2026): Draft PR with the implementation, tests and the full validation: https://github.com/Niko1221/Strata/pull/5516 — draft until the two scope questions in the report above are answered.
Author
Owner

@rwkeyes commented on GitHub (Nov 7, 2026):

Related work I should flag before you spend review time on this: #4777 (@code-martin, open) adds ROUTE_PRIOR <v> as an engine stdin command for exactly this motivation — changing a routing prior without a restart — plus an endpoint in serve/server.py. It touches the same two places this proposal does:

  • Textually: the same command loop in src/program/generate.cpp (my dispatch sits after the QUIT check and before the request's busy scope) and serve/server.py. Whichever of the two merges second needs a small rebase at the dispatch, not a redesign.
  • In design: they are the same mechanism with different reach. #4777 is one setting behind one command; TUNE key=value … here is a line any use-time setting can join. If that direction is acceptable, route_prior is a natural TUNE key and the #4777 endpoint becomes POST /v1/tune {"settings": {"route_prior": …}} — one mechanism instead of two.

I am happy to rebase on #4777 and fold route_prior in as a key, or to keep out of its way if you would rather land the single-purpose command first. What I would not do is hide the overlap and let a reviewer find it.

If a general retune line is not wanted at all, say so plainly and I will close #5516: the conversation-cache routing cannot switch prompt_cache without one, so it would be dropped rather than shrunk into something smaller.

<!-- gh-comment-id:6713431257 --> @rwkeyes commented on GitHub (Nov 7, 2026): Related work I should flag before you spend review time on this: **#4777** (@code-martin, open) adds `ROUTE_PRIOR <v>` as an engine stdin command for exactly this motivation — changing a routing prior without a restart — plus an endpoint in `serve/server.py`. It touches the same two places this proposal does: * **Textually:** the same command loop in `src/program/generate.cpp` (my dispatch sits after the `QUIT` check and before the request's busy scope) and `serve/server.py`. Whichever of the two merges second needs a small rebase at the dispatch, not a redesign. * **In design:** they are the same mechanism with different reach. #4777 is one setting behind one command; `TUNE key=value …` here is a line any use-time setting can join. If that direction is acceptable, `route_prior` is a natural `TUNE` key and the #4777 endpoint becomes `POST /v1/tune {"settings": {"route_prior": …}}` — one mechanism instead of two. I am happy to rebase on #4777 and fold `route_prior` in as a key, or to keep out of its way if you would rather land the single-purpose command first. What I would not do is hide the overlap and let a reviewer find it. If a general retune line is not wanted at all, say so plainly and I will close #5516: the conversation-cache routing cannot switch `prompt_cache` without one, so it would be dropped rather than shrunk into something smaller.
Sign in to join this conversation.
No milestone
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.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5486
No description provided.