Repository navigation
Studio hands KV preemption to a llama-server that parks slots itself - #10358
danielhanchen wants to merge 292 commits into
Conversation
86f3e54 to
a5f0fca
Compare
|
Checked the gating in studio/backend/core/inference/llama_cpp.py, where server_preempts_kv needs both the --preempt-ram probe and a unified cache, so the bundled build keeps today's path and the relay only runs on the swap build. Will get this reviewed once the base branch lands. |
d7880b0 to
7044b0e
Compare
|
One more commit,
Live on the 4B with the integration server: the child's environment carries the variable and the Studio process does not, status reports on, and a 300-token prompt at seed 0 and temperature 0 gives the same 1233 bytes alone twice and beside three neighbours; with the setting off the same cell diverges at byte 78. 103 new tests; the handoff suite and 2278 tests across the preemption, start-failure and load-mode suites pass; the three failures in a wider selection are the same three on the parent commit. No frontend indicator yet; the status field is there for one. |
|
Added a visible indicator for the exact concurrency switch (fc4ad27).
|
|
One measurement worth knowing before turning the switch on. On the llama.cpp side, exact concurrency derives its kernel column bound from the slot count times one plus the draft length, so with the MTP drafts Studio loads by default a four-chat run with the mode on reaches 0.45 of the mode-off aggregate decode rate (2.1x the wall), against 0.91 with speculation off. The switch stays opt-in and off by default, and the setting's help text says it costs throughput, so nothing here changes; a follow-up could disable drafts automatically while the switch is on, which is a separate decision. |
|
Follow-up to the note above: the speculative cost was a llama.cpp batch-splitting issue, not the mode itself, and it is fixed on the llama.cpp side (unslothai/llama.cpp#194 at c6c3cb671). With two MTP drafts, four chats in exact concurrency now decode at 0.74 of the mode-off rate instead of 0.43, byte-identical to the solo run on both the 4B and the 35B, with and without parks. Nothing changes in this PR: the switch is still opt-in and off by default, and a llama-server without that commit behaves as before. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15f04316cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not metrics: | ||
| return False | ||
| try: | ||
| parked = float(metrics.get("requests_preempted", 0) or 0) > 0 |
There was a problem hiding this comment.
Scope parked-slot grace to the stalled request
When a legacy swap-capable server has multiple concurrent slots, requests_preempted > 0 only establishes that some slot is parked, not that the stream whose read timed out is that slot. If one request is legitimately parked while another request wedges, every timeout on the wedged stream receives this grace and can be extended from the normal two-minute stall limit to the 30-minute cap; the backend-wide timestamp also lets that unrelated stream renew a durable lease. Correlate the parked slot with the current request, rather than applying this server-wide count to every stream.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed. /metrics on that build is the only signal there is: the OpenAI-compatible chunks carry no slot id, so a stream cannot be matched to a slot, and /slots cannot say which of its parked entries is this request. A slot cannot stall by itself while the same decode loop serves the others, so a silent stream beside a parked one is either the parked one or a server that has stopped for everyone, and the thirty-minute cap bounds the second case. The stamp is consulted only while a run's own stream is silent, which is the same condition.
The strict locale parity check fails on the two overlays that landed on main after the setting was added.
# Conflicts: # studio/backend/core/inference/video.py # studio/backend/tests/test_preempt_resume_wastes_no_work.py
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c56c051195
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| exactConcurrencyChipApplies({ | ||
| isExternalModel, | ||
| residentCheckpoint, | ||
| modelLoading, |
There was a problem hiding this comment.
Bind the exact chip to the selected resident model
When “Keep other models loaded” is enabled and the user opens a thread pinned to another already-resident local model, loadedExactConcurrency can still describe the backend last published by a status/load response. This gate passes only external/loading state and checks merely that some residentCheckpoint exists, so it can display Model A’s “Exact” guarantee beside Model B; resident models can differ after the setting changes between their loads. Pass the selected checkpoint into the gate and match it to per-model runtime state, rather than treating any local residency as applicable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I have left this one. The chip follows the selected model's own backend. exact_concurrency is a per-backend runtime field read through _llama_runtime_fields(get_llama_cpp_backend()), and both /load and /status?model= route to the slot serving the named model first (_select_load_slot and get_status via _route_to_extra_slot). The client writes loadedExactConcurrency from the load response of the model it just selected, including a dedupe onto an already-resident kept model, and it reads status with the selected checkpoint. Opening a thread pinned to another resident model does not change the selection: ChatModelNotice only offers the switch, so the header and the chip still describe the selected model, and accepting the offer is a load that brings that model's own state. Status reads without a model argument run only when nothing is selected, and they adopt the primary as the checkpoint at the same time.
| # A batched request's notices carry the prompt index; the client reads one stream state. | ||
| notice = parse_server_park_notice(raw_line) | ||
| return None if notice is None else _SERVER_PARK_SSE_BY_COMMENT.get(": " + notice[0]) |
There was a problem hiding this comment.
Preserve indexed park state in raw chat relays
For an OpenAI chat passthrough with n > 1, llama-server can emit indexed notices such as : resumed 0 while another choice remains parked. This stateless mapping turns every indexed resume into : preempt-resumed, so the client clears its paused state even though the request is still partly parked; subsequent keepalives do not restore the paused label. The completions relay already tracks ServerParkNotices and downgrades such a resume to a keepalive, and the raw chat relay needs the same per-request indexed state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I have left this one, because a chat stream cannot carry an indexed notice. llama-server does accept n on /v1/chat/completions (an alias of n_cmpl, fanned out as child tasks), but the park scheduler never takes those slots: the victim picker, the last-resort park and the rotation path all skip is_parent() || is_child() slots, since an n_cmpl > 1 family shares one sequence. A chat request has one prompt, so anything it parks is index 0, which uses the bare : preempted / : resumed form. Indexed notices come only from a multi-prompt /v1/completions request, and that relay is the one that keeps ServerParkNotices and turns a partial resume into a keepalive.
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/core/inference/chat_generation_runs.py # studio/backend/core/inference/chat_template_helpers.py # studio/backend/core/inference/llama_admission.py # studio/backend/core/inference/llama_cpp.py # studio/backend/core/inference/llama_preemption.py # studio/backend/core/inference/llama_stats.py # studio/backend/core/inference/studio_tool_loop.py # studio/backend/routes/inference.py # studio/backend/tests/preempt_fakes.py # studio/backend/tests/test_a_declined_pause_unsticks_the_participant.py # studio/backend/tests/test_a_give_up_tells_the_client.py # studio/backend/tests/test_a_holder_streaming_its_next_tool_call_is_still_preemptable.py # studio/backend/tests/test_a_parallel_round_dedupes_healed_calls_and_freezes_its_branch.py # studio/backend/tests/test_a_pause_charges_what_the_attempt_decoded.py # studio/backend/tests/test_a_provider_round_bounds_its_overlap.py # studio/backend/tests/test_a_reasoning_only_resume_keeps_the_whole_answer.py # studio/backend/tests/test_a_waiting_chat_is_not_stuck_while_others_decode.py # studio/backend/tests/test_admission_sse_contract.py # studio/backend/tests/test_checkpoint_compaction.py # studio/backend/tests/test_declined_continuation_tells_the_client.py # studio/backend/tests/test_durable_runs_relay_the_pause.py # studio/backend/tests/test_external_tool_edge_cases.py # studio/backend/tests/test_final_answer_pass_pauses_and_resumes.py # studio/backend/tests/test_llama_admission_enforced_max_tokens.py # studio/backend/tests/test_llama_admission_enforced_paths.py # studio/backend/tests/test_llama_admission_stated_cap_overcommits.py # studio/backend/tests/test_llama_admission_unstated_max_tokens.py # studio/backend/tests/test_llama_cpp_tool_loop.py # studio/backend/tests/test_llama_preemption.py # studio/backend/tests/test_llama_preemption_is_armed_on_chat_surfaces.py # studio/backend/tests/test_llama_preemption_wiring.py # studio/backend/tests/test_llama_stream_preempt.py # studio/backend/tests/test_llama_tool_loop_preempt_resume.py # studio/backend/tests/test_parallel_round_budget_counts_launched_calls.py # studio/backend/tests/test_parked_holder_gives_its_cells_back.py # studio/backend/tests/test_preempt_resume_wastes_no_work.py # studio/backend/tests/test_preempt_signal_reaches_the_tool_loop_stream.py # studio/backend/tests/test_preempted_usage_counts_every_attempt.py # studio/backend/tests/test_preemption_matches_the_benchmarked_policy.py # studio/backend/tests/test_preemption_sweep_arithmetic.py # studio/backend/tests/test_preemption_wiring_holes.py # studio/backend/tests/test_recost_wait_is_patient_with_a_busy_leader.py # studio/backend/tests/test_research_internal_call_tool_gate.py # studio/backend/tests/test_slot_probes_are_authenticated.py # studio/backend/tests/test_studio_tool_loop.py # studio/backend/tests/test_the_batch_reserve_is_only_held_while_something_prefills.py # studio/backend/tests/test_the_final_pass_charges_each_attempt_once.py # studio/backend/tests/test_the_final_pass_stays_under_kv_control.py # studio/backend/tests/test_tool_calls_run_in_parallel.py # studio/backend/tests/test_tool_calls_within_one_turn_overlap.py # studio/backend/tests/test_tool_loop_arms_after_its_admission_wait.py # studio/frontend/src/components/assistant-ui/thread.tsx # studio/frontend/src/features/chat/api/chat-adapter.ts # studio/frontend/src/features/chat/api/chat-api.ts # studio/frontend/src/features/chat/runtime-provider.tsx # studio/frontend/src/features/chat/types/api.ts # studio/frontend/src/features/chat/utils/continuation.ts # studio/frontend/tests/admission-sse-stream.test.ts # studio/frontend/tests/admission-status.test.ts # studio/frontend/tests/chat-continuation.test.ts # studio/frontend/tests/chat-runtime-reload-status.test.ts # studio/frontend/tests/chat-save-conflict-detail.test.ts # studio/frontend/tests/continuation-paused-reason.test.ts # studio/frontend/tests/preempt-gave-up-then-answered.test.ts # studio/frontend/tests/preempt-gave-up-turn.test.ts
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/tests/test_llama_admission_enforced_max_tokens.py # studio/backend/tests/test_llama_preemption.py # studio/backend/tests/test_llama_preemption_wiring.py # studio/backend/tests/test_llama_stream_preempt.py # studio/backend/tests/test_tool_calls_run_in_parallel.py # studio/frontend/scripts/check-bundle-budget.ts
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…rs can resolve A 5 ms first-token window against a 10 ms gap sits inside one tick of the Windows timer, so the negative case sometimes saw the second chunk before the deadline fired (DID NOT RAISE ReadTimeout on windows-latest). 50 ms against 250 ms keeps both cases apart.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Stacked on #10301. Pairs with unslothai/llama.cpp#260 (the server-side parking pin on upstream b11540, which replaces #184, #190 and #210 as the pinned commit).
Summary
When the launched llama-server can park a slot in host RAM itself (
--preempt-ram, unslothai/llama.cpp#184), Studio stands its own preemption down, lets every chat use the whole context window, relays the server's: preemptedand: resumedstream comments (unslothai/llama.cpp#190) to the GUI as the existing paused line, and never mistakes a park for a stall. On the bundled upstream build, or withUNSLOTH_LLAMA_PREEMPT_MODE=studio, behaviour is exactly #10301's.Why. Studio's own preemption pauses a chat by aborting its upstream stream and resumes by re-prefilling the partial. That is exact at the seam but not byte-identical once the MTP head is involved, and it has to hold back reaction headroom (192 cells per slot plus the drafts, 776 of 8192 at four slots). The server swap restores the sequence in place, byte-identical, at N minus 8 cells. With both active Studio's lower watermark fires first and the better mechanism never runs; with Studio's off, a parked slot was a silent stream that hit the 120 s stall timeout with nothing shown to the user.
Policy
--preempt-ramfrom the existing--helpprobe,--kv-unifiedon, and no hand-typed--preempt-ram 0.UNSLOTH_LLAMA_PREEMPT_MODE=auto|studio|server, defaultauto(server when the build can). Thearmedlog line says which mode is live.UNSLOTH_LLAMA_ADMISSION_PREEMPTisautowhen unset: every launch asks a parking-capable llama-server to park (a--preempt-rambudget bounded to the host: at most a quarter of available RAM, always leaving max(4 GiB, 15 percent of total)), and preemption arms only once that server confirms parking in/props(preempt.enabled). A stock or older server, an unreadable report, or a host with no RAM to spare keeps today's fair-share admission unchanged.1forces it on,0turns it off on both sides.PARKED_ON_TOOL,context_truncatedwithfits:falseand the ledger keep working. A parked slot is left out of the resident figure, since its cells are in host RAM; counting it made a nearly empty pool read as over the ceiling and erased idle slots for room that was never short.: preemptedand: resumedinto the same pause events the Studio-side preemption yields, so the routes emit: preempt-pausedand: preempt-resumedunchanged and the GUI shows "Paused while another chat finishes". The server's 2 s: preempt-keepaliverenews the stall deadline. For a swap build without the notices, the read wrapper consults/metricsrequests_preemptedbefore treating silence as a stall, capped at 30 minutes.Results
Qwen3.5-4B with two MTP drafts,
-c 8192, four slots, seed 0, temperature 0:Qwen3.6-35B-A3B with two MTP drafts,
-c 8192, four slots:Context size has been exceeded.Exactness
Forced parks every 64 tokens (
LLAMA_SERVER_PREEMPT_EVERY=64on the child) against an unforced run, through the Studio API, 1200 tokens, MTP on:Cost when it does not fire
Solo 1200-token chats on the 4B, same build, back to back: server mode 209.4 / 192.9 tok/s, studio mode 209.2 / 192.1, server again 208.8 / 193.4. The server-mode path adds one string compare on stream lines that are not
data:. The 35B solo numbers were taken on a GPU shared with a foreign job at full utilisation and spread 14x between passes, so they are not quoted.Tests
31 new tests in
test_server_side_preemption_handoff.py(mode and property, probe, controller, stream relay on both surfaces, a park before the first token, an upstream stream without comments is bytewise today's, the read-wrapper grace) plus the parked-slot occupancy test. 737 pass across the handoff, preemption, admission, tool loop, chat generation, slot release and stream cancel suites.Limitations
--preempt-rambudget. When that budget cannot hold a victim, the paired llama-server parks it by dropping its cells and re-prefilling on resume, so Studio never re-arms its own preemption for that case.: preemptedgo out then), so a build that carriesexact_concurrencyon/propsis never asked the aggregate/metricsreading; only a swap build predating the notices keeps that fallback./metricspark reading, bounded by the 30 minute park cap.Follow-up: slimmer
Five refactor commits, behaviour and coverage unchanged: the scripted backends, recording policies, fake responses and SSE builders that ten test files each carried are one shared
tests/preempt_fakes.py; the three pause sites inllama_cpp.pyshare one charge (the larger of the observed count and the estimate) and one declined-pause helper; the eighteen spellings of the controller key inroutes/inference.pyare one_preempt_key(); the barrier, recorder and registry-reset fixtures are shared; both no-flash respawns hand exact concurrency back through one helper. 1042 test functions before and after, none removed or renamed.Two comment sweeps then cut the added comment and docstring lines from 6313 to 1871 (70 percent), the AST gate confirming only comments, docstrings and whitespace changed. Against main the PR is 101 files and 17505 insertions, from 22555.
Verified at every commit by ruff and the 1484 preemption, admission, tool-loop and resume tests, then live on the slimmed Studio with the slimmed llama-server: four Chromium tool chats through the GUI at 8k finished 4 of 4 with 9 parks and 9 resumes, the paused label on three of them and no error; four parallel tool chats through
unsloth runat 16k finished 4 of 4 with 10 pauses and no context error.Follow-up: fixes and fewer tests
Three more commits.
Resume and lease fixes (4b9c38b). A resumed attempt keeps the reasoning that preceded its prose: the assembler folds the attempt's
reasoning_contentand any reasoning a previous pause left trailing into the partial the next attempt extends, instead of dropping it once prose had started. The final pass replays its own prose rather than the cumulative display text, which carried the thought into the answer. Stop during a pause ends the wait:ControllerPreemptionPolicy.await_resumetakes the cancel event and returns as soon as it is set, through one helper at the three pause sites. A park before the first token, and the keepalives that follow it, renew the first-token deadline instead of timing it out. A pause declined at the resume cap keeps the attempt: it is charged, its partial goes back through the assembler, and the final pass extends it withcontinue_final_messageunder what is left of the caller's cap, rather than starting afresh with the whole allowance. A long pause no longer expires a durable run: the server's: preempt-keepaliveand the Studio-side wait (now a generator that says so every two seconds while the policy waits) both reach the routes as a keepalive event, forwarded as: preempt-keepalive, which the durable producer renews the run lease on at the queue-wait rate and the frontend ignores.Admission fixes (a31bc71). One predicate,
preemption_eligible(), reads the rollout switch together with the admission-control and KV-budget switches for the controller'sactiveandplan_preemptions, for pricing, for arming and for the disarm's cache erase, so an install that switched admission off no longer arms a controller policy over leases charged nothing, and the wire clamp returns None under either opt-out instead of narrowing an unstated cap.LLAMA_ARG_PREEMPT_RAM=0in the child's environment disables the server hand-off the way--preempt-ram 0on the launch line does, read in llama.cpp's own order. Exact concurrency is reportedononly on the build's own evidence: a build that ignores the variable starts perfectly, so the load reads the--preempt-ramcapability the same fork ships and reportsunavailablewithout it, which under theonsetting fails the load as designed. The passthrough, Responses and/v1/messagesraw surfaces reserve as unpausable and pay the honest price, since a stream registered as never chosen has nothing to reclaim.Fewer tests (915cba3). 44 new test files and 11009 added lines become 10 files and 4494 lines, 604 test functions become 167 plus 21 parametrisations, with every behaviour kept: the incidents folded into their surface files, and every source-level wiring check but two rewritten as behaviour (a real FastAPI app with a recording backend and a patched controller ledger for the arming on every local chat surface, a recording erasures fixture for the disarm, a policy that reads the signal inside
on_resumedfor the clear-before-resume order). The survivors were checked against five scratch mutations of the production code (the arm made a no-op, the unregister skipped, the one-shot ledger no longer clearing,on_resumedbefore the clear, settlement never compacting); each was caught. The two source-level checks kept are the frontend's declared comment set, which only the TypeScript can answer, and the respawn retry's argument forwarding, which needs a llama-server that dies and comes back.Verified: ruff and the pre-push gate clean; the admission and preemption suites 1414 passed and 5 skipped; the whole backend suite 39557 passed and 221 skipped, with every failure in diffusion, audio, video and host-topology files this PR does not touch, the non-diffusion ones failing identically on the merge base. Live on the paired llama-server: four Chromium tool chats through the GUI at 8k finished 4 of 4 with the paused label on three, 9 parks and 9 resumes, no error box and no context error;
unsloth runat 16k with MTP and exact concurrency on, four parallel tool chats, finished 4 of 4 at 191 tok/s aggregate with 5 server parks and 5 resumes and no context error, Studio reportingmode=server exact=onfor every chat.Round two of fixes (1e7f37b). The parked-slot metrics probe sends the API key, since
/metricsis not in llama-server's public set and every check under--api-keywas a 401. Stop is read before every resume grant attempt and passed into the lease's resume, so a grant that succeeds at once no longer carries a stopped chat into the wait. The wire clamp takes the samepausableflag the reservation takes, and the passthrough body is built with it off, so an uncapped passthrough is held to its share while pausable chats keep the window. The settings page shows what the next load resolves to when nothing is stored, so an inheritedLLAMA_EXACT_CONCURRENCYreads as on. Three tests added; the admission, preemption and tool-loop suites 1152 passed and 5 skipped.Round 23
Five review items plus a second round of five isolated reviews of the updated heads. Everything below was reproduced before it was changed; the reproductions are now tests.
DeferredPreemptionPolicy.await_resumetook only a timeout, so the caller'scancel_eventkeyword raisedTypeErrorand the fallback waited without Stopcancel_event; an older inner policy still worksonoff the--preempt-ramcapability, which a build without the mode can carry/propsnow carriesexact_concurrency(unslothai/llama.cpp#197)contradicting_argskept every occurrence, so--flash-attn off --flash-attn onread as a contradiction andonkilled a valid server/v1/messagesstreams droppedpreemptevents; each restarted the stall keepalive, so a long park sent no bytes/v1/messagesstreams forward the same: preempt-paused,: preempt-keepalive,: preempt-resumedcomments as the OpenAI surfaceappend_assistant_turnconcatenatesreasoning_contentlike it concatenates contentlengthToolLoopController.call_key)/v1/messagesraw passthrough sent the caller's cap or the whole window while reserved as unpausabletool_startwithout closing its cardUNSLOTH_LLAMA_ADMISSION_PREEMPT=0left the child parking on its own default budgetLLAMA_ARG_PREEMPT_RAM=0unless something named a budget--preempt-ramis re-prefilled, and a re-prefill is not byte-identical on CUDA (it is on CPU)--preempt-ramto the whole pool when the server's default would not hold it; the server warns if a re-prefill happens under the mode anyway| The raw passthrough loops (Responses, chat and completions passthrough,
/v1/messagespassthrough) relayeddata:lines only, so a request the server parked sent the client nothing for the whole park |_server_park_sseforwards the server's park notices as the same comments every other surface sends || Exact concurrency was reported
onwith Studio doing the pausing (UNSLOTH_LLAMA_PREEMPT_MODE=studio, or the server's parking off), and a chat Studio resumes is re-prefilled rather than restored | The state needs the server to be the one parking;onfails the load naming the reason,autoloads with a warning || A user-named
--preempt-rambelow the KV pool was kept and reported exact, and the first park to outgrow it is re-prefilled | The shortfall is judged at launch: a warning names the figure to raise it to, the state isunavailable, andonfails the load || A swap build predating the stream notices parks in silence, and the read wrapper's
/metricsexcuse forwarded nothing, so a durable run's lease could expire during a legitimate park | The excuse stamps the backend and the run loop renews the lease from it, with a bounded wait || A pause that landed as the caller's cap ran out folded the interrupted attempt into the accumulators and then built the terminal event from the same reading, so a four-token answer reported eight and twice its decode time | Both cap-spent sites hand the builder the attempt's prompt side only |
| An auto-fit context left the KV pool unknown at launch, so the exact launch neither enlarged the parking budget nor judged it while the state read
on| With nothing named the child parks without a limit; a named budget is judged after launch off the context the server chose, and a pool that cannot be sized is not certified || Under
auto, Studio-side pausing or parking switched off were only judged after launch, so the child ran the mode it was then reported not to have | Preflighted: the child is not given the flag, with a warning naming the reason;onstill fails the load || The raw relays read llama-server without the metrics park grace, so on a swap build predating the stream notices a parked raw request was cut off as a stall |
_aiter_llama_stream_itemstakes the backend's park probe and excuses the silence under the same thirty-minute cap || A raw relay was priced at the honest per-slot share even with the server parking slots itself, so a raw stream cost a whole slot of the window that it never used | Both entry points read
server_preempts_kvand price a raw stream at the window on a parking server; a Studio-only server keeps the share || The raw relays' first-item deadline never asked the park probe, so a raw request parked during its prefill was cut off before its first token | Both first-read timeouts take the same metrics grace as the stall after it, under the same cap |
|
UNSLOTH_LLAMA_ADMISSION_PREEMPT=0with nothing named stood the child's parking down after the auto preflight had passed it | The preflight sees the opt-out too and drops the flag with a warning || A diffusion runner was asked to reload for exact concurrency it cannot apply | The reload check returns off for a diffusion runtime |
| The raw relays' park grace retried the httpx iterator after its read timeout, and an async generator that raised is closed, so the retry got StopAsyncIteration and a parked raw request ended as if its answer were complete |
_install_park_aware_readwaits the park out on the network stream's read, below the iterators, the way the synchronous read wrapper does; a closed iterator is never retried, so a stall is an error rather than a short answer || A declined pause that had spent the caller's cap still ran the final pass, floored at one token past the cap | The decline ends the turn with
lengthwhen the cap is spent, as a granted pause does ||
UNSLOTH_LLAMA_PREEMPT_MODE=studioleft the child its default parking budget, so the server parked on its own while Studio reported it did not and no relay excused the silence | Forced Studio mode stands the child's parking down like the global opt-out; a named budget keeps its say || The park grace's cap ran from the start of the read, so a request parked at the first-token deadline was cut off after the normal window plus what was left of the cap, not the grace the backstop allows | Both read wrappers start the grace at the deadline they first crossed and bound each retry by what is left of it |
| The park probe scrapes
/metricswith a blocking read, and the async relays called it on the event loop, holding every other stream for up to three seconds | The probe runs off the loop, at the network read and above the iterator alike || The final pass's refusal to pause again built its terminal event without folding the interrupted attempt, and its not-resumed end folded it and then added the reading again | Both ends fold the attempt once and hand the builder its prompt side |
| Exact concurrency appended
--kv-unifiedafter the user's extras, so an explicit--no-kv-unifiedwas reversed by last-arg | The opt-out is kept and reported as the contradiction it is;autodoes not start a mode the extras contradict,onfails the load naming the flag || A durable run renewed a silent lease only from the stamp the read wrapper writes at its read deadline, and before the first token that deadline is the whole first-token budget, the default lease exactly, so a run parked during prefill on a swap build without the notices was cancelled while healthy | With no stamp in hand the run loop asks
/metricsitself, off the event loop and at most once in five seconds across runs, still under the wrapper's cap || The exact chip and the field docs said llama-server refused the mode when Studio had withheld it itself | They say the load is not running with it; the load warnings carry the reason |
| The launch generated
--preempt-ram -1on the guess that exact would run, and every abandoned exact attempt kept it, so a fallback load parked on an unlimited budget | No budget is generated for a pool the launch cannot size; the server's default is judged after launch || The grace cap test timed real sleeps, which overshoot on a loaded runner and read as a short grace | The test drives a fake clock advanced by exactly each window |
| A parking shortfall found after an auto-fit launch was reported as the server having come up without the mode, while /props said it ran | The warning and the
onrefusal say the mode runs but cannot hold every park, so a chat re-prefilled after such a park can differ ||
UNSLOTH_LLAMA_PREEMPT_MODE=studiowith a named--preempt-ramran both mechanisms: the stand-down read any named budget as somebody's say, andLLAMA_ARG_PREEMPT_RAM=0alone could not have won because llama.cpp applies argv after the environment | One owner pauses chats: the stand-down reads only the mode, zeroes the environment and the argv token in place, and the load warning names the flag it overrode;autono longer starts the mode on the strength of a named budget while preemption is off || The parking budget was sized from the target pool plus a margin, while the server saves the target and the MTP draft state per park and holds several parks at once, so a budget the launch certified was short with a drafter |
_exact_parking_need_mibprices both pools plus a per-park margin, times the slot count; a draft cache that cannot be sized is judged after launch rather than certified ||
--cpu-moe,--n-cpu-moeand a CPU--override-tensorwere not contradictions, though they place per-layer matmuls on a backend whose kernel selection is size dependent; and their last occurrence was taken to decide, while llama.cpp accumulates tensor overrides | All three are Studio's own contradictions (a zero--n-cpu-moeis the default spelled out); an earlier CPU placement is not taken back by a later occurrence || A park that fell to recompute under exact concurrency was invisible to the client | The server's
: recomputednotice (unslothai/llama.cpp#197) is relayed as: preempt-recomputedon every surface and to durable followers, the finalpreemptcounts ride the turn's metadata, a build that counts without the notice has it synthesised, and the exact chip names the re-prefilled answer on the chat it happened in || The stall excuse asked the aggregate
requests_preempted, which counts every request, so a neighbour's park excused any stalled stream, including one that had already resumed |ServerParkNoticesreads this stream's own: preemptedand: resumedoff the wire below the parsers; a stream that has heard a notice never falls back to the aggregate probe, which stays for a swap build predating the notices under the same cap || The base branch moved under this one: #10120's wire enforcement and the audit fixes on #10301 (the resume grant, the prompt-plus-generated ledger, the reasoning and failed-wait backports, the uncontended token path, the re-cost that prices what it sends and treats a Stop as a Stop) were not here | Merged; one wire bound carries both policies, and this branch's
pausablestays on it and on the passthrough retry, so a raw relay keeps its share unless the server parks raw streams itself || The import-hoist gate read the shared test fixtures and three unused imports as botched hoists, and missed a name loaded inside an assignment target (
app.dependency_overrides[get_current_subject] = ...) | The unused imports go, the fixtures are named once per module, and every assignment target records the names it loads, with a self-test case |Round 25
Follow-up: on by default, review fixes, single-user latency
On by default, as described under Policy. Fixes from the review rounds since:
/propsreport parked silently while Studio read its silence as a stallserver_may_parkkeeps the park probe on; admission stays fair share until the server confirms/metricsreading is taken for non-streaming bodiesonexact concurrency check that can kill itTwo single-user latency levers from a profile of Studio's own overhead, each measured ABBA on one exclusive B200 against two base sessions (A/A spread in brackets):
<,[or{(every form it removes opens with one)Two other candidates (skipping the exact count on one slot, throttling the API key
last_used_atwrite) showed no gain outside the noise and were dropped.One chat on Studio's
--parallel 4 --kv-unifiedlaunch decodes as fast as on--parallel 1. Same binary and flags, fixed prompt withcache_promptoff, configs ordered ABBA over two rounds on one exclusive B200, server-side tok/s, median [range] of 12 samples:--parallel 1--parallel 4A new chat's time to first token is also the same on both: 426 ms on 4B and 464 ms on 0.6B, 16 samples each. About 300 to 430 ms of that is llama-server saving the previous conversation to its RAM prompt cache before the new prompt starts, since
--cache-ram 0brings it down to 37 to 113 ms. That cost belongs to the server's prompt cache, not to the slot count or to this change, and turning the cache off would give up fast switching back to an earlier conversation, so the launch keeps it. Doing the save in the background in llama-server is the follow-up.Single-user cost of the whole change, main (2a9f621) against this branch, Qwen3.5-4B on one exclusive B200, sessions ordered ABBA at each slot count, median [range] over every request (main has two or three sessions per row, so its range is the noise from one session to the next):
Every median on this branch sits inside main's own spread, for the direct and
/v1paths too, so the change costs a single chat nothing measurable at one slot or four.Before / after in Studio
Four chats at once on
unsloth/Qwen3.5-4B-MTP-GGUF(UD-Q4_K_XL),-c 8192 --parallel 4, each with a ~1500 token prompt and Max Tokens at Max, so each fits alone but not all together. Both sides run the same llama-server build (unslothai/llama.cpp#260) and default settings. BEFORE is #10301, where preemption is off by default; AFTER is this branch.failed to find free space in the KV cacheretries, thenspeculative batch index ... is not inside the current sub-batchon two slots--preempt-ram 2212chosen for the host; slots parked to host RAM (about 120 MiB each) and restored in about 140 ms; one rotation of a long-parked chatFinal state of all four chats (BEFORE left, AFTER right):
One AFTER chat while the server held it parked:
Settings: the exact concurrency control
Settings > System > GGUF inference engine, from two separate installs. BEFORE is #10301's head (647c0fb), since this PR is stacked on it; AFTER is this branch (c5e6453). AFTER adds the Exact concurrency row with its description and an Auto / Off / On select, default Off;
/api/settings/exact-concurrencyanswers 404 on BEFORE andeffective: "off"on AFTER.