From 5efa5908869ca899ecc847f8bf30b790da69ccbc Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sun, 25 Oct 2026 15:33:14 +0100 Subject: [PATCH] deploy planner: 15 CPU workers (the pool's limit) and a 2 GiB workstation VRAM margin, from the measured cost of the preset (job 9p0) Co-Authored-By: Claude Sonnet 5.5 --- crates/deploy/src/reconfigure.rs | 12 ++++++------ crates/deploy/src/resources.rs | 23 +++++++++++++---------- docs/deploy.md | 6 +++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/crates/deploy/src/reconfigure.rs b/crates/deploy/src/reconfigure.rs index 06d8ea14..65ea1ec6 100644 --- a/crates/deploy/src/reconfigure.rs +++ b/crates/deploy/src/reconfigure.rs @@ -548,7 +548,7 @@ mod tests { }; let profile = Profile::builtin("rtx5090-32g").unwrap(); // `up` resolved the dedicated preset's worker count into the environment - let env = BTreeMap::from([(CPU_WORKERS_ENV.to_owned(), "8".to_owned())]); + let env = BTreeMap::from([(CPU_WORKERS_ENV.to_owned(), "15".to_owned())]); let mut config = RunConfig::new(&dirs, ports, 0, profile.clone(), env); config.base_profile = Some(profile); config @@ -772,13 +772,13 @@ mod tests { assert_eq!(ws.preset, Preset::Workstation); assert_eq!( ws.profile.gpu_budget_bytes, - 27 * GIB, - "32100 MiB free minus the 4 GiB left to the desktop" + 29 * GIB, + "32100 MiB free minus the 2 GiB left to the desktop" ); assert_eq!(ws.profile.memory.soft_floor_mib, Some(16384)); assert_eq!( ws.engine_env.get(CPU_WORKERS_ENV).map(String::as_str), - Some("8") + Some("15") ); // back: the unmodified profile is restored from the recorded base let back = plan( @@ -946,7 +946,7 @@ mod tests { .config; assert_eq!( config.engine_env.get(CPU_WORKERS_ENV).map(String::as_str), - Some("8") + Some("15") ); let changed = record_settings( &mut config, @@ -1096,6 +1096,6 @@ mod tests { assert_eq!(summary["gpu_budget_gib"], 30.0); assert_eq!(summary["preset"], "dedicated"); assert_eq!(summary["context_tokens"], 262144); - assert_eq!(summary["cpu_workers"], 8); + assert_eq!(summary["cpu_workers"], 15); } } diff --git a/crates/deploy/src/resources.rs b/crates/deploy/src/resources.rs index 0274d1d9..cdfef18e 100644 --- a/crates/deploy/src/resources.rs +++ b/crates/deploy/src/resources.rs @@ -19,10 +19,13 @@ use crate::{ const GIB: u64 = 1 << 30; const MIB: u64 = 1 << 20; -/// Decode is bound by host memory bandwidth: more CPU expert workers than this do not help (`docs/roofline.md`). -const MAX_USEFUL_WORKERS: u32 = 8; +/// The native expert pool refuses more than 15 workers, and fewer cost decode: on the 5090 replay (job 9p0) 8 workers decode 2.4 % slower than 15 +/// (136.4 against 139.8 tok/s), so the useful maximum is the pool's limit. /// VRAM the desktop/browser keeps in the workstation preset. -const WORKSTATION_VRAM_MARGIN_MIB: u64 = 4096; +const MAX_USEFUL_WORKERS: u32 = 15; +/// VRAM the desktop/browser keeps in the workstation preset. Every GiB taken from the expert tier costs decode: 3 GiB less (27 against 30 GiB) was +/// 12 % slower on the 5090 replay (job 9p0: 119.6 against 139.8 tok/s), so the margin is the 2 GiB a desktop session needs. +const WORKSTATION_VRAM_MARGIN_MIB: u64 = 2048; /// Resident host memory of a memfd-backed engine besides the archive (tokenizer, pinned buffers, CUDA host state). const ENGINE_EXTRA_BYTES: u64 = 3 * GIB; /// Host memory the mapped form keeps for the engine itself, the tokenizer and the working set of the page cache. @@ -289,7 +292,7 @@ mod tests { #[test] fn dedicated_takes_the_profile_and_caps_workers_at_the_useful_maximum() { let plan = compute(&host(32, 121, 100), Some(&gpu(32607, 32100)), &server(), Preset::Dedicated); - assert_eq!(plan.cpu_workers, Some(8)); + assert_eq!(plan.cpu_workers, Some(15)); assert_eq!(plan.gpu_budget_bytes, server().gpu_budget_bytes); assert_eq!(plan.ram_floors_mib, None); assert!(plan.problems.is_empty()); @@ -298,25 +301,25 @@ mod tests { #[test] fn workstation_leaves_cores_ram_and_vram_on_the_server() { let plan = compute(&host(32, 121, 100), Some(&gpu(32607, 32100)), &server(), Preset::Workstation); - assert_eq!(plan.cpu_workers, Some(8), "32 cores - 8 left free = 24, capped at 8"); - assert_eq!(plan.gpu_budget_bytes, 27 * GIB, "32100 MiB free - 4096 MiB, rounded down to GiB"); + assert_eq!(plan.cpu_workers, Some(15), "32 cores - 8 left free = 24, capped at the pool's 15"); + assert_eq!(plan.gpu_budget_bytes, 29 * GIB, "32100 MiB free - 2048 MiB, rounded down to GiB"); assert_eq!(plan.ram_floors_mib, Some((16384, 8192))); assert!(plan.problems.is_empty(), "{:?}", plan.problems); let mut profile = server(); let mut env = BTreeMap::new(); apply(&plan, &mut profile, &mut env, false); - assert_eq!(profile.gpu_budget_bytes, 27 * GIB); + assert_eq!(profile.gpu_budget_bytes, 29 * GIB); assert_eq!(profile.memory.soft_floor_mib, Some(16384)); assert_eq!(profile.memory.hard_floor_mib, Some(8192)); - assert_eq!(env.get(CPU_WORKERS_ENV).map(String::as_str), Some("8")); + assert_eq!(env.get(CPU_WORKERS_ENV).map(String::as_str), Some("15")); } #[test] fn workstation_on_a_16_thread_laptop_leaves_four_cores_and_scales_the_ram_target() { let plan = compute(&host(16, 24, 21), Some(&gpu(16384, 15500)), &laptop(), Preset::Workstation); - assert_eq!(plan.cpu_workers, Some(8)); + assert_eq!(plan.cpu_workers, Some(12), "16 threads - 4 left free"); assert_eq!(plan.ram_floors_mib, Some((8192, 4096))); - assert_eq!(plan.gpu_budget_bytes, 11 * GIB); + assert_eq!(plan.gpu_budget_bytes, 13 * GIB); assert!(plan.problems.is_empty(), "{:?}", plan.problems); let small = compute(&host(8, 24, 21), Some(&gpu(16384, 15500)), &laptop(), Preset::Workstation); assert_eq!(small.cpu_workers, Some(4)); diff --git a/docs/deploy.md b/docs/deploy.md index dbdce101..f0f5a5d0 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -125,11 +125,11 @@ binary built without `sm86` on such a card. All PTX is embedded in the binaries | | `dedicated` (default) | `workstation` | | --- | --- | --- | | purpose | the host belongs to the runtime | Docker, agents and the IDE share the machine | -| CPU expert workers | `min(cores - 2, 8)` | `min(cores - leave, 8)`, leave 4 cores (8 above 16 cores) | +| CPU expert workers | `min(cores - 2, 15)` | `min(cores - leave, 15)`, leave 4 cores (8 above 16 cores) | | host RAM kept free | the profile's governor floors (server: soft 4 GiB, hard 2 GiB) | soft floor 8 / 12 / 16 GiB (hosts under 32 / under 64 / from 64 GiB RAM), hard floor half of it; the profile's floors are only raised. The governor sheds the prefix cache first, then refuses new requests with 503 `memory_pressure` | -| VRAM | the profile budget | `min(profile, free - 4 GiB)` rounded down to GiB; the expert tier is sized from what remains | +| VRAM | the profile budget | `min(profile, free - 2 GiB)` rounded down to GiB; the expert tier is sized from what remains | -More than 8 CPU workers do not help (decode is bound by host memory bandwidth, `docs/roofline.md`), so on a large host the cores that `dedicated` leaves free are the spare ones, and `workstation` mainly guarantees the RAM and VRAM headroom. If the workstation target cannot be met (less than half of the profile's VRAM budget would remain) the preflight fails with the numbers; a RAM shortfall does not fail: when the pinned form (sealed archive plus engine, about 58 GiB on the server) would leave less than the free target, `up` switches the profile to the mapped form of the laptop profile: the archive stays a read-only file and the experts are memory-mapped from SSD/HDD, with `available - target - 8 GiB` of experts page-locked (`resident_budget_gib`, 0 on a small host). It prints a warning, because decode is slower than with everything in RAM. The same fallback applies to `dedicated` when the host cannot hold the pinned form at all. `--gpu-budget-gib` and explicit profile fields win over the preset. +The native expert pool takes at most 15 workers. **Measured cost of the preset on the 5090** (job 9p0, tic-tac-toe replay, 16 requests, 2 repeats, fixed window): default (30 GiB, 15 workers) 139.8 tok/s; 8 workers alone 136.4 (-2.4 %); 8 workers and a 27 GiB budget 119.6 (-14.5 %). The VRAM taken from the expert tier is what costs (about 4 % per GiB), so the workstation margin is 2 GiB, not more, and the workers are capped at 15 rather than 8. If the workstation target cannot be met (less than half of the profile's VRAM budget would remain) the preflight fails with the numbers; a RAM shortfall does not fail: when the pinned form (sealed archive plus engine, about 58 GiB on the server) would leave less than the free target, `up` switches the profile to the mapped form of the laptop profile: the archive stays a read-only file and the experts are memory-mapped from SSD/HDD, with `available - target - 8 GiB` of experts page-locked (`resident_budget_gib`, 0 on a small host). It prints a warning, because decode is slower than with everything in RAM. The same fallback applies to `dedicated` when the host cannot hold the pinned form at all. `--gpu-budget-gib` and explicit profile fields win over the preset. ## 4c. What the runtime reports (`leleka status`)