From cdf284c9c34ace3ffd5f9d220980f649730686d1 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 16 Oct 2026 21:56:41 +0200 Subject: [PATCH 1/6] docs(serve): round-overhead A/B record (jobs 800-803) Co-Authored-By: Claude Opus 5.5 --- docs/original-serve.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/original-serve.md b/docs/original-serve.md index c25bc4aa..87ccacf2 100644 --- a/docs/original-serve.md +++ b/docs/original-serve.md @@ -255,3 +255,39 @@ With `STRATA_CKPT_REREAD=1` (separate process) F, S and Q2 re-read are token-ide (S: same chunks, unlike the full read); P differs because the re-read from 0 also cuts the root boundary. The existing serve smoke passes with the cache on by default. Job 412 (same requests, cache off) shows the stack is deterministic within and across processes for identical inputs and identical chunks. + +## Round overhead (jobs 800-804) + +RTX 5090, Ryzen 9 9950X3D, driver 595.99.02; one binary per job with A/B environment switches; 6 prompts of +`~/work/gpu-runs/prompts.txt` x 2 passes x 128 greedy tokens (`LELEKA_SMOKE_MIN_P=0.5`), expert tier on (2048 slots, +per layer, profile, `PCIE_FRAC=0.55`), `LELEKA_SERVE_PROFILE=1`. "Static" = `LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=0` +(placement independent of copy timing, so arms are compared token for token). Per-round figures are profile sums +over the 12 corpus requests divided by their rounds. + +Job 803 (round-overhead 3e8e10e on port-gpu-bringup f845d86, static, arms A B C D D C B A): + +| arm | decode tok/s (12 req) | ms/round | window | PCIe plan | publish | draft | vs old | +| --- | --- | --- | --- | --- | --- | --- | --- | +| old (serial publish, no overlap, DMA) | 47.5 / 47.4 | 52.5 / 52.6 | 50.0 / 50.1 | 2.36 | 0.24 | 2.48 | - | +| new (all three) | 49.1 / 49.2 | 50.8 / 50.6 | 48.6 / 48.4 | 0.10 | 0.20 | 2.19 | 12/12 identical (x2) | +| new, DMA staging | 49.1 / 47.7 | 51.0 / 52.3 | 48.8 / 50.0 | 2.24-2.34 | 0.17 | 2.18 | 10/12, 12/12 | +| new, no overlap | 48.9 / 48.9 | 50.9 / 50.9 | 48.5 / 48.5 | 0.09 | 0.19 | 2.44 | 12/12 identical (x2) | + +"Identical" = every corpus request's tokens and round count, plus the smoke's greedy, seeded-sampled and short +requests. The 10/12 DMA arm differs from its own repeat as well: the two other DMA-staged arms (old x2, DMA-2) agree. +TTFT is unchanged by these (793-803 ms means; the conversation cache resumes pass 1). + +With the adaptive tier (default) the fenced publication removed the per-round context synchronizes (publish 1.9 -> +0.2 ms, draft 3.3 -> 2.2 ms) but the swap copies then overlap the next window and its CPU share (CPU pool +1-2 +ms/round; 62.6 / 63.8 vs 63.7 / 64.4 tok/s with `LELEKA_SERVE_PUBLISH=serial`); the swaps are now awaited at the +round start (3eb7405, job 804). + +Job 802 (`--pcie-frac` 0 vs 0.55 with the copy kernel, adaptive, a b b a): 41.9 / 42.7 vs 62.2 / 63.6 tok/s, TTFT +1214 / 1209 vs 1212 / 1207 ms; the default is now 0.55 (placement differs, so tokens do). + +Job 801: queueing the prompt's lent-slot refill beside the window capture saved nothing (TTFT 1215 vs 1218 ms; the +~49 ms is host span validation) and was reverted. + +Job 800 profile of the old path (adaptive, before the merge of f845d86) per round: window 36.6 ms (CPU share 25.0, +PCIe plan 1.6 of it), publish 1.3 (twelve checkpoints, each with a context synchronize that waits for the swaps), +draft 3.5; per request: verifier assembly 111 ms (canonical GDN upload 17, seven graph captures 92), teardown 13. From 973e0d2fdfec7faba7c7872082a0124f9ac97fc7 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 16 Oct 2026 21:58:46 +0200 Subject: [PATCH 2/6] feat(serve): --dump-routing for the expert-cache profile (LELEKA_ORIGINAL_SERVE_DUMP_ROUTING) generate.cpp's --dump-routing writes every routed expert so tools/make_profile.py can rank the (layer, expert) pairs a workload uses; the expert-cache profile then decides what starts resident. The port's tier writes the same records (layer, k, ids, weights) for every decode window row it serves (prompt routing is not traced). Off unless the variable names a file. Co-Authored-By: Claude Opus 5.5 --- .../qwen_forward/original_serve_residency.rs | 34 ++++++++++++++++++- .../src/qwen_forward/original_serve_stack.rs | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs b/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs index 654151ca..05e3999a 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs @@ -343,10 +343,41 @@ impl ResidencyStats { pub(crate) struct ResidencyState { usage: Vec, pub(crate) stats: ResidencyStats, + /// generate.cpp `--dump-routing FILE` (`LELEKA_ORIGINAL_SERVE_DUMP_ROUTING`): every decode window row's routed + /// experts, as `tools/make_profile.py` reads them (layer i32, k i32, k ids i32, k weights f32). + routing: Option>, } impl ResidencyState { pub(crate) fn new(config: &ExpertTierConfig) -> Self { - Self { usage: if config.adaptive() { vec![0.0; LAYERS * EXPERTS] } else { Vec::new() }, stats: ResidencyStats::default() } + let routing = std::env::var_os("LELEKA_ORIGINAL_SERVE_DUMP_ROUTING") + .and_then(|path| std::fs::File::create(path).ok()) + .map(std::io::BufWriter::new); + Self { + usage: if config.adaptive() { vec![0.0; LAYERS * EXPERTS] } else { Vec::new() }, + stats: ResidencyStats::default(), + routing, + } + } + /// Write the buffered routing records out (end of a request). + pub(crate) fn flush_routing(&mut self) { + if let Some(routing) = self.routing.as_mut() { + let _ = std::io::Write::flush(routing); + } + } + fn record_routing(&mut self, layer: usize, ids: &[i32], weights: &[f32]) { + let Some(routing) = self.routing.as_mut() else { return }; + if ids.len() != weights.len() { + return; + } + let mut record = Vec::with_capacity(8 + 8 * TOP_K); + for (row, w) in ids.chunks_exact(TOP_K).zip(weights.chunks_exact(TOP_K)) { + record.clear(); + record.extend_from_slice(&(layer as i32).to_le_bytes()); + record.extend_from_slice(&(TOP_K as i32).to_le_bytes()); + row.iter().for_each(|e| record.extend_from_slice(&e.to_le_bytes())); + w.iter().for_each(|x| record.extend_from_slice(&x.to_le_bytes())); + let _ = std::io::Write::write_all(routing, &record); + } } } @@ -375,6 +406,7 @@ impl<'ctx> OriginalServePool<'ctx> for GpuExpertPool<'_, '_, 'ctx> { return Err(Error::InvalidDimension); } let mut clock = super::original_serve_pool::window_trace::now(); + self.state.record_routing(layer, rows.ids, rows.route_weights); if !self.state.usage.is_empty() { for &e in rows.ids { if (0..EXPERTS as i32).contains(&e) { diff --git a/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs b/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs index 435c7607..681b568a 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs @@ -1010,6 +1010,7 @@ impl<'a, 'ctx> RequestOwners for OriginalServeStack<'a, 'ctx> { profile::add("mtp.instantiate", instantiate_ms); profile::add("prefill.phase", self.timing.0); profile::report("request"); + self.residency.flush_routing(); result } fn finish(&mut self, ended: std::result::Result<(), ServeError>) { From c45bcaafd71cde5ed17cbd538796200093c7dd3b Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 16 Oct 2026 23:17:36 +0200 Subject: [PATCH 3/6] Revert "perf(serve): update the previous verifier's graph executables instead of instantiating anew" Job 804 (RTX 5090, rt-b8): with the parked executables on (the default), both arms broke the stack in the smoke's cancellation sequence (a window failed with CudaExecution after a few requests, the stack went Broken) while every arm with LELEKA_GRAPH_EXEC_REUSE=off passed. The executable update path is withdrawn; the instantiation it would have saved is ~21 ms per request. Co-Authored-By: Claude Opus 5.5 --- crates/cuda-driver/src/lib.rs | 22 ------ .../cuda-driver/src/original_gpu_schedule.rs | 70 +------------------ .../src/original_gpu_schedule_ffi.rs | 26 ------- 3 files changed, 3 insertions(+), 115 deletions(-) diff --git a/crates/cuda-driver/src/lib.rs b/crates/cuda-driver/src/lib.rs index b10a9d26..66b4dffe 100644 --- a/crates/cuda-driver/src/lib.rs +++ b/crates/cuda-driver/src/lib.rs @@ -419,7 +419,6 @@ impl<'driver> Device<'driver> { kar_levels: Cell::new(None), experimental: std::array::from_fn(|_| Cell::new(None)), window_modules: RefCell::new(Vec::new()), - parked_execs: RefCell::new(Vec::new()), }) } } @@ -471,9 +470,6 @@ pub struct Context<'driver> { /// Sealed verify-window modules loaded under this context, shared by every verifier bank created later /// (the serve path assembles one per request) and unloaded with the context. window_modules: RefCell, Vec<&'static str>)>>, - /// Drained verifier graph executables kept for the next verifier's graphs of the same shape (destroyed with - /// the context). - parked_execs: RefCell>, } #[derive(Clone, Copy)] struct FixedKernel { @@ -2093,22 +2089,6 @@ impl Context<'_> { } /// The shared verify-window modules: unloaded (current context) once no bank holds them; a module a live /// bank still shares is left to that bank's own unload. - fn destroy_parked_execs(&mut self) -> Result<()> { - let parked = std::mem::take(self.parked_execs.get_mut()); - if parked.is_empty() { - return Ok(()); - } - if self.is_poisoned() { - std::mem::forget(parked); - return Err(Error::ContextPoisoned); - } - let guard = self.enter()?; - let mut result = Ok(()); - for p in parked { - result = combine(result, p.api.exec_destroy(p.exec)); - } - combine(result, guard.finish()) - } fn unload_window_modules(&mut self) -> Result<()> { let modules = std::mem::take(self.window_modules.get_mut()); if modules.is_empty() { @@ -2173,7 +2153,6 @@ impl Context<'_> { let unload = combine(unload, self.unload_kar_levels()); let unload = combine(unload, self.unload_experimental()); let unload = combine(unload, self.unload_window_modules()); - let unload = combine(unload, self.destroy_parked_execs()); if let Some(handle) = self.handle.take() { // cuCtxDestroy accepts an owned non-current context. Pushing here // would add a stack entry for a handle invalidated by destruction. @@ -2635,7 +2614,6 @@ mod tests { kar_levels: Cell::new(None), experimental: std::array::from_fn(|_| Cell::new(None)), window_modules: RefCell::new(Vec::new()), - parked_execs: RefCell::new(Vec::new()), }; let make = |handle| DeviceBuffer { context: &context, diff --git a/crates/cuda-driver/src/original_gpu_schedule.rs b/crates/cuda-driver/src/original_gpu_schedule.rs index 136ad214..5990bf2b 100644 --- a/crates/cuda-driver/src/original_gpu_schedule.rs +++ b/crates/cuda-driver/src/original_gpu_schedule.rs @@ -309,7 +309,6 @@ impl<'ctx> OriginalGpuStream<'ctx> { nodes: None, policy, last_sequence: 0, - shape_nodes: 0, }; let begin = call(self.inner.context, &self.inner.api, |a| a.begin(h)); if let Err(primary) = begin { @@ -365,30 +364,8 @@ impl<'ctx> OriginalGpuStream<'ctx> { ); } } - // A verifier graph of an earlier (closed) verifier of this context with the same policy and node count is - // updated in place instead of instantiated again (cuGraphExecUpdate: the topology must match, else the driver - // refuses and the graph is instantiated as before). - let reusable = matches!(policy, OriginalCapturePolicy::VerifierWindow | OriginalCapturePolicy::VerifierCommit) - && reuse_execs(); - let parked = if reusable { - let n = call(g.context, &g.api, |a| a.nodes(graph))?; - g.shape_nodes = n; - g.context.take_parked_exec(policy as u8, n) - } else { - None - }; let instantiate = call(g.context, &g.api, |a| { - g.exec = Some(match parked { - Some(e) => { - if a.exec_update(e, graph)? { - e - } else { - a.exec_destroy(e)?; - a.instantiate(graph)? - } - } - None => a.instantiate(graph)?, - }); + g.exec = Some(a.instantiate(graph)?); if policy == OriginalCapturePolicy::Registry { g.done = Some(a.event_create(false)?); } else { @@ -612,8 +589,6 @@ pub struct OriginalGpuGraph<'ctx, R: OriginalGraphResources> { nodes: Option, policy: OriginalCapturePolicy, last_sequence: u64, - /// Node count of the captured graph of a reusable (verifier) policy: its executable's parking key. - shape_nodes: usize, } impl<'ctx, R: OriginalGraphResources> OriginalGpuGraph<'ctx, R> { fn validate(&self) -> Result { @@ -787,20 +762,10 @@ impl<'ctx, R: OriginalGraphResources> OriginalGpuGraph<'ctx, R> { if drained.is_err() { return drained; } - // Original reset order is executable -> graph -> completion event. A drained verifier executable is - // parked with the context for the next verifier's graph of the same shape (`capture_owned`). + // Original reset order is executable -> graph -> completion event. let mut result = Ok(()); if let Some(e) = self.exec.take() { - let park = matches!(self.policy, OriginalCapturePolicy::VerifierWindow | OriginalCapturePolicy::VerifierCommit) - && reuse_execs() - && self.graph.is_none(); - let parked = park - && self.shape_nodes > 0 - && !self.context.is_poisoned() - && self.context.park_exec(self.policy as u8, self.shape_nodes, e, Rc::clone(&self.api)); - if !parked { - result = combine(result, a.exec_destroy(e)); - } + result = combine(result, a.exec_destroy(e)); } if let Some(g) = self.graph.take() { result = combine(result, a.graph_destroy(g)); @@ -1080,32 +1045,3 @@ pub mod capture_timing { (v[0], v[1], v[2]) } } - -/// `LELEKA_GRAPH_EXEC_REUSE=off`: every verifier graph is instantiated anew (A/B control). -fn reuse_execs() -> bool { - static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| !std::env::var("LELEKA_GRAPH_EXEC_REUSE").is_ok_and(|v| v == "off" || v == "0")) -} -/// A drained verifier executable kept by its context for the next verifier's graph of the same shape. -pub(crate) struct ParkedExec { - pub(crate) policy: u8, - pub(crate) nodes: usize, - pub(crate) exec: usize, - pub(crate) api: Rc, -} -impl<'d> Context<'d> { - /// Park `exec` (at most 16 per context); false when the caller must destroy it. - pub(crate) fn park_exec(&self, policy: u8, nodes: usize, exec: usize, api: Rc) -> bool { - let Ok(mut parked) = self.parked_execs.try_borrow_mut() else { return false }; - if parked.len() >= 16 || parked.try_reserve(1).is_err() { - return false; - } - parked.push(ParkedExec { policy, nodes, exec, api }); - true - } - pub(crate) fn take_parked_exec(&self, policy: u8, nodes: usize) -> Option { - let mut parked = self.parked_execs.try_borrow_mut().ok()?; - let at = parked.iter().position(|p| p.policy == policy && p.nodes == nodes)?; - Some(parked.swap_remove(at).exec) - } -} diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi.rs b/crates/cuda-driver/src/original_gpu_schedule_ffi.rs index 1767de7c..fb3183f9 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi.rs +++ b/crates/cuda-driver/src/original_gpu_schedule_ffi.rs @@ -41,14 +41,6 @@ mod platform { type End = unsafe extern "C" fn(Handle, *mut Handle) -> i32; type Nodes = unsafe extern "C" fn(Handle, *mut Handle, *mut usize) -> i32; type Instantiate = unsafe extern "C" fn(*mut Handle, Handle, u64) -> i32; - /// `CUgraphExecUpdateResultInfo`. - #[repr(C)] - struct UpdateInfo { - result: i32, - error_node: Handle, - error_from_node: Handle, - } - type ExecUpdate = unsafe extern "C" fn(Handle, Handle, *mut UpdateInfo) -> i32; type GraphCall = unsafe extern "C" fn(Handle) -> i32; type GraphStream = unsafe extern "C" fn(Handle, Handle) -> i32; type CopyH2d = unsafe extern "C" fn(u64, *const c_void, usize, Handle) -> i32; @@ -86,7 +78,6 @@ mod platform { end: End, nodes: Nodes, instantiate: Instantiate, - exec_update: ExecUpdate, graph_destroy: GraphCall, exec_destroy: GraphCall, upload: GraphStream, @@ -134,7 +125,6 @@ mod platform { end: sym!(c"cuStreamEndCapture", End), nodes: sym!(c"cuGraphGetNodes", Nodes), instantiate: sym!(c"cuGraphInstantiateWithFlags", Instantiate), - exec_update: sym!(c"cuGraphExecUpdate_v2", ExecUpdate), graph_destroy: sym!(c"cuGraphDestroy", GraphCall), exec_destroy: sym!(c"cuGraphExecDestroy", GraphCall), upload: sym!(c"cuGraphUpload", GraphStream), @@ -255,19 +245,6 @@ mod platform { } Ok(e as usize) } - /// `cuGraphExecUpdate`: `Ok(true)` when the executable now runs `g`'s parameters, `Ok(false)` when the - /// driver refused the update (topology or node kind differ; the executable is unchanged and still valid). - pub(crate) fn exec_update(&self, e: usize, g: usize) -> Result { - let mut info = UpdateInfo { result: 0, error_node: std::ptr::null_mut(), error_from_node: std::ptr::null_mut() }; - // SAFETY: live executable and graph of the current context; `info` is a valid out-parameter. - let code = unsafe { (self.exec_update)(e as Handle, g as Handle, &mut info) }; - // CUDA_ERROR_GRAPH_EXEC_UPDATE_FAILURE (910): a refused update, not a fault. - match code { - 0 => Ok(info.result == 0), - 910 => Ok(false), - _ => check("cuGraphExecUpdate", code).map(|()| false), - } - } pub(crate) fn graph_destroy(&self, g: usize) -> Result<()> { check("cuGraphDestroy", unsafe { (self.graph_destroy)(g as Handle) @@ -382,9 +359,6 @@ impl Api { pub(crate) fn instantiate(&self, _: usize) -> Result { Err(Error::UnsupportedPlatform) } - pub(crate) fn exec_update(&self, _: usize, _: usize) -> Result { - Err(Error::UnsupportedPlatform) - } pub(crate) fn graph_destroy(&self, _: usize) -> Result<()> { Err(Error::UnsupportedPlatform) } From a9f67649eedb379ea904cbc62bef7c10429bdb87 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sat, 17 Oct 2026 00:01:47 +0200 Subject: [PATCH 4/6] fix(serve): default --pcie-frac 0.55 only over a pinned expert bank The 0.55 default (3e8e10e) also applied to the laptop's pageable low-RAM mapped bank, whose PCIe share is DMA'd from pageable pages (the copy kernel needs aliases): the coordinator's 3080 runs decoded at 6.66 tok/s against ~10-12 with 0. Unset, the share is now 0 for a pageable bank and 0.55 for a registered one; an operator's LELEKA_ORIGINAL_SERVE_PCIE_FRAC applies as given. Co-Authored-By: Claude Opus 5.5 --- .../src/qwen_forward/original_serve_residency.rs | 14 ++++++++++++++ .../src/qwen_forward/original_serve_stack.rs | 5 +++-- docs/original-serve.md | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs b/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs index 05e3999a..5f7eaeb8 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_serve_residency.rs @@ -82,6 +82,9 @@ pub(crate) struct ExpertTierConfig { /// `--pcie-frac` (0.55, generate.cpp's default): the share of a group's missed experts staged over PCIe (by the /// copy kernel or DMA, `pcie_mode`). Only used while the tier is on. pub(crate) pcie_frac: f64, + /// `pcie_frac` was set by the operator. Unset, a pageable (low-RAM, file-mapped) bank stages nothing over PCIe: + /// its misses would be DMA'd from pageable pages (job report: 6.7 vs 10-12 tok/s on the 3080 laptop). + pub(crate) pcie_frac_set: bool, /// `--pcie-mode` (auto). pub(crate) pcie_mode: PcieMode, /// `--adapt-every` (4) and `--adapt-swaps` (96); either 0 turns the adaptive tier off. @@ -101,6 +104,7 @@ impl ExpertTierConfig { reserve_mib: 700, decode_reserve_mib: 1024, pcie_frac: 0.55, + pcie_frac_set: false, pcie_mode: PcieMode::Auto, adapt_every: 4, adapt_swaps: 96, @@ -128,6 +132,11 @@ impl ExpertTierConfig { pub(crate) fn pcie_num(&self) -> u32 { (self.pcie_frac * 256.0 + 0.5).clamp(0.0, 256.0) as u32 } + /// `pcie_num` for the bank the tier reads: the default 0.55 needs a registered (pinned, aliased) source; a + /// pageable mapped bank takes 0 unless the operator set a share. + pub(crate) fn pcie_num_for(&self, pageable_source: bool) -> u32 { + if pageable_source && !self.pcie_frac_set { 0 } else { self.pcie_num() } + } pub(crate) fn adaptive(&self) -> bool { self.adapt_every > 0 && self.adapt_swaps > 0 } @@ -155,6 +164,7 @@ impl ExpertTierConfig { number("DECODE_RESERVE_MIB", &mut config.decode_reserve_mib)?; if let Some(v) = var("PCIE_FRAC") { config.pcie_frac = v.parse().map_err(|_| Error::InvalidDimension)?; + config.pcie_frac_set = true; } if let Some(v) = var("PCIE_MODE") { config.pcie_mode = match v.as_str() { @@ -759,6 +769,10 @@ mod tests { assert_eq!(with_profile.effective_slots(), -1); assert_eq!(ExpertTierConfig { slots: 2048, ..off.clone() }.effective_slots(), 2048); assert_eq!(ExpertTierConfig { pcie_frac: 0.55, ..off.clone() }.pcie_num(), 141); + // the default share needs a pinned source; an operator's share applies to a pageable bank too + assert_eq!(off.pcie_num_for(false), 141); + assert_eq!(off.pcie_num_for(true), 0); + assert_eq!(ExpertTierConfig { pcie_frac: 0.3, pcie_frac_set: true, ..off.clone() }.pcie_num_for(true), 77); assert_eq!(ExpertTierConfig { pcie_frac: 1.0, ..off.clone() }.pcie_num(), 256); assert!(ExpertTierConfig { slots: -2, ..off.clone() }.validate().is_err()); assert!(ExpertTierConfig { pcie_frac: 1.5, ..off.clone() }.validate().is_err()); diff --git a/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs b/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs index 681b568a..6574ddc6 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_serve_stack.rs @@ -495,7 +495,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> { } // generate.cpp `ver.set_pcie_mode`: only a window that can stage anything over PCIe records the copy kernel. let pcie_mode = match (expert_cache.as_ref(), moe.original_expert_bank()) { - (Some(_), Some(bank)) if config.expert_tier.pcie_num() > 0 => { + (Some(_), Some(bank)) if config.expert_tier.pcie_num_for(bank.pageable()) > 0 => { config.expert_tier.pcie_mode.graph_mode(bank.pageable(), blobs.spans_tile_blobs()).ok_or(Error::Unsupported( super::contract::Stage::Session, ))? @@ -540,6 +540,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> { let mut gpu_pool; let pool: &mut dyn OriginalServePool<'ctx> = match (expert_cache.as_mut(), moe.original_expert_bank()) { (Some(cache), Some(bank)) => { + let pcie_num = config.expert_tier.pcie_num_for(bank.pageable()); gpu_pool = GpuExpertPool { binding, moe: &*moe, @@ -547,7 +548,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> { bank, cpu: &mut *pool, state: &mut *residency, - pcie_num: config.expert_tier.pcie_num(), + pcie_num, adapt_every: config.expert_tier.adapt_every, adapt_swaps: config.expert_tier.adapt_swaps as usize, }; diff --git a/docs/original-serve.md b/docs/original-serve.md index 87ccacf2..851d41e2 100644 --- a/docs/original-serve.md +++ b/docs/original-serve.md @@ -49,7 +49,7 @@ The load must be the explicit KAR PLE MTP load, as for the windowed256 modes. | `LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS` = `auto` \| N | `--expert-cache` | off (a profile alone means auto) | | `LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes` | `--expert-cache-per-layer` | global | | `LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=P` | `--expert-profile` | none | -| `LELEKA_ORIGINAL_SERVE_PCIE_FRAC` | `--pcie-frac` | 0.55 (job 802) | +| `LELEKA_ORIGINAL_SERVE_PCIE_FRAC` | `--pcie-frac` | 0.55 over a pinned bank (job 802); 0 over the pageable low-RAM bank unless set | | `LELEKA_ORIGINAL_SERVE_PCIE_MODE` = `auto` \| `dma` \| `kernel` | `--pcie-mode` | auto (the copy kernel when the bank has device aliases) | | `LELEKA_ORIGINAL_SERVE_ADAPT_EVERY` / `_ADAPT_SWAPS` | `--adapt-every` / `--adapt-swaps` | 4 / 96 | | `LELEKA_ORIGINAL_SERVE_VRAM_RESERVE_MIB` / `_DECODE_RESERVE_MIB` | `--vram-reserve-mib` / port only | 700 / 1024 (auto sizing) | From 858f42001ef5976e1df07ade591e144daa9efe9f Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sat, 17 Oct 2026 00:13:51 +0200 Subject: [PATCH 5/6] docs(serve): job 804 record (shared window modules, reverted executable reuse) Co-Authored-By: Claude Opus 5.5 --- docs/original-serve.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/original-serve.md b/docs/original-serve.md index 851d41e2..841cd998 100644 --- a/docs/original-serve.md +++ b/docs/original-serve.md @@ -291,3 +291,13 @@ Job 801: queueing the prompt's lent-slot refill beside the window capture saved Job 800 profile of the old path (adaptive, before the merge of f845d86) per round: window 36.6 ms (CPU share 25.0, PCIe plan 1.6 of it), publish 1.3 (twelve checkpoints, each with a context synchronize that waits for the swaps), draft 3.5; per request: verifier assembly 111 ms (canonical GDN upload 17, seven graph captures 92), teardown 13. + +Job 804 (3eb7405-era binary rt-b8, static, o m x x m o): sharing the verify window's sealed modules across the +per-request verifiers (`Context::window_modules`, `LELEKA_WINDOW_MODULE_CACHE=off` to disable) cut the verifier +assembly from 118 / 118 to 70 / 70 ms (module loading 49 -> 0.4 ms; capture 29 and instantiate 21 ms remain) and +the TTFT mean over the 12 requests from 807 / 812 to 763 / 755 ms, outputs 12/12 identical, decode unchanged +(49.2 / 49.4 vs 49.1 / 49.2 tok/s). Re-using the previous verifier's graph executables through cuGraphExecUpdate +(6fa92c1) broke the stack in both arms that enabled it (window `CudaExecution` after a few requests; the 3080 +laptop saw the same on its third request) and was reverted (c45bcaa); the root cause was not isolated: the failure +appears only when the update is accepted (with the module cache off the functions differ, the update is refused, +the graph is instantiated and the runs pass). From 7a113d14067b8e01c7de516d1a4b1bf4a6168bfd Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sat, 17 Oct 2026 01:56:37 +0200 Subject: [PATCH 6/6] docs(serve): expert residency record (job 805: placeholder profile, static vs adaptive) Co-Authored-By: Claude Opus 5.5 --- docs/original-serve.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/original-serve.md b/docs/original-serve.md index 841cd998..025c6dca 100644 --- a/docs/original-serve.md +++ b/docs/original-serve.md @@ -301,3 +301,26 @@ the TTFT mean over the 12 requests from 807 / 812 to 763 / 755 ms, outputs 12/12 laptop saw the same on its third request) and was reverted (c45bcaa); the root cause was not isolated: the failure appears only when the update is accepted (with the module cache off the functions differ, the update is refused, the graph is instantiated and the runs pass). + +### Expert residency (job 805, rt-b9 = round-overhead 973e0d2 on port-gpu-bringup 0850cfe) + +`~/work/gpu-runs/baseline/profile.bin` is a placeholder: `make_profile.py --no-base` without a trace, i.e. every +(layer, expert) pair in index order interleaved across the layers. With it, static residency serves 7-9 % of the +routed entries from VRAM (random placement: 2048 of 24,576 experts is 8.3 %). Same 6 prompts x 2 passes x 128 tokens: + +| residency | profile | decode tok/s (12 req, 2 runs) | VRAM hits per request | +| --- | --- | --- | --- | +| static | placeholder | 49.9 / 49.9 | 7-9 % | +| static | shipped `data/expert-profile.bin` (sha256 8f59b4aa, the laptop's) | 51.0 / 51.0 | 4-19 % | +| static | trace of 12 unrelated prompts x 256 tokens (`LELEKA_ORIGINAL_SERVE_DUMP_ROUTING` + `make_profile.py`) | 54.9 / 54.9 | 12-22 % | +| adaptive (default) | placeholder | 66.8 / 67.0 | pass 0: 15-43 %, pass 1: 31-64 % | +| adaptive | shipped | 67.2 / 67.2 | pass 0: 11-50 %, pass 1: 31-59 % | +| adaptive | trace | 67.1 | pass 0: 15-48 %, pass 1: 35-62 % | +| adaptive, swaps polled (`LELEKA_SERVE_SWAP_WAIT=off`) | placeholder | 64.8 | | +| adaptive, old host path (serial publish, no overlap, DMA, polled) | placeholder | 69.2 (one run) | | + +The adaptive tier's gain is residency matched to the conversation being served (it swaps in what these very +requests route): no static ranking from another workload gets there, and under adaptation the starting profile +hardly matters. The prompt's own routing (computed by the prefill) would be the earliest signal for a first +request; that needs a hook in the prompt path and is not done. The single old-path run was faster than the new +default with adaptation (window 32.9 vs 35.4 ms at an equal CPU share): job 807 separates the PCIe staging mode.