mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5516] [Engine] serve: in-place retune (TUNE) and conversation-cache routing by traffic shape #5490
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5490
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5516
Author: @rwkeyes
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:serve/in-place-tune-and-cache-routing📝 Commits (2)
21a634eengine: retune the running engine between requests (a TUNE line)e929c26serve: POST /v1/tune, and route the prompt cache by traffic shape📊 Changes
6 files changed (+677 additions, -0 deletions)
View changed files
➕
serve/conv_router.py(+126 -0)📝
serve/server.py(+157 -0)➕
serve/test_conv_router.py(+113 -0)➕
serve/test_tune.py(+146 -0)📝
src/program/generate.cpp(+69 -0)📝
sycl/src/program/generate.cpp(+66 -0)📄 Description
Problem and result
Two settings live behind an engine restart today, and one of them is worth a lot on the traffic this
server actually sees:
prompt_cache,prompt_cache_every,short_read,spec_min_p,pcie_frac,prefill_chunkand theadapt_*family are read out of the engine's options at themoment the engine uses them, yet changing one restarts the engine — and with it a model load
(93–100 s measured here). Measuring one value costs a start; a sweep costs one per candidate.
--prompt-cache 6, a request thatwill never reuse its context still pays the parking cost. Cache off is +10.1 % prefill on 3.5 k
code and +4.0 % on 4.0 k prose, and short single-shot prompts go from 0.522 s to 0.239 s TTFT.
A context that is reused goes from 5.3 s to 0.3 s with the cache on, so the cache is right for
chat/agent traffic and wrong for a batch of one-shot prompts — and the message list says which one
a request is.
Result: a retune line on the serve pipe,
POST /v1/tunein front of it, and an opt-in--conv-route off|shadow|on(default off) that switchesprompt_cacheper traffic shape.Measured on this tree (stock
146df3c4+ these two commits), Arc Pro B70, engine 0.1.58 SYCL,Qwen3.8-Flash-Next IQ1_M, temperature 0, one request at a time:
--conv-route off--conv-route on--conv-route-batch-afterPOST /v1/tuneround trip on the same run:{"settings":{"prompt_cache":0,"spec_min_p":0.4}}→{"applied":{"prompt_cache":0,"spec_min_p":0.4},"refused":[]};{"settings":{"spec":4}}→{"applied":{},"refused":["spec=4"]}(a start-up-only key is refused, per key,not silently ignored).
The empty answers in the extraction lane are expected on this tree: it is stock + these two commits,
without the thinking policy from #5512, so a 24-token budget still goes into the reasoning block. That
is the other PR; nothing here changes answer content, and the lanes above differ only in cache state.
Related discussion
Issue: #5515 — the problem, the proposed shape, and the two questions I would like a maintainer's
answer on before this is anything more than a draft (whether a retune belongs in the serve protocol at
all, and which key set it should accept). This PR is that implementation, kept in draft until the
scope question is answered.
Independent of #5512 (thinking budget by prompt): different regions of
serve/server.py, no sharedlines, and either can land without the other — though the two together are what make the short-answer
lanes both fast and non-empty.
Approach
Two commits:
engine: retune the running engine between requests (a TUNE line)TUNE k=v ...on the serve pipe →TUNED k=v ...with arefused: k=v(why)tail. Same handler insrc/program/generate.cpp(CUDA/HIP) and the DPCT copy insycl/src/program/generate.cpp. Thedispatch sits after the QUIT check and before the request's busy scope, so nothing is in flight
when a field is written — that is what makes it safe without a lock. The key set is only what is read
out of the options when used:
adapt_every,adapt_swaps,adapt_decay,adapt_min_gain(src/ only —the DPCT copy has no such field),
pcie_frac,spec_min_p,prompt_cache,prompt_cache_every,short_read, andprefill_chunkdownward only (its buffers were sized at start-up). Everythingthat sizes memory or the session at load is deliberately absent:
--spec,--kv*,--max-context,--expert-cacheand the resident tiers,--pcie-mode, graph/native flags.serve: POST /v1/tune, and route the prompt cache by traffic shapeStrataEngine.tune()writes the line and parses the reply (TUNED→ applied/refused,ERR→ValueError, silence →EngineDied).Service.tune()takes the FIFO and, with--batch, the engine'scontrol line, exactly as
Service.vram()already does, so a retune never lands mid-request.POST /v1/tunereturns 200 applied/refused, 409 while a request holds the engine, 400 for a malformedbody, 503 when the engine is gone.
serve/conv_router.pyis the decision, and it is deliberately biased to keeping the cache: more thanone user turn, tools, or a prefix seen recently → on; a run of
--conv-route-batch-after(4)single-shot never-seen prompts → off; one conversational request switches it straight back. A wrong
"off" costs one full re-prefill on the next repeat, a wrong "on" costs the prefill share — that
asymmetry is why the counter is a run and not a single request. A switch needs the FIFO within 1 s, so
a retune that cannot get it is counted as
refusedand skipped rather than delaying the request.shadowlabels and logs only, so a deployment can measure its own mix first. Counters are reportedunder
conv_routeinGET /v1/status.Validation
Passed:
e929c26:cmake -S sycl -B build-sycl-aot -DSTRATA_SYCL_AOT=bmg-g31,ninja -j10→ engine 108 MB,--helprc=0, AOT device images embedded. 17 m 30 s cold.
cmake -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89(CUDA 12.6) thenninja CMakeFiles/strata.dir/src/program/generate.cpp.o→ object produced (2.45 MB), warnings only.-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_COMPILER=/opt/rocm-7.1.1/llvm/bin/clang++ -DCMAKE_HIP_ARCHITECTURES=gfx1100 -Dhip_DIR=/opt/rocm-7.1.1/lib/cmake/hip -DCMAKE_CXX_FLAGS=-D__HIP_PLATFORM_AMD__=1then the sameobject target → object produced (2.48 MB). Two notes for the tree, both pre-existing and untouched by
this PR: the plain-CMake HIP configure needs
hip_DIR(viasetup.pyit is found), and the hostcompile of that TU needs
__HIP_PLATFORM_AMD__(the repo's own setup path defines it). Alsosrc/kernels/cuda/iq_kernels.cuhas two__shared__ alignas(16) int4sites that HIP clang rejects(#778) — I did not touch them and did not include a fix, since it is a different problem.
--conv-route offandon,same config otherwise,
POST /v1/tuneexercised in both arms (applied and refused paths).python -m pytest -q serve/test_tune.py serve/test_conv_router.py→ 22 passed.python -m unittest discover -s serve -p 'test_*.py'→ 1521 tests, 613 s, 17 skipped, 1 failure;the failure is
test_server.test_hip_ordinal('0,1' != '1,0'), which fails identically on anunpatched
146df3c4worktree. Log kept.Failed: none observed beyond the pre-existing
test_hip_ordinal.Not run:
the engine. Both backends' changed translation units compile; neither was executed.
--batch/multi-slot run:Service.tune()takes the engine's control line when--batchis on,following
Service.vram(), but I did not exercise a batching configuration.Limits
that arrives right after four single-shot requests loses the cache for that one request and pays it
back on the next repeat, which is the documented asymmetry;
shadowexists to measure that rate onreal traffic before turning it on.
use time, but a key that sizes memory cannot join it — a future
--specor--kv-residentchange isstill a restart, and the reply now says so per key instead of failing invisibly.
batch_after,the repeat window) are defaults from one workload, not universal constants.
AI assistance was used for the implementation and the measurement runs. Every number is from a run on
the hardware named, and the commands are in this body.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.