diff --git a/core/continuum-serving/src/modules/serving_daemon/launch.rs b/core/continuum-serving/src/modules/serving_daemon/launch.rs index 37c3877320..b2fa8ace4a 100644 --- a/core/continuum-serving/src/modules/serving_daemon/launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/launch.rs @@ -21,23 +21,20 @@ impl ServingDaemonModule { /// /// The launch decides only the pool's size; no mind's window comes from it. Each mind's /// window is her grant from her measured requirement (`grants.rs`), and under `--kv-unified` - /// any one sequence may grow into the whole pool. The pool is the most memory the plan's own - /// arithmetic proves fits: its window x its lanes, or its fit at the sequences (a window - /// within the budget for each), whichever is larger. The sequences are every seated mind, - /// the minds leased in at the last plan, and the scratch traffic, so seating never relaunches. - /// On the M5 (plan 2 x 128,768) that is 257,536 for 5; on the IntelMac (plan 2 x 32,768, - /// fit 9 x 32,768) 294,912 for 9, what it serves healthy today. Dividing the pool by the - /// sequences as each mind's window gave the M5 5 x 10,803 (b03d7c5bc) and would have given - /// the IntelMac 7,281 against 13-30k acts (Joel, 2026-11-03: "System accommodates it doesn't - /// do stupid division"). + /// any one sequence may grow into the whole pool. The sequences are every seated mind, the + /// minds leased in at the last plan, and the scratch traffic, so seating never relaunches. + /// The size is [`launch_pool`] at the host's PHYSICAL budget, never the plan's live one. fn engine_pool(&self, model: &crate::model_registry::types::Model, served_ctx: u32, lanes: u32) -> (u32, u32) { let leased_in = LAST_LEASED_IN_PEAK.load(Ordering::Relaxed); let sequences = self.seated().saturating_add(1).saturating_add(leased_in).max(lanes).max(1); - let budget = self.plan_budget_bytes.load(Ordering::Relaxed); - let plan_pool = u64::from(served_ctx) * u64::from(lanes); - let fit_pool = footprint_for(model) - .map_or(0, |fp| u64::from(fp.window_within(budget, sequences).min(model.context_window)) * u64::from(sequences)); // map_or: no footprint proves no fit beyond the plan's own pool - let pool = plan_pool.max(fit_pool); + let pool = launch_pool( + footprint_for(model).as_ref(), + self.physical_budget().usable_bytes, + served_ctx, + lanes, + sequences, + model.context_window, + ); // `-c` is the CLI's `slots x per-slot`: the pool carried in that shape, not anyone's window. let per_slot = u32::try_from(pool / u64::from(sequences)).unwrap_or(u32::MAX); // unwrap_or: a pool over u32 x sequences is no real engine; the CLI caps it (per_slot, sequences) @@ -704,3 +701,29 @@ impl ServingDaemonModule { })) } } + +/// The pool an engine launches with: the most memory the host's measured capacity proves fits. +/// That is the fit at `sequences` (a window within `budget_bytes` for each, capped at the trained +/// window) or the plan's own window x its lanes, whichever is larger. +/// +/// `budget_bytes` is the PHYSICAL budget (`physical_budget`, the capacity `launch_window` bounds by +/// too), never the plan's live one. The engine launches once and is never relaunched to resize, so +/// a pool sized at a transient is kept for the engine's life: b4be7bc59 launched the M5 at +/// 5 x 2,048 from the cold boot plan, whose window was the bootstrap 2,048 and whose live budget +/// fit nothing at five sequences (2026-11-03 18:18Z, rolled back; Cormac on #5733). On the M5 +/// (plan 2 x 128,768) the result is 257,536 for 5; on the IntelMac (plan 2 x 32,768, fit +/// 9 x 32,768) 294,912 for 9, its healthy geometry. +pub(super) fn launch_pool( + footprint: Option<&crate::inference::planning::serving_plan::ModelFootprint>, + budget_bytes: u64, + plan_window: u32, + lanes: u32, + sequences: u32, + trained_window: u32, +) -> u64 { + let plan_pool = u64::from(plan_window) * u64::from(lanes); + let fit_pool = footprint.map_or(0, |fp| { + u64::from(fp.window_within(budget_bytes, sequences).min(trained_window)) * u64::from(sequences) + }); // map_or: no footprint proves no fit beyond the plan's own pool + plan_pool.max(fit_pool) +} diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs b/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs index b212ddd61b..16e63bae75 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs @@ -112,3 +112,25 @@ fn model_swap_on_a_ready_lane_needs_a_sustained_streak() { ModelChangeGate::NotAChange ); } + +// what this catches (b4be7bc59 on the M5, 2026-11-03 18:18Z, rolled back): a launch pool sized +// from the cold boot plan. Its window was the bootstrap 2,048 and the plan's live budget fit +// nothing at five sequences, so the engine launched at 5 x 2,048, and one launch is never +// relaunched to resize. On the boot plan the pool is the fit at the physical budget, never the +// plan's 2,048 (Cormac on #5733). Fixed inputs, so the result never depends on the host's RAM +// (Cormac on #5739): the M5's model (20.69 GB weights, 8,317 B/token, read 11-03 12:51Z), a fixed +// 96 GB physical budget, the boot plan (2,048 x 1), five sequences. +#[test] +fn the_launch_pool_never_comes_from_the_boot_plan() { + let trained = 262_144; + let mut fp = footprint_from_parts("ggml-org/Qwen3.6-35B-A3B-GGUF", 20_690_000_000, trained, true, None) + .expect("a footprint from the weights"); + fp.kv_per_token = 8_317; + let physical = 96 * GB; + let fit = u64::from(fp.window_within(physical, 5).min(trained)) * 5; + assert!(fit > 2_048, "the physical budget fits more than the bootstrap window: {fit}"); + let launch_pool = super::super::launch::launch_pool; + assert_eq!(launch_pool(Some(&fp), physical, 2_048, 1, 5, trained), fit, "the pool is the physical fit, not the boot plan"); + assert_eq!(launch_pool(Some(&fp), 0, 2_048, 1, 5, trained), 2_048, "what b4be7bc59 fed it: a zero budget leaves only the boot plan"); + assert_eq!(launch_pool(None, physical, 128_768, 2, 5, trained), 257_536, "no footprint: the plan's own window x lanes"); +}