From 9110228fbba7e743a1e1e1c6271c02e30adebd09 Mon Sep 17 00:00:00 2001 From: Jason Cook Date: Mon, 30 Nov 2026 10:00:10 -0500 Subject: [PATCH] helios/scheduler: scale GPU prefix calibration ceiling per step across depth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per the model-agnostic sidecar contract in `helios/model-contract.md`, `proposal_confidence[frame, row, d]` carries per-step conditional confidence values, which the host multiplies into cumulative prefix survival (`prefix *= confidence[row][depth]`) across `depth + 1` draft steps. When a drafter's per-step confidence signal (for example, Rényi-2 collision probability `sum_i q_{j,i}^2`) underpredicts target-matching acceptance on each step, that ratio compounds multiplicatively across `depth + 1` steps. Clamping `realized / predicted` to a flat `CALIBRATION_FACTOR_MAX = 2.0` regardless of depth truncated deeper calibration ratios (`d >= 2`) below realized acceptance, trapping ordinary packed selection at shallow widths (such as `packed_token_capacity = 3`). Scaling the ceiling across `depth` additional steps by `2.0 * 1.75^depth` (`depth` capped at `30`) preserves a conservative per-step shrinkage margin against noise (`0.5 * 1.75 = 0.875 < 1` relative to doubling per step) while allowing sustained multi-step survival to reach wider packed verification shapes, and preserves the unbiased round-level `DepthCalibration` update (`if count > 0`) paired with `population[depth]`. Before -> after: - `helios/src/scheduler/rounds.rs`: `DepthCalibration::factor` and `RequestCalibration::factor` previously clamped `realized / predicted` to `CALIBRATION_FACTOR_MAX` (`2.0`) at all depths. Added `CALIBRATION_STEP_FACTOR_MAX = 1.75` and `CALIBRATION_MAX_DEPTH = 30`, extracted `calibration_factor_max(depth)` and shared `calibration_ratio(realized, predicted, depth)` used by both `DepthCalibration::factor` and `RequestCalibration::factor`, and threaded `depth` through calibration accessors and `RequestCalibration::observe`. - `helios/src/scheduler/policy_tests.rs`: added `gpu_confidence_calibration_ceiling_scales_per_step_across_depth` and `gpu_confidence_multi_step_calibration_escapes_packed_three_trap_and_respects_low_depth_two_survival`. - `docs/scheduling-runtime-design.md` and `helios/README.md`: documented the per-step `proposal_confidence` sidecar multiplication and the `[0, 2 * 1.75^depth]` ceiling (`depth` capped at `30`). Claimed benefit: Unblocks ordinary packed speculative selection at `depth >= 2` when per-step calibration compounds across depth while bounding deep extrapolation (`18.76` at depth 4) and keeping shallow-width selection when realized survival at `depth >= 2` is low. On CPU scheduler simulation (`B=1`, `W=6`, `alpha = 0.75`, per-step confidence `0.55`), realized survival `[0.95, 0.90, 0.85, 0.80, 0.75]` moves from `packed_token_capacity = 3` to `6`, while `[0.95, 0.90, 0.05, 0.0, 0.0]` stays at `3`. Supporting evidence and material limitations: - `helios` (`--locked --release --features runtime-core,server` with prepared `FLARE_TEST_TEMPLATE_DIR`): 1,746 passed, 0 failed, 46 ignored in `--lib` (399 passed, 0 failed, 4 ignored in `scheduler::`) and 62 passed, 0 failed, 34 ignored across integration test binaries (1,808 passed total). - `flare` (`--locked --release`): 245 passed, 0 failed, 4 ignored. - `flare-cli` (`--locked --release`): 227 passed, 0 failed, 3 ignored. - `heliopause` (`--locked --release`): 216 passed, 0 failed, 6 ignored. - `verification/helios-lifecycle/check.py` (TLC/TLA+) and `cargo kani` were not run on this host because no TLC JAR or `cargo-kani` installation is present. - Isolated `origin/main` (`0a8c20f4`) vs this commit live SM121 TP4 `flare run` A/B (`draft_tokens = 7`, default `alpha = 1.0`): HTML/JS code segment `135.53 -> 140.32 tok/s` (+3.5%; 5s peak `155.07 -> 162.21 tok/s`, +4.6%; depth-6/7 acceptance `0.287/0.216 -> 0.492/0.378`), while single-pass `temperature = 1.0` `8K` prose and short coding samples measured `1.9%-5.2%` lower (`C=32` acceptance `65.6% -> 59.4%`). Design-Signed-Off-By: Jason Cook ; design-review=2e5b --- docs/scheduling-runtime-design.md | 57 +++++---- helios/README.md | 5 +- helios/src/scheduler/policy_tests.rs | 168 +++++++++++++++++++++++++++ helios/src/scheduler/rounds.rs | 40 ++++--- 4 files changed, 232 insertions(+), 38 deletions(-) diff --git a/docs/scheduling-runtime-design.md b/docs/scheduling-runtime-design.md index 0b20fa8ba..8d8016e06 100644 --- a/docs/scheduling-runtime-design.md +++ b/docs/scheduling-runtime-design.md @@ -111,28 +111,45 @@ confidence forecast is adjusted by two online corrections derived solely from completed rounds: 1. **Hierarchical per-request, per-depth drafter calibration (`RequestCalibration` - + `DepthCalibration`):** A slow round-level global prior `DepthCalibration` - (`clamp(realized / predicted, 0.0, 2.0)`, defaulting to `1.0` when - `predicted <= 1e-6`, initialized at `realized == predicted == 0.5^d` with - prior weight `4.0`, updated **once per completed round** from the mean - realized and predicted survival across contributing lanes with EWMA cap - `64.0`) provides instant model-wide protection for brand-new requests (e.g., - if a drafter breaks globally) while preventing a single correlated - large-batch dip from overwriting the prior in one step. Each live request - maintains its own aged per-depth `RequestCalibration` (seeded + + `DepthCalibration`):** Both calibration levels clamp `realized / predicted` + to `[0.0, calibration_factor_max(depth)]` (defaulting to `1.0` when + `predicted <= 1e-6`), where `calibration_factor_max(depth) = 2.0 * 1.75^depth` + with `depth` capped at `CALIBRATION_MAX_DEPTH = 30` (`CALIBRATION_FACTOR_MAX = 2.0` + at `depth = 0`, scaled by `CALIBRATION_STEP_FACTOR_MAX = 1.75` per additional + draft step). Per the model-agnostic sidecar contract in + [helios/model-contract.md](../helios/model-contract.md), + `proposal_confidence[frame, row, d]` carries per-step conditional confidence + values, which the host multiplies into cumulative prefix survival + (`prefix *= confidence[row][depth]`) across `depth + 1` draft steps. When a + drafter signal—for example, per-step Rényi-2 collision probability + `sum_i q_{j,i}^2`—underpredicts realized verification acceptance on each + step, that underprediction compounds multiplicatively across the cumulative + product. Compounding the ceiling across `depth` additional steps as + `2.0 * 1.75^depth` preserves a conservative per-step shrinkage margin against + noise (`0.5 * 1.75 = 0.875 < 1` relative to doubling per step) while + allowing sustained multi-step survival to calibrate past shallow packed + widths (such as `packed_token_capacity = 3`). + A slow round-level global prior `DepthCalibration` (initialized at + `realized == predicted == 0.5^d` with prior weight `4.0`, updated **once per + completed round** from the mean realized and predicted survival across + contributing lanes with EWMA cap `64.0`) provides instant model-wide + protection for brand-new requests (e.g., if a drafter breaks globally) while + preventing a single correlated large-batch dip from overwriting the prior in + one step. Each live request maintains its own aged per-depth `RequestCalibration` (seeded scale-invariantly at `anchor = max(predicted, 0.05)` with prior weight `2.0` from the live global factor on its first observation at that depth, EWMA cap - `32.0`, 128-token half-life aging matching `PrefixEstimate`) so sequential - workloads, context lengths, and heterogeneous concurrent lanes do not bleed - calibration across requests, and censored unobserved depths decay their prior - weight so a single funded acceptance probe can escape stale priors. Updates - use the exact offered, determined prefix outcomes computed once in - `complete_inner` (Rao-Blackwellized with `completion_speculative_survival` - when reported, else binary acceptance/rejection). Pricing multiplies each - depth's stored mean by the request's calibration factor, adds the Hoeffding - optimistic margin using the minimum aged weight of the confidence forecast - and verification calibration during funded acceptance learning, clamps to - `[0, 1]`, and enforces nonincreasing prefix survival across depths. + `32.0`, 128-token half-life aging matching `PrefixEstimate`, and clamped to + `calibration_factor_max(depth)`) so sequential workloads, context lengths, and + heterogeneous concurrent lanes do not bleed calibration across requests, and + censored unobserved depths decay their prior weight so a single funded + acceptance probe can escape stale priors. Updates use the exact offered, + determined prefix outcomes computed once in `complete_inner` (Rao-Blackwellized + with `completion_speculative_survival` when reported, else binary + acceptance/rejection). Pricing multiplies each depth's stored mean by the + request's calibration factor, adds the Hoeffding optimistic margin using the + minimum aged weight of the confidence forecast and verification calibration + during funded acceptance learning, clamps to `[0, 1]`, and enforces + nonincreasing prefix survival across depths. 2. **Cross-lane order-statistic allocation surplus (`SurplusHistory`):** Inside a packed GPU-allocated round (`B >= 2`, `P < B * W`, `depth >= 1`), the device allocator observes fresh per-step confidences across all active lanes diff --git a/helios/README.md b/helios/README.md index b10957132..9785c4ff2 100644 --- a/helios/README.md +++ b/helios/README.md @@ -447,8 +447,9 @@ outcomes. When pricing GPU-confidence shapes, stored per-depth forecasts are scaled by a request-local aged per-depth verification calibration ratio (seeded scale-invariantly with prior weight `2` from a once-per-round population prior capped at weight `64`, 128-token half-life, request EWMA cap `32`, clamped to -`[0, 2]`), and crowded GPU-allocated packed shapes (`B >= 2`, `P < B * W`, -`depth >= 1`) additionally apply a bounded empirical cross-lane order-statistic +`[0, 2 * 1.75^depth]` with `depth` capped at `30`), and crowded GPU-allocated +packed shapes (`B >= 2`, `P < B * W`, `depth >= 1`) additionally apply a bounded +empirical cross-lane order-statistic surplus (from dual 256-entry rolling windows—one for `depth >= 2` curves and a dedicated depth-1 ring for `W=2`—with conservative `eff_depth <= depth` fallback, excess scaled by `(1 - 1/b) * min(alpha, 1)` and capped at 100% draft diff --git a/helios/src/scheduler/policy_tests.rs b/helios/src/scheduler/policy_tests.rs index 278954f86..22dad8a41 100644 --- a/helios/src/scheduler/policy_tests.rs +++ b/helios/src/scheduler/policy_tests.rs @@ -6429,3 +6429,171 @@ fn expensive_stale_shape_does_not_starve_smaller_stale_shapes_under_credit_refil // Bound P <= (0.002 / 0.998) * O + D uses the most recent refresh episode duration D. assert!(refresh_ns as f64 <= ordinary_ns as f64 * 0.002 / 0.998 + last_refresh_ns as f64); } + +#[test] +fn gpu_confidence_calibration_ceiling_scales_per_step_across_depth() { + let mut forecasts = rounds::Forecasts::new(6); + let mut clamped = rounds::Forecasts::new(6); + for _ in 0..256 { + // Depth 0 ceiling is 2.0 * 1.75^0 = 2.0: 0.99 / 0.10 = 9.9 clamps to 2.0. + forecasts.observe_calibration(0, 0.99, 0.10); + // Depth 3 ceiling is 2.0 * 1.75^3 = 10.71875: 0.99 / 0.01 = 99.0 clamps to 10.71875. + forecasts.observe_calibration(3, 0.99, 0.01); + // Depth 4 ceiling is 2.0 * 1.75^4 = 18.7578125: 0.75 / 0.05 = 15.0 passes unclamped. + forecasts.observe_calibration(4, 0.75, 0.05); + // Depth 4 ceiling is 2.0 * 1.75^4 = 18.7578125: 0.99 / 0.01 = 99.0 clamps to 18.7578125. + clamped.observe_calibration(4, 0.99, 0.01); + } + assert!((forecasts.calibration_factor(0) - 2.0).abs() < 1e-6); + assert!((forecasts.calibration_factor(3) - 10.71875).abs() < 1e-6); + assert!((forecasts.calibration_factor(4) - 15.0).abs() < 0.25); + assert!((clamped.calibration_factor(4) - 18.7578125).abs() < 1e-6); +} + +fn single_lane_packed_calibration_engine() -> RequestScheduler { + let mut s = engine(1, false); + s.configure_policy(PolicyConfig { + adaptive_verification_alpha: 0.75, + token_fairness: 0.0, + delivery_fairness: 0.0, + decode_age_price: 0.0, + ..PolicyConfig::default() + }) + .unwrap(); + let mut graphs: Vec<_> = super::tests::duration_graphs(1) + .into_iter() + .filter(|g| g.kind != GraphKind::Speculative) + .collect(); + for g in &mut graphs { + g.estimated_duration_ns = MS; + } + graphs.push(crate::execution::GraphDescriptor { + name: "speculative-b1-d0-w1".into(), + kind: GraphKind::Speculative, + sampling_mode: SamplingMode::General, + handle: 100, + batch_capacity: 1, + draft_tokens: 0, + token_capacity: 1, + packed_token_capacity: 0, + prefill_capacity: 0, + estimated_duration_ns: 28 * MS, + confidence_width: 0, + tuned_bindings: vec![], + input_bindings: vec![], + }); + for (packed, nanos) in [ + (2usize, 29_500_000u64), + (3, 31_200_000), + (4, 35_000_000), + (5, 37_000_000), + (6, 38_800_000), + ] { + graphs.push(crate::execution::GraphDescriptor { + name: format!("speculative-b1-d5-w6-p{packed}"), + kind: GraphKind::Speculative, + sampling_mode: SamplingMode::General, + handle: 100 + packed, + batch_capacity: 1, + draft_tokens: 5, + token_capacity: 6, + packed_token_capacity: packed, + prefill_capacity: 0, + estimated_duration_ns: nanos, + confidence_width: 5, + tuned_bindings: vec![], + input_bindings: vec![], + }); + } + s.measured_graph_durations(&graphs).unwrap(); + s.enable_speculation(&[1, 6]).unwrap(); + s.capabilities.speculative_allocations = [2, 3, 4, 5, 6] + .into_iter() + .map(|packed| (1, 5, 6, packed, crate::execution::PrefixAllocation::Gpu)) + .collect(); + s +} + +fn observe_single_lane_packed_round( + s: &mut RequestScheduler, + handle: RequestHandle, + plan: &ScheduledPlan, + conf_per_step: f32, + realized: &[f32; 5], +) { + let fence = Fence(s.submitted.0 + 1); + s.commit(plan, fence).unwrap(); + let mut records = completion_records(s, plan, fence, 0); + let remaining = plan.packed_token_capacity.saturating_sub(plan.lanes.len()); + let offered = plan.lanes[0].tokens.saturating_sub(1).min(remaining).min(5); + let vec = records[handle.slot as usize].vector.as_mut().unwrap(); + vec.verification_width = plan.token_capacity as i64; + vec.offered_drafts = offered as i64; + let slots = s.limits.request_capacity(); + let mut surv = vec![vec![-1.0f32; 15]; slots]; + for d in 0..offered { + surv[handle.slot as usize][d] = realized[d]; + } + let confidence = vec![vec![conf_per_step; 15]; plan.batch_capacity]; + let duration = plan.estimated_duration_ns().max(MS); + s.advance_to(s.now_ns + duration).unwrap(); + s.complete_packed_round_with_survival(fence, &records, gpu_time(duration), &confidence, Some(&surv)) + .unwrap(); +} + +#[test] +fn gpu_confidence_multi_step_calibration_escapes_packed_three_trap_and_respects_low_depth_two_survival() { + // (b) High per-step acceptance (realized = [0.95..0.75]) with low per-step confidence (0.55) + // calibrates deep prefix products across all 5 steps and selects Ordinary packed = 6. + let mut s = single_lane_packed_calibration_engine(); + let handle = add(&mut s, 1, 64, 1024); + ready(&mut s, &[handle]); + s.refresh.acceptance_credit_ns = 0.0; + s.refresh.credit_ns = 0.0; + + let initial = s.plan().unwrap(); + assert_eq!(initial.origin, PlanOrigin::Ordinary); + assert_eq!(initial.packed_token_capacity, 3); + let high_realized = [0.95f32, 0.90, 0.85, 0.80, 0.75]; + observe_single_lane_packed_round(&mut s, handle, &initial, 0.55, &high_realized); + + for _ in 0..48 { + s.refresh.acceptance_credit_ns = refresh::CREDIT_CAP_NS; + let plan = s.plan().unwrap(); + observe_single_lane_packed_round(&mut s, handle, &plan, 0.55, &high_realized); + } + + assert!( + s.forecasts.request_calibration_factor(handle, 4) > 8.0, + "depth 4 calibration factor must exceed the depth-0 2.0 ceiling: {}", + s.forecasts.request_calibration_factor(handle, 4) + ); + let req = s.request(handle).unwrap(); + let curve = s.speculative_curve(req, false); + for (depth, &expected) in high_realized.iter().enumerate() { + assert!( + (curve[depth] - f64::from(expected)).abs() < 0.05, + "depth {depth} should calibrate near {expected}, got {:?}", + &curve[..5] + ); + } + s.refresh.acceptance_credit_ns = 0.0; + let selected = s.plan().unwrap(); + assert_eq!(selected.origin, PlanOrigin::Ordinary); + assert_eq!(selected.packed_token_capacity, 6); + + // (c) Low realized survival at depth >= 2 continues to select Ordinary packed = 3. + let mut s_low = single_lane_packed_calibration_engine(); + let handle_low = add(&mut s_low, 1, 64, 1024); + ready(&mut s_low, &[handle_low]); + let low_realized = [0.95f32, 0.90, 0.05, 0.0, 0.0]; + for _ in 0..24 { + s_low.refresh.acceptance_credit_ns = refresh::CREDIT_CAP_NS; + let plan = s_low.plan().unwrap(); + observe_single_lane_packed_round(&mut s_low, handle_low, &plan, 0.55, &low_realized); + } + s_low.refresh.acceptance_credit_ns = 0.0; + let selected_low = s_low.plan().unwrap(); + assert_eq!(selected_low.origin, PlanOrigin::Ordinary); + assert_eq!(selected_low.packed_token_capacity, 3); +} diff --git a/helios/src/scheduler/rounds.rs b/helios/src/scheduler/rounds.rs index ef4c8027e..e1e39e81c 100644 --- a/helios/src/scheduler/rounds.rs +++ b/helios/src/scheduler/rounds.rs @@ -11,6 +11,8 @@ const POPULATION_WEIGHT: f32 = 1.0 / 64.0; const CALIBRATION_PRIOR_WEIGHT: f64 = 4.0; const POPULATION_CALIBRATION_MAX_WEIGHT: f64 = 64.0; const CALIBRATION_FACTOR_MAX: f64 = 2.0; +const CALIBRATION_STEP_FACTOR_MAX: f64 = 1.75; +const CALIBRATION_MAX_DEPTH: usize = 30; const REQUEST_CALIBRATION_PRIOR_WEIGHT: f64 = 2.0; const REQUEST_CALIBRATION_MAX_WEIGHT: f64 = 32.0; const REQUEST_CALIBRATION_HALF_LIFE: f64 = 128.0; @@ -19,6 +21,18 @@ const SURPLUS_HISTORY_CAPACITY: usize = 256; const SURPLUS_MIN_SAMPLES: usize = 4; const SURPLUS_FACTOR_MAX: f64 = 2.0; +fn calibration_factor_max(depth: usize) -> f64 { + CALIBRATION_FACTOR_MAX * CALIBRATION_STEP_FACTOR_MAX.powi(depth.min(CALIBRATION_MAX_DEPTH) as i32) +} + +fn calibration_ratio(realized: f64, predicted: f64, depth: usize) -> f64 { + if predicted > 1e-6 { + (realized / predicted).clamp(0.0, calibration_factor_max(depth)) + } else { + 1.0 + } +} + #[derive(Clone, Copy)] struct DepthCalibration { realized: f64, @@ -39,12 +53,8 @@ impl DepthCalibration { self.predicted += (predicted - self.predicted) / self.weight; } - fn factor(self) -> f64 { - if self.predicted > 1e-6 { - (self.realized / self.predicted).clamp(0.0, CALIBRATION_FACTOR_MAX) - } else { - 1.0 - } + fn factor(self, depth: usize) -> f64 { + calibration_ratio(self.realized, self.predicted, depth) } } @@ -75,23 +85,21 @@ impl RequestCalibration { base * Self::decay(generated, self.observed_at) } - fn factor(self, global: DepthCalibration) -> f64 { + fn factor(self, depth: usize, global: DepthCalibration) -> f64 { if self.weight == 0.0 { - global.factor() - } else if self.predicted > 1e-6 { - (self.realized / self.predicted).clamp(0.0, CALIBRATION_FACTOR_MAX) + global.factor(depth) } else { - 1.0 + calibration_ratio(self.realized, self.predicted, depth) } } - fn observe(&mut self, realized: f64, predicted: f64, generated: u32, global: DepthCalibration) { + fn observe(&mut self, depth: usize, realized: f64, predicted: f64, generated: u32, global: DepthCalibration) { debug_assert!(realized.is_finite() && (0.0..=1.0).contains(&realized)); debug_assert!(predicted.is_finite() && (0.0..=1.0).contains(&predicted)); let aged = if self.weight == 0.0 { let anchor = predicted.max(REQUEST_CALIBRATION_ANCHOR_FLOOR); self.predicted = anchor; - self.realized = (anchor * global.factor()).clamp(0.0, 1.0); + self.realized = (anchor * global.factor(depth)).clamp(0.0, 1.0); REQUEST_CALIBRATION_PRIOR_WEIGHT * Self::decay(generated, self.observed_at) } else { self.weight_at(generated) @@ -277,7 +285,7 @@ impl Forecast { fn calibration_factor(&self, depth: usize, global: &[DepthCalibration]) -> f64 { let global_entry = global.get(depth).copied().unwrap_or(DepthCalibration::new(1.0)); - self.calibration.get(depth).map_or_else(|| global_entry.factor(), |entry| entry.factor(global_entry)) + self.calibration.get(depth).map_or_else(|| global_entry.factor(depth), |entry| entry.factor(depth, global_entry)) } fn calibration_information(&self, depth: usize, generated: u32) -> f64 { @@ -287,7 +295,7 @@ impl Forecast { fn observe_calibration(&mut self, depth: usize, realized: f64, predicted: f64, generated: u32, global: &[DepthCalibration]) { if let Some(entry) = self.calibration.get_mut(depth) { let global_entry = global.get(depth).copied().unwrap_or(DepthCalibration::new(1.0)); - entry.observe(realized, predicted, generated, global_entry); + entry.observe(depth, realized, predicted, generated, global_entry); } } } @@ -327,7 +335,7 @@ impl Forecasts { #[cfg(test)] pub(super) fn calibration_factor(&self, depth: usize) -> f64 { - self.calibration.get(depth).map_or(1.0, |entry| entry.factor()) + self.calibration.get(depth).map_or(1.0, |entry| entry.factor(depth)) } #[cfg(test)]