From 4d28f0a250c4e6d5900f63e4bb333fa41a75a895 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sun, 25 Oct 2026 12:42:33 +0100 Subject: [PATCH] reconfigure: kv_resident is fixed per process and cpu_workers is 1..=15 (found by live job 9r1); reconfigure takes 7 s and waits for the request in flight Co-Authored-By: Claude Sonnet 5.5 --- control-plane/src/server_api.rs | 7 ++-- crates/deploy/src/cli.rs | 8 ++--- .../src/backend_original_serve.rs | 4 +-- crates/leleka-runtime/src/serve_tuning.rs | 36 +++++++++++++------ docs/deploy.md | 8 ++--- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/control-plane/src/server_api.rs b/control-plane/src/server_api.rs index 4d6ccaaf..ba0bf4ae 100644 --- a/control-plane/src/server_api.rs +++ b/control-plane/src/server_api.rs @@ -525,9 +525,10 @@ pub async fn v1_load(State(state): State, headers: HeaderMap, body: By /// `POST /v1/reconfigure`: change the inference settings of the running engine without reloading the model (context length, /// prefix cache, prefill chunk, CPU workers...). The body is a JSON object with any of: `context_tokens`, `prefill_capacity`, -/// `kv_resident`, `prefix_cache_mib`, `prefix_cache_tail`, `prefix_cache_block`, `prefix_retention_min`, `cpu_workers`, -/// `spec_min_p`. The engine reopens its serve stack (tens of seconds; requests meanwhile wait in the queue) and the answer -/// carries the effective settings; a refused change leaves the previous settings in place. +/// `kv_resident` (only the value in force), `prefix_cache_mib`, `prefix_cache_tail`, `prefix_cache_block`, `prefix_retention_min`, +/// `cpu_workers` (1..=15), `spec_min_p`. The call waits for the request in flight, the engine reopens its serve stack (about 7 s on +/// the 5090; requests meanwhile wait in the queue) and the answer carries the effective settings; a refused change leaves the +/// previous settings in place. pub async fn v1_reconfigure(State(state): State, headers: HeaderMap, body: Bytes) -> Response { if let Err(response) = own_page_check(&state, &headers, "the engine settings can be changed") { return *response; diff --git a/crates/deploy/src/cli.rs b/crates/deploy/src/cli.rs index 9b76cc46..4543ad35 100644 --- a/crates/deploy/src/cli.rs +++ b/crates/deploy/src/cli.rs @@ -50,16 +50,16 @@ UP / PREFLIGHT OPTIONS its RAM is not required (foreground / --mode none only) --service-user NAME system unit only: account the service runs as (default leleka, created if missing) -RECONFIGURE OPTIONS (any of them; the engine reopens its serve stack in tens of seconds, the weights stay loaded; a refused change -keeps the previous settings; the VRAM budget and the preset need a restart: `leleka up`) +RECONFIGURE OPTIONS (any of them; the call waits for the request in flight, the engine reopens its serve stack in a few seconds, the weights stay +loaded; a refused change keeps the previous settings; the VRAM budget, the preset and --kv-resident need a restart: `leleka up`) --context-tokens N tokens of context (1..262144) --prefill-capacity N prefill chunk: 256 512 1024 2048 3072 4096 6144 8192 - --kv-resident N K/V cells kept in VRAM per layer (0 = all, else >= 20480) + --kv-resident N only the value in force is accepted (the K/V window is fixed per process; restart to change it) --prefix-cache-mib auto|off|N host-RAM budget of the cross-session prefix cache --prefix-cache-tail off|prompt|reply request-end checkpoints --prefix-cache-block N tokens per prefix block (multiple of 256; 0 = the prefill chunk) --prefix-retention-min N minutes an idle cached session is kept (0 = no limit) - --cpu-workers N CPU expert workers (1..64) + --cpu-workers N CPU expert workers (1..15) --spec-min-p P draft-probability floor (0..1) --assets/--state-dir/--prefix/--api-port/--json as for `up`; `leleka status` prints the settings in force diff --git a/crates/leleka-runtime/src/backend_original_serve.rs b/crates/leleka-runtime/src/backend_original_serve.rs index 4b2cf661..06e1140e 100644 --- a/crates/leleka-runtime/src/backend_original_serve.rs +++ b/crates/leleka-runtime/src/backend_original_serve.rs @@ -163,9 +163,9 @@ impl Default for OriginalServeOptions { impl OriginalServeOptions { /// `validate` for the run-time tuning (`serve_tuning.rs`), which reports a plain message. pub fn validate_for_tuning(&self) -> Result<(), String> { - let workers_ok = self.cpu_workers.is_none_or(|w| (1..=64).contains(&w)); + let workers_ok = self.cpu_workers.is_none_or(|w| (1..=15).contains(&w)); if !workers_ok { - return Err("cpu_workers must be 1..=64".into()); + return Err("cpu_workers must be 1..=15".into()); } self.validate().map_err(|error| error.message) } diff --git a/crates/leleka-runtime/src/serve_tuning.rs b/crates/leleka-runtime/src/serve_tuning.rs index 506f3fe2..77472900 100644 --- a/crates/leleka-runtime/src/serve_tuning.rs +++ b/crates/leleka-runtime/src/serve_tuning.rs @@ -3,14 +3,17 @@ //! //! The document is a JSON object whose members are all optional; an absent member keeps its current value. What can change without //! reloading the model: the context length, the prefill chunk, the resident K/V window, the prefix cache (host RAM budget, request-end -//! checkpoints, block, retention), the CPU expert workers and the draft-probability floor. What cannot (it is fixed when the CUDA -//! context is created): the VRAM budget; that takes a restart (`leleka up`). +//! checkpoints, block, retention), the CPU expert workers (1..=15, the native pool's limit) and the draft-probability floor. What cannot: +//! the VRAM budget (fixed when the CUDA context is created) and the resident K/V window (`kv_resident`, configured once per process, +//! live job 9r1); those take a restart (`leleka up`). use crate::backend::{OriginalServeOptions, PrefixCacheOptions, PrefixTail}; use serde::Deserialize; use serde_json::{Value, json}; /// The admitted prefill chunk sizes of the Original path (`OriginalServeOptions::validate`). const CAPACITIES: [usize; 8] = [256, 512, 1024, 2048, 3072, 4096, 6144, 8192]; +/// QSA K/V cells per layer kept in VRAM when `--kv-resident` is not given. +const DEFAULT_KV_RESIDENT: usize = 32_768; /// The context ceiling of the Original serve path. pub const MAX_CONTEXT_TOKENS: u32 = 262_144; @@ -21,7 +24,8 @@ pub struct Tuning { pub context_tokens: Option, /// Prompt chunk of the batched prefill; also the default prefix-cache block. pub prefill_capacity: Option, - /// QSA K/V cells kept in VRAM per layer (0 = the whole context; at least 20480 otherwise). + /// QSA K/V cells kept in VRAM per layer (0 = the whole context; at least 20480 otherwise). Fixed for the life of the process: + /// only the value already in force is accepted; a different one needs a restart. pub kv_resident: Option, /// Host-RAM budget of the prefix cache: `"auto"`, `"off"` (or `"0"`), or a size in MiB. pub prefix_cache_mib: Option, @@ -31,7 +35,7 @@ pub struct Tuning { pub prefix_cache_block: Option, /// Minutes an unused cached session is kept (0 = no time limit). pub prefix_retention_min: Option, - /// CPU expert workers (1..=64). + /// CPU expert workers (1..=15: the native pool refuses more). pub cpu_workers: Option, /// Draft-probability floor of a speculative window (0..=1). pub spec_min_p: Option, @@ -73,14 +77,14 @@ impl Tuning { if cells != 0 && cells < 20_480 { return Err("kv_resident must be 0 (the whole context) or at least 20480".into()); } - if Some(cells) != next.kv_resident { - changed.push("kv_resident"); + let in_force = next.kv_resident.unwrap_or(DEFAULT_KV_RESIDENT); + if cells != in_force { + return Err(format!("kv_resident is fixed for the life of the process (now {in_force}); change it with a restart (`leleka up --kv-resident`)")); } - next.kv_resident = Some(cells); } if let Some(workers) = self.cpu_workers { - if !(1..=64).contains(&workers) { - return Err("cpu_workers must be 1..=64".into()); + if !(1..=15).contains(&workers) { + return Err("cpu_workers must be 1..=15 (the native expert pool refuses more)".into()); } if Some(workers) != next.cpu_workers { changed.push("cpu_workers"); @@ -167,7 +171,7 @@ pub fn describe(options: &OriginalServeOptions, context_tokens: u32, cpu_workers json!({ "context_tokens": context_tokens, "prefill_capacity": options.prefill_capacity.unwrap_or(2048), - "kv_resident": options.kv_resident.unwrap_or(32_768), + "kv_resident": options.kv_resident.unwrap_or(DEFAULT_KV_RESIDENT), "cpu_workers": cpu_workers_effective, "spec_min_p": options.spec_min_p, "prefix_cache": prefix, @@ -219,7 +223,9 @@ mod tests { r#"{"context_tokens":300000}"#, r#"{"prefill_capacity":5000}"#, r#"{"kv_resident":1000}"#, + r#"{"kv_resident":0}"#, // fixed per process: only the value in force is accepted r#"{"cpu_workers":0}"#, + r#"{"cpu_workers":16}"#, r#"{"spec_min_p":1.5}"#, r#"{"prefix_cache_tail":"always"}"#, r#"{"prefix_cache_mib":"lots"}"#, @@ -234,6 +240,16 @@ mod tests { } } + #[test] + fn the_resident_kv_window_is_accepted_only_at_the_value_in_force() { + let (mut options, mut context) = base(); + let changed = Tuning::parse(r#"{"kv_resident":32768,"context_tokens":100000}"#).unwrap().apply(&mut options, &mut context).unwrap(); + assert_eq!(changed, vec!["context_tokens"]); + options.kv_resident = Some(40_960); + assert!(Tuning::parse(r#"{"kv_resident":32768}"#).unwrap().apply(&mut options, &mut context).unwrap_err().contains("restart")); + assert!(Tuning::parse(r#"{"kv_resident":40960,"prefill_capacity":4096}"#).unwrap().apply(&mut options, &mut context).is_ok()); + } + #[test] fn the_prefix_cache_can_be_switched_off_and_back_on() { let (mut options, mut context) = base(); diff --git a/docs/deploy.md b/docs/deploy.md index 279e2129..ac678ad5 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -148,8 +148,8 @@ Prefill rate counts the tokens actually prefilled (prompt minus reused). Rates a ## 4d. Changing the runtime settings (`leleka reconfigure`) The engine can be re-initialised while it runs: it closes its serve stack and opens a new one with other settings, **without reloading the -weights, the CUDA context or the sealed archive** (about 25 s on the 5090 instead of the 3-5 minute start). Requests that arrive meanwhile wait in the -gateway queue; a request in flight makes the call fail with HTTP 409 (nothing changes). If the new stack cannot open (for example the VRAM +weights, the CUDA context or the sealed archive** (**7 s** on the 5090 instead of the 3-5 minute start, live job 9r1). The call waits for the request in flight; requests that arrive meanwhile wait in the +gateway queue. If the new stack cannot open (for example the VRAM does not hold a larger context) the previous settings are reopened and the call answers `reconfigure refused: ...; the previous settings are back`. ```sh @@ -161,11 +161,11 @@ leleka status # prints "settings in force" with the engine telemetry | --- | --- | --- | | `--context-tokens N` | context length (prompt plus output of one request) | 1..262144; bounded by the VRAM left for the K/V window | | `--prefill-capacity N` | prefill chunk (256 ... 8192) | 8192 prefills a cold 100k prompt about twice as fast as 2048; takes VRAM from the expert cache | -| `--kv-resident N` | K/V cells per layer kept in VRAM | 0 = all, else at least 20480 | +| `--kv-resident N` | K/V cells per layer kept in VRAM | fixed for the life of the process: only the value in force is accepted (a different one needs a restart; 9r1 showed the engine refuses it) | | `--prefix-cache-mib auto\|off\|N` | host-RAM budget of the cross-session prefix cache | `off` drops the cache | | `--prefix-cache-tail off\|prompt\|reply` | request-end checkpoints | `docs/prefix-cache.md` | | `--prefix-cache-block N`, `--prefix-retention-min N` | block / grid size, minutes an idle session is kept | | -| `--cpu-workers N` | CPU expert workers | the resources the engine takes on the host | +| `--cpu-workers N` | CPU expert workers (1..=15, the native pool's limit; the engine default is 15) | the resources the engine takes on the host | | `--spec-min-p P` | draft-probability floor | | The same call is `POST /v1/reconfigure` with the JSON document (`{"context_tokens": 131072, ...}`; same bearer key; the answer carries the