Merge claude/window-policy: draft-floor ceiling default 0.60 (LELEKA_SPEC_POLICY=legacy restores 0.9), replay-arm policy tooling, spec-trace bar/slope, run-e2e ATTN_DAILY_MTP default
Paired A/B 245k (8 blocks): +1.09% tok/s, se 1.86 (not resolved); replay screening +0.35..+1.72 tok/s; argmax flips 1.9-2.0% vs A/A 1.3-1.55% (<2.8% bound). Not claimed as a speedup. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -664,6 +664,23 @@ mod tests {
|
||||
assert!((32..=4096).contains(&a.len()) && a.bytes().all(|c| (0x21..=0x7e).contains(&c)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_server_profile_switches_reach_the_engine_environment_through_the_saved_config() {
|
||||
// `up` saves the RunConfig (profile.engine_env inside) as leleka.json; `run` loads it and `start_engine` hands
|
||||
// `engine_environment()` to the child (`child_env` sets every pair). The 5090 profile's engine_env must arrive.
|
||||
let saved = serde_json::to_string(&config("rtx5090-32g")).unwrap();
|
||||
let loaded: RunConfig = serde_json::from_str(&saved).unwrap();
|
||||
let env = loaded.engine_environment();
|
||||
for (key, value) in [("LELEKA_SM120_ATTN_DAILY_MTP", "1"), ("LELEKA_ORIGINAL_SERVE_SEED", "off"), ("LELEKA_CHAIN", "all")] {
|
||||
assert_eq!(env.get(key).map(String::as_str), Some(value), "{key}");
|
||||
}
|
||||
assert!(!config("rtx3080-16g").engine_environment().contains_key("LELEKA_SM120_ATTN_DAILY_MTP"));
|
||||
// an operator's `engine_env` (the `up` resolved one) wins over the profile
|
||||
let mut operator = loaded;
|
||||
operator.engine_env.insert("LELEKA_SM120_ATTN_DAILY_MTP".into(), "0".into());
|
||||
assert_eq!(operator.engine_environment()["LELEKA_SM120_ATTN_DAILY_MTP"], "0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expert_environment_wins_over_the_profile() {
|
||||
let mut config = config("rtx3080-16g");
|
||||
|
||||
@@ -417,6 +417,10 @@ impl OriginalServeSettings {
|
||||
for entry in list.split(',').map(str::trim).filter(|l|!l.is_empty()) {
|
||||
// `name@MIN_P` pins the arm's request floor; `+flag` suffixes (`adaptive@0+tail7`) are the replay harness's, the label keeps them
|
||||
let main=entry.split_once('+').map_or(entry,|(m,_)|m);
|
||||
// `~key=value` suffixes set constants of the adaptive policy for this arm alone (`adaptive@0~step=0.3~explore=0`,
|
||||
// `AdaptiveConfig::set_option`); an unknown key drops the arm
|
||||
let mut options=main.split('~');
|
||||
let main=options.next().unwrap_or(main);
|
||||
let (label,min_p)=match main.split_once('@') {
|
||||
Some((l,p))=>(l,p.parse::<f32>().ok()),
|
||||
None=>(main,None),
|
||||
@@ -426,7 +430,9 @@ impl OriginalServeSettings {
|
||||
let n=n.clamp(2,MAX_T);s.max_t=(n+2).min(MAX_T);s.mtp_max_t=n;s.suffix_min_match=3;
|
||||
} else if label=="adaptive" {
|
||||
s.max_t=MAX_T;s.mtp_max_t=MAX_T;s.suffix_min_match=3;
|
||||
s.adaptive=Some(AdaptiveConfig::new(MAX_T,MAX_T-1).from_environment());
|
||||
let mut cfg=AdaptiveConfig::new(MAX_T,MAX_T-1).from_environment();
|
||||
if !options.all(|o|o.split_once('=').is_some_and(|(k,v)|cfg.set_option(k,v))) {continue;}
|
||||
s.adaptive=Some(cfg);
|
||||
} else {continue;}
|
||||
arms.push((entry.to_owned(),s));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ const S_FIRST_AGREE: [f64; M_BUCKETS] = [0.75, 0.88, 0.93, 0.96, 0.97];
|
||||
const S_FIRST_OTHER: [f64; M_BUCKETS] = [0.25, 0.35, 0.45, 0.55, 0.65];
|
||||
const S_CONT_AGREE: [f64; M_BUCKETS] = [0.88, 0.93, 0.96, 0.97, 0.98];
|
||||
const S_CONT_OTHER: [f64; M_BUCKETS] = [0.75, 0.85, 0.90, 0.93, 0.95];
|
||||
/// Upper bound of the chain's confidence floor when the request carries none (`spec_min_p` 0, the product profile). The computed floor (`draft_plan`) is the
|
||||
/// lower edge of the first probability bucket whose calibrated acceptance clears the bar of a further draft; at 245k context (1.8 ms per verified row, a faster
|
||||
/// draft round) that bar sits at the acceptance of the 0.7-0.8 bucket, so the floor flips between 0.7 and 0.8 and every flip prunes a tenth of the chain's
|
||||
/// continuations, drafts that the verify-time choice (calibrated acceptance of the actual row, a better-informed test than one draft's own probability)
|
||||
/// would have kept. A lower ceiling leaves that choice to `choose`. `LELEKA_SPEC_POLICY=legacy` restores [`FLOOR_CEILING_LEGACY`].
|
||||
pub(crate) const FLOOR_CEILING: f32 = 0.60;
|
||||
/// The ceiling the policy shipped with (a request with `spec_min_p` 0 meant 0.9).
|
||||
pub(crate) const FLOOR_CEILING_LEGACY: f32 = 0.90;
|
||||
const N0_BUCKET: f64 = 6.0;
|
||||
const N0_DEPTH: f64 = 10.0;
|
||||
const N0_SUFFIX: f64 = 4.0;
|
||||
@@ -64,6 +72,13 @@ pub(crate) struct AdaptiveConfig {
|
||||
pub(crate) decay: f64,
|
||||
/// Rate of the fast content bias.
|
||||
pub(crate) bias_rate: f64,
|
||||
/// Share of a verified row's cost that a DRAFTED row is expected to cost: a draft is produced for `draft_step_ms` and is verified (pays the row slope) only when
|
||||
/// the next round chooses it (1.0 = the earlier rule, every produced draft is verified).
|
||||
pub(crate) row_q: f64,
|
||||
/// The draft floor follows the calibrated acceptance curve continuously (linear between the bucket centres) instead of jumping between the bucket edges.
|
||||
pub(crate) smooth_floor: bool,
|
||||
/// The draft floor's bar uses the measured token rate of the recent rounds instead of the rate the chosen candidate was predicted to have.
|
||||
pub(crate) measured_rate: bool,
|
||||
}
|
||||
impl AdaptiveConfig {
|
||||
pub(crate) fn new(max_t: usize, max_drafts: usize) -> Self {
|
||||
@@ -74,18 +89,24 @@ impl AdaptiveConfig {
|
||||
margin: 0.02,
|
||||
explore_period: 32,
|
||||
min_p_lo: 0.10,
|
||||
min_p_hi: 0.90,
|
||||
min_p_hi: FLOOR_CEILING,
|
||||
draft_step_ms: 0.45,
|
||||
cost_alpha: 0.12,
|
||||
decay: 0.995,
|
||||
bias_rate: 0.06,
|
||||
row_q: 1.0,
|
||||
smooth_floor: false,
|
||||
measured_rate: false,
|
||||
}
|
||||
}
|
||||
/// `LELEKA_SPEC_EXPLORE` (period), `_MARGIN`, `_MIN_P_LO`, `_DRAFT_STEP_MS`, `_COST_ALPHA`, `_DECAY`, `_BIAS_RATE`.
|
||||
/// `LELEKA_SPEC_EXPLORE` (period), `_MARGIN`, `_MIN_P_LO`, `_DRAFT_STEP_MS`, `_COST_ALPHA`, `_DECAY`, `_BIAS_RATE`, `_FLOOR_CEILING`; `LELEKA_SPEC_POLICY=legacy`
|
||||
/// first restores the constants the policy shipped with before the draft-round change (see [`Self::with_policy`]).
|
||||
pub(crate) fn from_environment(mut self) -> Self {
|
||||
fn num<T: std::str::FromStr>(name: &str) -> Option<T> {
|
||||
std::env::var(name).ok().and_then(|v| v.trim().parse().ok())
|
||||
}
|
||||
self = self.with_policy(std::env::var("LELEKA_SPEC_POLICY").ok().as_deref());
|
||||
if let Some(v) = num("LELEKA_SPEC_FLOOR_CEILING") { self.min_p_hi = v; }
|
||||
if let Some(v) = num("LELEKA_SPEC_EXPLORE") { self.explore_period = v; }
|
||||
if let Some(v) = num("LELEKA_SPEC_MARGIN") { self.margin = v; }
|
||||
if let Some(v) = num("LELEKA_SPEC_MIN_P_LO") { self.min_p_lo = v; }
|
||||
@@ -95,6 +116,34 @@ impl AdaptiveConfig {
|
||||
if let Some(v) = num("LELEKA_SPEC_BIAS_RATE") { self.bias_rate = v; }
|
||||
self
|
||||
}
|
||||
/// `LELEKA_SPEC_POLICY`: unset / `current` = the defaults of [`Self::new`]; `legacy` (also `v1`) = the constants of the earlier policy (the draft-floor ceiling 0.9).
|
||||
pub(crate) fn with_policy(mut self, policy: Option<&str>) -> Self {
|
||||
if matches!(policy.map(str::trim), Some("legacy" | "v1")) {
|
||||
self.min_p_hi = FLOOR_CEILING_LEGACY;
|
||||
}
|
||||
self
|
||||
}
|
||||
/// One named constant of a replay arm (`adaptive@0~step=0.3~explore=0`, `OriginalServeSettings::arms_from_environment`): the same
|
||||
/// constants as the `LELEKA_SPEC_*` variables, so that policy variants can be compared inside one process on the same forced text.
|
||||
/// False when the key or the value is not understood.
|
||||
pub(crate) fn set_option(&mut self, key: &str, value: &str) -> bool {
|
||||
let Ok(v) = value.trim().parse::<f64>() else { return false };
|
||||
match key {
|
||||
"explore" => self.explore_period = v as u64,
|
||||
"margin" => self.margin = v,
|
||||
"min_p_lo" => self.min_p_lo = v as f32,
|
||||
"step" => self.draft_step_ms = v,
|
||||
"alpha" => self.cost_alpha = v,
|
||||
"decay" => self.decay = v,
|
||||
"bias" => self.bias_rate = v,
|
||||
"ceil" => self.min_p_hi = v as f32,
|
||||
"rowq" => self.row_q = v,
|
||||
"smooth" => self.smooth_floor = v != 0.0,
|
||||
"measured" => self.measured_rate = v != 0.0,
|
||||
_ => return false,
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, Debug)]
|
||||
@@ -190,6 +239,9 @@ pub(crate) struct AdaptivePolicy {
|
||||
drafts_ewma: f64,
|
||||
survive_ewma: f64,
|
||||
rate_ewma: f64,
|
||||
/// Decayed tokens and ms of the recent rounds (their ratio is the measured token rate).
|
||||
meas_tok: f64,
|
||||
meas_ms: f64,
|
||||
}
|
||||
|
||||
impl AdaptivePolicy {
|
||||
@@ -215,6 +267,8 @@ impl AdaptivePolicy {
|
||||
drafts_ewma: 3.0,
|
||||
survive_ewma: 0.5,
|
||||
rate_ewma: 0.0,
|
||||
meas_tok: 0.0,
|
||||
meas_ms: 0.0,
|
||||
}
|
||||
}
|
||||
pub(crate) fn config(&self) -> &AdaptiveConfig {
|
||||
@@ -451,6 +505,10 @@ impl AdaptivePolicy {
|
||||
self.survive_ewma += 0.1 * (surv - self.survive_ewma);
|
||||
}
|
||||
self.rate_ewma = if self.rate_ewma > 0.0 { self.rate_ewma + 0.1 * (c.rate - self.rate_ewma) } else { c.rate };
|
||||
if round_ms.is_finite() && round_ms > 0.0 {
|
||||
self.meas_tok = 0.95 * self.meas_tok + (accepted + 1) as f64;
|
||||
self.meas_ms = 0.95 * self.meas_ms + round_ms;
|
||||
}
|
||||
self.last = Some((c.origin, c.t));
|
||||
}
|
||||
/// E of the chosen window without its last row (`expected` is a prefix sum of the cumulative acceptances).
|
||||
@@ -468,19 +526,50 @@ impl AdaptivePolicy {
|
||||
|
||||
// ---- next draft chain -------------------------------------------------------------------------------------
|
||||
|
||||
/// The calibrated acceptance a further draft must promise to be worth producing: `rate * (row_q * row slope + chain step) / survival` (see `draft_plan`).
|
||||
pub(crate) fn bar(&self) -> f64 {
|
||||
let rate = if self.cfg.measured_rate && self.meas_ms > 0.0 {
|
||||
self.meas_tok / self.meas_ms
|
||||
} else if self.rate_ewma > 0.0 {
|
||||
self.rate_ewma
|
||||
} else {
|
||||
0.04
|
||||
};
|
||||
(rate * (self.cfg.row_q * self.row_slope_ms() + self.cfg.draft_step_ms) / self.survive_ewma.max(0.2)).clamp(0.0, 0.99)
|
||||
}
|
||||
|
||||
/// How deep the next MTP chain should go and the draft probability below which it stops. A chain step costs
|
||||
/// `draft_step_ms`; a verified row costs `row_slope_ms` and is worth it when `survival * a / slope` beats the current
|
||||
/// tokens-per-ms, so the floor is the smallest draft probability whose calibrated acceptance clears that bar.
|
||||
pub(crate) fn draft_plan(&self) -> DraftPlan {
|
||||
let max_drafts = ((self.hold_t.ceil() as usize).max(2)).min(self.cfg.max_drafts.max(1));
|
||||
let rate = if self.rate_ewma > 0.0 { self.rate_ewma } else { 0.04 };
|
||||
let a_req = (rate * (self.row_slope_ms() + self.cfg.draft_step_ms) / self.survive_ewma.max(0.2)).clamp(0.0, 0.99);
|
||||
let a_req = self.bar();
|
||||
let rates: [f64; P_BUCKETS] = std::array::from_fn(|b| sigmoid(logit(self.mtp_bucket[b].rate(P_PRIOR[b], N0_BUCKET)) + self.bias_mtp));
|
||||
let mut min_p = self.cfg.min_p_hi;
|
||||
for b in 0..P_BUCKETS {
|
||||
let r = sigmoid(logit(self.mtp_bucket[b].rate(P_PRIOR[b], N0_BUCKET)) + self.bias_mtp);
|
||||
if r >= a_req {
|
||||
min_p = P_EDGES[b];
|
||||
break;
|
||||
if self.cfg.smooth_floor {
|
||||
// the smallest p at which the calibrated acceptance (linear between the bucket centres) reaches the bar
|
||||
let centre = |b: usize| -> f64 { if b + 1 < P_BUCKETS { 0.5 * (P_EDGES[b] + P_EDGES[b + 1]) as f64 } else { 0.975 } };
|
||||
let mut found = None;
|
||||
for b in 0..P_BUCKETS {
|
||||
if rates[b] >= a_req {
|
||||
found = Some(if b == 0 {
|
||||
0.0
|
||||
} else {
|
||||
let (c0, c1, r0, r1) = (centre(b - 1), centre(b), rates[b - 1], rates[b]);
|
||||
c0 + (c1 - c0) * ((a_req - r0) / (r1 - r0).max(1e-9)).clamp(0.0, 1.0)
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(p) = found {
|
||||
min_p = p as f32;
|
||||
}
|
||||
} else {
|
||||
for b in 0..P_BUCKETS {
|
||||
if rates[b] >= a_req {
|
||||
min_p = P_EDGES[b];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
DraftPlan { max_drafts, min_p: min_p.clamp(self.cfg.min_p_lo, self.cfg.min_p_hi) }
|
||||
@@ -794,6 +883,122 @@ mod tests {
|
||||
assert!(a.min_p <= b.min_p, "{a:?} {b:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replay_arm_options_set_the_named_constants_and_refuse_the_unknown() {
|
||||
let mut c = cfg();
|
||||
assert!(c.set_option("step", "0.3") && c.set_option("explore", "0") && c.set_option("margin", "0.05") && c.set_option("min_p_lo", "0.2"));
|
||||
assert!(c.set_option("alpha", "0.2") && c.set_option("decay", "0.99") && c.set_option("bias", "0.1"));
|
||||
assert_eq!((c.draft_step_ms, c.explore_period, c.margin, c.min_p_lo), (0.3, 0, 0.05, 0.2));
|
||||
assert_eq!((c.cost_alpha, c.decay, c.bias_rate), (0.2, 0.99, 0.1));
|
||||
let before = c;
|
||||
assert!(!c.set_option("nope", "1") && !c.set_option("step", "fast"));
|
||||
assert_eq!(c, before);
|
||||
}
|
||||
|
||||
/// The earlier rule, kept as the reference: the floor is the lower edge of the first bucket whose calibrated acceptance clears the bar.
|
||||
fn legacy_plan(pol: &AdaptivePolicy) -> DraftPlan {
|
||||
let max_drafts = ((pol.hold_t.ceil() as usize).max(2)).min(pol.cfg.max_drafts.max(1));
|
||||
let rate = if pol.rate_ewma > 0.0 { pol.rate_ewma } else { 0.04 };
|
||||
let a_req = (rate * (pol.row_slope_ms() + pol.cfg.draft_step_ms) / pol.survive_ewma.max(0.2)).clamp(0.0, 0.99);
|
||||
let mut min_p = pol.cfg.min_p_hi;
|
||||
for b in 0..P_BUCKETS {
|
||||
let r = sigmoid(logit(pol.mtp_bucket[b].rate(P_PRIOR[b], N0_BUCKET)) + pol.bias_mtp);
|
||||
if r >= a_req {
|
||||
min_p = P_EDGES[b];
|
||||
break;
|
||||
}
|
||||
}
|
||||
DraftPlan { max_drafts, min_p: min_p.clamp(pol.cfg.min_p_lo, pol.cfg.min_p_hi) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_draft_plan_is_the_earlier_rule_and_the_new_options_only_lower_or_smooth_the_floor() {
|
||||
let mut rng = Rng(8);
|
||||
for world in [CODE_CHEAP, CODE_COSTLY, PROSE_CHEAP, PROSE_COSTLY] {
|
||||
let mut pol = AdaptivePolicy::new(cfg());
|
||||
let (mut cheaper, mut smooth, mut measured) = (cfg(), cfg(), cfg());
|
||||
cheaper.row_q = 0.5;
|
||||
smooth.smooth_floor = true;
|
||||
measured.measured_rate = true;
|
||||
let (mut pc, mut ps, mut pm) = (AdaptivePolicy::new(cheaper), AdaptivePolicy::new(smooth), AdaptivePolicy::new(measured));
|
||||
for i in 0..600 {
|
||||
let mut r2 = Rng(i + 3);
|
||||
play(&world, &mut rng, Some(&mut pol), None);
|
||||
play(&world, &mut r2, Some(&mut pc), None);
|
||||
let mut r3 = Rng(i + 3);
|
||||
play(&world, &mut r3, Some(&mut ps), None);
|
||||
let mut r4 = Rng(i + 3);
|
||||
play(&world, &mut r4, Some(&mut pm), None);
|
||||
assert_eq!(pol.draft_plan(), legacy_plan(&pol), "round {i}");
|
||||
let l = legacy_plan(&pc);
|
||||
assert!(pc.draft_plan().min_p <= l.min_p + 1e-6 && pc.draft_plan().max_drafts == l.max_drafts, "row_q 0.5 raised the floor at round {i}");
|
||||
let sp = ps.draft_plan().min_p;
|
||||
assert!((0.10..=0.90).contains(&sp), "smooth floor {sp} out of bounds at round {i}");
|
||||
let pl = pm.draft_plan();
|
||||
assert!((0.10..=0.90).contains(&pl.min_p) && (1..=7).contains(&pl.max_drafts), "{pl:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_ceiling_is_the_new_one_and_the_legacy_switch_restores_the_old_policy_exactly() {
|
||||
let new = AdaptiveConfig::new(8, 7);
|
||||
assert_eq!(new.min_p_hi, FLOOR_CEILING);
|
||||
let legacy = new.with_policy(Some("legacy"));
|
||||
assert_eq!(legacy.min_p_hi, 0.90);
|
||||
// everything but the ceiling is the earlier policy's, field by field
|
||||
let earlier = AdaptiveConfig {
|
||||
max_t: 8, max_drafts: 7, margin: 0.02, explore_period: 32, min_p_lo: 0.10, min_p_hi: 0.90, draft_step_ms: 0.45,
|
||||
cost_alpha: 0.12, decay: 0.995, bias_rate: 0.06, row_q: 1.0, smooth_floor: false, measured_rate: false,
|
||||
};
|
||||
assert_eq!(legacy, earlier);
|
||||
assert_eq!(new.with_policy(Some("v1")), earlier);
|
||||
assert_eq!(new.with_policy(None), new);
|
||||
assert_eq!(new.with_policy(Some("current")), new);
|
||||
// a request that names a ceiling keeps it in both policies; one that does not gets the policy's
|
||||
for (cfg, want) in [(new, FLOOR_CEILING), (legacy, 0.90)] {
|
||||
let mut pol = AdaptivePolicy::new(cfg);
|
||||
pol.begin_request(0.0);
|
||||
assert_eq!(pol.cfg.min_p_hi, want);
|
||||
pol.begin_request(0.7);
|
||||
assert_eq!(pol.cfg.min_p_hi, 0.7);
|
||||
pol.begin_request(0.0);
|
||||
assert_eq!(pol.cfg.min_p_hi, want);
|
||||
}
|
||||
// the chain floor the plan asks for never exceeds the ceiling of the policy
|
||||
let mut pol = AdaptivePolicy::new(new);
|
||||
pol.begin_request(0.0);
|
||||
let mut rng = Rng(5);
|
||||
for _ in 0..600 {
|
||||
play(&CODE_COSTLY, &mut rng, Some(&mut pol), None);
|
||||
assert!(pol.draft_plan().min_p <= FLOOR_CEILING + 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_smooth_floor_moves_continuously_with_the_bar() {
|
||||
// synthetic, calibrated tables: the floor must not jump by a bucket for a small change of the bar
|
||||
let mut pol = AdaptivePolicy::new({ let mut c = cfg(); c.smooth_floor = true; c });
|
||||
for b in 0..P_BUCKETS {
|
||||
let centre = if b + 1 < P_BUCKETS { 0.5 * (P_EDGES[b] + P_EDGES[b + 1]) as f64 } else { 0.975 };
|
||||
for _ in 0..400 {
|
||||
pol.mtp_bucket[b].add(false, 1.0);
|
||||
}
|
||||
pol.mtp_bucket[b].ok = 400.0 * centre;
|
||||
}
|
||||
let mut last: Option<f32> = None;
|
||||
for step in 0..30 {
|
||||
pol.rate_ewma = 0.10 + 0.002 * step as f64;
|
||||
pol.survive_ewma = 0.5;
|
||||
let p = pol.draft_plan().min_p;
|
||||
if let Some(l) = last {
|
||||
assert!((p - l).abs() < 0.08, "floor jumped from {l} to {p} at step {step}");
|
||||
assert!(p >= l - 1e-6, "floor fell while the bar rose");
|
||||
}
|
||||
last = Some(p);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_trace_is_reproducible() {
|
||||
let run = || {
|
||||
|
||||
@@ -449,8 +449,8 @@ impl OriginalSpecController {
|
||||
self.plan=Some(pol.draft_plan());
|
||||
if trace_enabled() {
|
||||
let plan=self.plan.unwrap_or(DraftPlan{max_drafts:0,min_p:0.0});
|
||||
eprintln!("DBG spec-trace r={} t={} src={:?} acc={} ms={:.2} E={:.2} rate={:.4} explored={} drafts={} next_plan={}/{:.2}",
|
||||
round.round_number,round.t,c.origin,round.accepted,ms,c.expected,c.rate,c.explored as u8,drafts_after,plan.max_drafts,plan.min_p);
|
||||
eprintln!("DBG spec-trace r={} t={} src={:?} acc={} ms={:.2} E={:.2} rate={:.4} explored={} drafts={} next_plan={}/{:.2} bar={:.3} slope={:.2}",
|
||||
round.round_number,round.t,c.origin,round.accepted,ms,c.expected,c.rate,c.explored as u8,drafts_after,plan.max_drafts,plan.min_p,pol.bar(),pol.row_slope_ms());
|
||||
}
|
||||
}
|
||||
_=>{
|
||||
|
||||
@@ -43,7 +43,7 @@ prefix of each as a candidate window and takes the one with the best
|
||||
* **Next chain plan** (`draft_plan`): chain length = peak-held recent width (decays 8 % per round) capped by `max_t - 1`; confidence
|
||||
floor = the smallest draft probability whose calibrated acceptance clears `rate * (row slope + chain step ms) / survival`, i.e.
|
||||
a lower floor when rows are cheap, clamped to `[LELEKA_SPEC_MIN_P_LO, request spec_min_p]` (the operator's value stays the upper
|
||||
bound; 0 means 0.9). The plan is applied to the MTP actor per round (`set_draft_plan`; the actor's `max_drafts` is set from it).
|
||||
bound; 0 means the policy's default ceiling, 0.6 since claude/window-policy, 0.9 before and with `LELEKA_SPEC_POLICY=legacy`, docs/experiments/window-policy-5090.md). The plan is applied to the MTP actor per round (`set_draft_plan`; the actor's `max_drafts` is set from it).
|
||||
|
||||
Verification is untouched. The controller still checks every offered row against the target's own output, commits the accepted
|
||||
prefix and the bonus token. Sampled requests use the existing sampled verification path unchanged (acceptance is equality with the
|
||||
@@ -58,8 +58,11 @@ sampled target token; the policy only chooses how many rows to offer).
|
||||
| `LELEKA_SPEC` / `_MTP_MAX_T` / `_SUFFIX` | unset / spec / 3 | the Original's `--spec`, `--mtp-max-t`, `--suffix-draft`; setting `LELEKA_SPEC` selects the fixed window |
|
||||
| `LELEKA_SPEC_ARMS` | - | `fixed3@0.5,fixed4@0,adaptive@0`: policies one process switches between per request (A/B in one load); `@P` pins the arm's request floor (`spec_min_p`) |
|
||||
| `LELEKA_SPEC_EXPLORE`, `_MARGIN`, `_MIN_P_LO`, `_DRAFT_STEP_MS`, `_COST_ALPHA`, `_DECAY`, `_BIAS_RATE` | 32, 0.02, 0.10, 0.45, 0.12, 0.995, 0.06 | policy constants |
|
||||
| `LELEKA_SPEC_FLOOR_CEILING` | 0.60 | the chain floor's ceiling when the request carries `spec_min_p` 0 (a request value above 0 is the ceiling itself) |
|
||||
| `LELEKA_SPEC_POLICY` | current | `legacy` (or `v1`): the constants of the policy before claude/window-policy (ceiling 0.9) |
|
||||
| `LELEKA_SPEC_ARMS` suffix `~key=value` | - | per-arm policy constants for replays: `adaptive@0.6~step=0.3~explore=0` (keys step explore margin min_p_lo alpha decay bias ceil rowq smooth measured) |
|
||||
| `LELEKA_SPEC_STATS=1` | off | one `DBG spec-stats` line per request: rounds, tokens per round, width and accepted histograms, mean ms per width |
|
||||
| `LELEKA_SPEC_TRACE=1` | off | one `DBG spec-trace` line per timed round (width, source, accepted, round ms, expected tokens, next chain plan) |
|
||||
| `LELEKA_SPEC_TRACE=1` | off | one `DBG spec-trace` line per timed round (width, source, accepted, round ms, expected tokens, next chain plan, the bar a further draft must clear and the row slope in ms) |
|
||||
| smoke: `@file:PATH` lines in `LELEKA_SMOKE_PROMPTS` | - | a whole file as one prompt (code with its newlines); with `LELEKA_SPEC_ARMS` pass p of prompt i uses arm (p+i) mod arms |
|
||||
|
||||
## Wider windows than 6
|
||||
|
||||
@@ -218,6 +218,7 @@ tok/round, which moves by +-0.1 between identical arms.
|
||||
must keep its order, so only the two-pass fusion is safe. Not done.
|
||||
* **Draft before commit in the host order** (the draft would start about 48 us earlier): with the fused commit the commit enqueue costs about 10 us, so there is nothing left to win; and the reorder touches the controller's state machine.
|
||||
* **Pipelined chain** (launch step j+1 before the host read of step j): the adaptive window always runs with a confidence floor, and a speculative step past a failed test writes a ring cell; not safe to do bitwise.
|
||||
* Follow-up: [window-policy-5090](window-policy-5090.md) finds why the window narrows (a step function of the draft floor), screens the policy constants on forced text and changes the default draft-floor ceiling 0.9 -> 0.6 (`LELEKA_SPEC_POLICY=legacy` restores it); the fixed-window gain of section 6 was content, not policy.
|
||||
* `LELEKA_SPEC_DRAFT_STEP_MS` (the adaptive window's constant for the cost of one chain step, 0.45 ms) is now closer to the measured step (about 0.42 ms with the attention switch) than before (0.6); it is a policy parameter, not touched.
|
||||
|
||||
## 8. Reproduce
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
# 5090 decode at 245k: the adaptive window answers a faster draft round with narrower windows; the default policy after it (claude/window-policy)
|
||||
|
||||
Date 2026-11-02/03. RTX 5090 (32 GB), Ryzen 9 9950X3D, driver 595.99, CUDA 13.2, server `rnr5090`, one heavy job at a time under `/data/leleka-e2e/gpu.lock`, sealed KAR memfd held by the holder.
|
||||
Base = `main` f9003b7ce (the draft-round merge with `LELEKA_SM120_ATTN_DAILY_MTP=1` in the rtx5090-32g profile). Workload of the end-to-end runs: the frozen 245k corpus, 5 turns, `--max-output 300`, final-turn input 246,885-247,057 tokens,
|
||||
PCIe share pinned 0.45, seed off, upstream ranked profile, auto slots, `LELEKA_CHAIN=all`, prefix cache auto, `--spec-min-p 0`. Labels: M measured in the run named, E estimate.
|
||||
Follows [draft-round-5090](draft-round-5090.md) sections 5-7: the faster MTP draft shortened every round by 0.366 ms (12 of 12 blocks) and tok/s moved by +0.5 % +- 0.6 % only.
|
||||
|
||||
## 1. Result
|
||||
|
||||
| item | class | status | effect |
|
||||
| --- | --- | --- | --- |
|
||||
| **draft-floor ceiling of the adaptive window 0.9 -> 0.6** (request `spec_min_p` 0; `LELEKA_SPEC_POLICY=legacy` or `LELEKA_SPEC_FLOOR_CEILING=0.9` restores it) | speculation policy, verified tokens unchanged in kind (section 5: inside the policy's own run-to-run envelope, not bitwise, cannot be) | **new engine default** (this branch) | paired A/B at 245k, 8 blocks, one binary: tok/s **+1.63 (+1.09 %), se 1.86, 4 of 8 blocks** (n.s.); tok/round **+4.1 %** (6 of 8), ms/round **+0.39 ms (+3.0 %)** (8 of 8 longer), rows/round +5.9 %, chain steps/round +38 % (8 of 8); on the same forced text (replay) +0.35..+1.7 % |
|
||||
| `LELEKA_DRAFT_FUSED_COMMIT=on` as a third arm | bitwise | **stays opt-in, off** | on top of the new default: tok/s -0.67 (-0.39 %), se 1.66, 4 of 8; ms/round -0.13 ms (7 of 8 shorter) but tok/round -1.3 %; against main c - a +0.64 % (n.s.) |
|
||||
| constants tried and NOT adopted: smooth floor, measured rate, `rowq` 0.5 / 0.75, `step` 0.3, exploration off, ceilings 0.5-0.55, fixed windows | | not adopted | all inside +-1.2 % of main on forced text, section 4 |
|
||||
| `LELEKA_SM120_ATTN_DAILY_MTP=1` in `scripts/e2e/run-e2e.sh`; profile -> engine path checked | harness / test | done | section 7 |
|
||||
|
||||
**The honest size of this.** The draft-round finding stands: a faster draft makes the adaptive window narrower, and that gave back most of the 2.7 % shorter round. What this branch finds is that the optimum of the window policy is **flat** at 245k (every ceiling from 0.9 to 0.6, the fixed window and every constant change are within +-1.2 % of each other on identical forced text),
|
||||
so the policy was never far from the best and there is at most +0.3..+1.7 % to recover: the end-to-end A/B measures +1.1 % +- 1.2 % (n.s.; per-block tok/s differences have sd 5 tok/s from the text each run happens to produce, tok/round moves 0.05-0.2 between identical arms). No pooled measurement of the new default is negative (replay pairs 4 of 5 and 3 of 3 positive; e2e tok/round up in 6 of 8, tok/s up in 4 of 8) and moves the policy back to the depth it had before the faster draft;
|
||||
it is a small, switchable default change, not a resolved speedup. The "fixed window +3.0 %" of draft-round section 6 was not a policy gain (section 4, point 3).
|
||||
|
||||
|
||||
|
||||
## 2. Why a faster round gives a narrower window (M, `runs/window-policy-obs`, bin-dr2, `LELEKA_SPEC_TRACE=1`, one 5-turn run per regime)
|
||||
|
||||
The adaptive window (`original_spec_adaptive.rs`, `docs/adaptive-spec.md`) has two halves. `choose` picks, per round, how many of the offered drafts to verify (tokens per ms with the *measured* cost of each width). `draft_plan` decides what the NEXT
|
||||
round is offered: how many chain steps to run and the confidence floor at which the chain stops. The floor is the lower edge of the first probability bucket (edges 0.25 0.4 0.55 0.7 0.8 0.9 0.95) whose calibrated acceptance clears the *bar*
|
||||
`a_req = rate * (row slope + chain step) / survival` (a further draft is worth producing when `survival * a` tokens beat `rate` tokens per ms of its verify row plus its chain step), clamped to `[0.10, ceiling]`, ceiling = the request's `spec_min_p`, 0 meaning 0.9.
|
||||
|
||||
| | legacy policy (ceiling 0.9) | new default (ceiling 0.6) |
|
||||
| --- | --- | --- |
|
||||
| rounds, tok/round, ms/round (one run each, `runs/window-policy-obs2`, bin-wp1) | 725, 2.072, 13.10 | 705, 2.122, 13.64 |
|
||||
| bar `a_req`: mean (p10 / p90), row slope, token rate | 0.682 (0.593 / 0.797), 1.99 ms, 0.154 tok/ms | 0.693 (0.562 / 0.857), 2.05 ms, 0.151 tok/ms |
|
||||
| floor chosen for the next chain (share of rounds) | 0.8: 62 %, 0.7: 22 %, 0.55: 11 %, 0.9: 5 % | 0.6: 74 %, 0.55: 25 % |
|
||||
| drafts produced per round / verified rows | 1.78 / 2.64 | 2.16 / 2.74 |
|
||||
| width shares t = 1 / 2 / 3 / 4 / 5+ | 7 / 51 / 30 / 4 / 8 % | 10 / 42 / 31 / 5 / 12 % |
|
||||
|
||||
And before the faster draft (`runs/window-policy-obs`, bin-dr2, attention switch off, one run each): floor 0.7 in 75 % of the rounds, 0.8 in 5 %, t = 4 in 14 % of the rounds; with the switch on: floor 0.8 in 73 %, 0.7 in 4 %, t = 4 in 4 %. The 12-block draft-round series moved the same way (rows/round -2.4 %, chain steps/round -4 %).
|
||||
|
||||
**Mechanism (M for the floors and the bar, E for the causal chain).**
|
||||
1. The bar `a_req` is about 0.68 +- 0.1 (rate 0.154 tok/ms x (row slope 2.0 ms + chain step 0.45 ms) / survival of the last row about 0.5). That is the calibrated acceptance of the 0.7-0.8 bucket (prior 0.70, learned 0.70-0.8). The floor is a *step function* of the bar: a bar below the 0.7-0.8 bucket's acceptance gives floor 0.7, above it 0.8, and the next bucket
|
||||
jumps 0.1 in probability. Any change of an input of the bar of a few percent moves the floor by a whole bucket. A faster round raises `rate` (same tokens in less time) and the floor goes from 0.7 to 0.8; the content (the learned acceptance of that bucket) does the same.
|
||||
2. A floor of 0.8 instead of 0.7 stops the chain after every draft below 0.8 (a draft is produced only when the one before it had p >= floor); about a third of the drafts have p in 0.55-0.8. The next round is then offered fewer drafts (1.78 against 2.16 per round) and `choose` can only verify what was produced: rows/round and tokens/round fall.
|
||||
3. The cost model that sets the bar charges every produced draft the full verify row (`slope + step`), but only the drafts the next round chooses pay the row: 70 % of the offered drafts are verified, and of the rounds that were offered three drafts 75 % drop the third (`runs/window-policy-obs`). The bar is therefore an upper bound on what a draft must promise, and `choose` (full information: the calibrated acceptance of the actual row) is the better test for the row. Hence a lower
|
||||
ceiling: the chain may go deeper and `choose` prunes.
|
||||
4. The loss is small because the optimum is flat: removing the marginal rows saved little time and cost little: a row near the bar yields tokens at about the rate it costs (the replay pairs, section 4).
|
||||
|
||||
Not the cause (checked): the cost constant `draft_step_ms` 0.45 ms equals the measured chain step now (0.438 ms wall, `mtp.chain_step`; it sat under the old 0.59). Calibrating it to 0.3 *loses* 1.06 tok/s (0 of 3): a cheaper step lowers the bar, but it also lowers the cost subtracted from every width's round time and the choice gets worse.
|
||||
|
||||
|
||||
## 3. Change
|
||||
|
||||
* `original_spec_adaptive.rs`: `FLOOR_CEILING = 0.60` (the chain floor's upper bound when the request carries `spec_min_p` 0, the product profile) replaces the hard-coded 0.90. A request that names a ceiling (`spec_min_p` > 0) keeps it, exactly as before.
|
||||
* Switches (default-changing config with the old behaviour restorable): `LELEKA_SPEC_POLICY=legacy` (also `v1`) restores every constant of the earlier policy (field-by-field unit test); `LELEKA_SPEC_FLOOR_CEILING=<p>` sets the ceiling; in replays `adaptive@0.9` is the old policy and `adaptive@0.6` the new one in the same process.
|
||||
* Option plumbing for the experiments (default off, the plan rule equals the earlier one for every input, unit test against the kept earlier rule): `rowq`, `smooth`, `measured` and the per-arm `~key=value` suffix of `LELEKA_SPEC_ARMS` (`AdaptiveConfig::set_option`).
|
||||
* `DBG spec-trace` prints the bar and the row slope of the policy (`bar=0.682 slope=1.99`) after the next plan.
|
||||
* Not changed: kernels, verification, the draft numerics, `draft_step_ms`, exploration, the profile (`engine_env` takes only `LELEKA_ORIGINAL_SERVE_*`, `LELEKA_SM120_*` and `LELEKA_CHAIN` keys, so the policy default lives in the engine).
|
||||
* Fused commit: stays off (section 6).
|
||||
|
||||
|
||||
## 4. Screening on forced text (M)
|
||||
|
||||
Instrument: `scripts/e2e/decode/windowpolicy-replay.sh` (+ `-summary.py`). One test-binary process (`rt-wp2`, `rt-wp3`) loads the model once and serves a 5-request capture in teacher-forced replay (`LELEKA_REPLAY_FORCE=1`: every arm decodes exactly the recorded text), production decode
|
||||
shape (auto expert slots, seed off, adaptive tier swaps every 4 rounds, chain kernels, upstream ranked profile, PCIe 0.45, prefix cache reply@8192, the CPU pool at its default, draft attention switch on), with several window policies as `LELEKA_SPEC_ARMS`
|
||||
(`adaptive@P` = adaptive window with the request floor ceiling P, `fixedN@P` = the Original's window, `~key=value` = per-arm policy constants, new in this branch). Arms rotate over the repetitions, so every arm meets every cache/tier state, and every arm decodes the same text: the
|
||||
arms differ only in how they speculate and the noise is timing only. Per-pass tok/s is rebuilt from the per-request `decode_ms` (the `REPLAY PASS` line rounds to 0.1 s = 1.2 %).
|
||||
|
||||
**Replay of night5-long-256k** (`runs/window-policy-rp2`, 10 arms x 3 repetitions, 240 forced tokens x 5 requests, prompts 46k..243k; ms/round 15.3 here against 13.2 in the end-to-end runs, because requests start on a cold tier):
|
||||
|
||||
| arm | tok/s | tok/round | ms/round | paired against adaptive@0 (= ceiling 0.9, main) |
|
||||
| --- | ---: | ---: | ---: | --- |
|
||||
| adaptive@0 (ceiling 0.9, main) | 139.09 | 2.131 | 15.32 | |
|
||||
| adaptive@0.7 | 139.54 | 2.167 | 15.53 | +0.44 (se 0.25), 3 of 3 |
|
||||
| **adaptive@0.6** | **140.81** | 2.232 | 15.85 | **+1.72 (se 0.52), 3 of 3** |
|
||||
| adaptive@0.5 | 138.23 | 2.226 | 16.11 | -0.86 (se 0.91), 1 of 3 |
|
||||
| fixed4@0.5 | 138.36 | 2.093 | 15.13 | -0.74 (se 0.26), 0 of 3 |
|
||||
| rowq=0.5 | 138.70 | 2.244 | 16.18 | -0.40 (se 0.17), 0 of 3 |
|
||||
| smooth floor | 138.32 | 2.131 | 15.41 | -0.76 (se 1.08) |
|
||||
| measured rate | 139.01 | 2.145 | 15.43 | -0.09 (se 0.48) |
|
||||
| explore=0 | 140.06 | 2.151 | 15.36 | +0.97 (se 0.71), 2 of 3 |
|
||||
| step=0.3 | 138.03 | 2.147 | 15.55 | -1.06 (se 0.15), 0 of 3 |
|
||||
|
||||
**Replay of the end-to-end workload itself** (`runs/window-policy-cap` is the e2e run that wrote the capture `/data/leleka-e2e/window-policy/capture/corpus245`; `runs/window-policy-rp3c`, 8 arms x 5 repetitions, 300 forced tokens x 5 requests, prompts 46k..247k, ms/round 14.6-15.4):
|
||||
|
||||
| arm | tok/s | sd | tok/round | ms/round | paired against adaptive@0.9 (main) |
|
||||
| --- | ---: | ---: | ---: | ---: | --- |
|
||||
| adaptive@0.9 (main) | 136.24 | 0.38 | 1.990 | 14.61 | |
|
||||
| adaptive@0.7 | 136.81 | 0.62 | 2.046 | 14.95 | +0.57 (se 0.40), 4 of 5 |
|
||||
| adaptive@0.65 | 136.78 | 1.24 | 2.061 | 15.07 | +0.55 (se 0.77), 2 of 5 |
|
||||
| **adaptive@0.6 (the new default)** | 136.59 | 0.69 | 2.089 | 15.29 | +0.35 (se 0.27), 4 of 5 |
|
||||
| adaptive@0.55 | 135.57 | 1.40 | 2.093 | 15.44 | -0.67 (se 0.76), 1 of 5 |
|
||||
| fixed4@0.5 | 136.35 | 0.39 | 2.011 | 14.75 | +0.11 (se 0.16), 3 of 5 |
|
||||
| adaptive@0.6, explore=0 | 136.71 | 0.18 | 2.068 | 15.13 | +0.47 (se 0.24), 4 of 5 |
|
||||
| adaptive@0.9, rowq=0.75 | 136.75 | 0.85 | 2.068 | 15.13 | +0.51 (se 0.54), 4 of 5 |
|
||||
|
||||
Reading: the landscape is **flat**. Every ceiling from 0.9 to 0.55, the fixed window and every constant change are within +-1.2 % of main (pass-to-pass sd 0.4-1.4 tok/s). What the data resolve:
|
||||
1. A lower ceiling buys depth, not speed: tok/round 1.99 -> 2.09 (+5 %) for ms/round 14.6 -> 15.3 (+4.7 %), net +0.3..+0.6 % on the e2e workload and +0.4..+1.7 % on night5 for ceilings 0.7 and 0.6; below 0.6 the extra depth costs more than it gives (0.55 and 0.5 are negative on both).
|
||||
2. The other candidates are not better than the ceiling: the smooth floor, the measured rate, a cheaper chain step (0.3: -1.06, 0 of 3) do nothing or lose; the production-cost factor `rowq` 0.75 is worth about what the ceiling is, 0.5 goes too deep.
|
||||
3. The adaptive window is not worse than the fixed window at 245k with the new draft (fixed4@0.5: -0.74 on night5, +0.11 on the e2e capture): the "fixed window +2.8 %" of draft-round section 6 was content (one deterministic text path, 2.063 tok/round), not policy.
|
||||
4. Exploration off (+0.5..+1.0, 4 of 5 and 2 of 3) is suggestive and not resolved; it is the price of probing widths on real sessions and is left alone.
|
||||
|
||||
|
||||
## 5. Identity
|
||||
|
||||
`scripts/e2e/decode/windowpolicy-id.sh` (`runs/window-policy-id1`, test binary `rt-wp3` = the branch build): teacher-forced replay of night5-long-256k, 5 requests x 240 forced tokens, production shape, **adaptive window** (the draft-round gate of draft-round-5090 section 4 ran a fixed window,
|
||||
`LELEKA_SPEC=4`, whose widths cannot move and so proves nothing about a window policy), `ADAPT_EVERY=4`, 8000 slots, seed off, `LELEKA_TRACE_LOGPROBS=16`, draft attention switch on in both; one process per setting, two identical arms in each (I1, I2). P1 = `LELEKA_SPEC_POLICY=legacy` (ceiling 0.9, main's
|
||||
behaviour), P2 = the new default. Compared: the top-16 (token id, logprob) rows of every window row (`q_pair`: a row is keyed by request, position and the window's inputs up to the row, so windows cut differently still meet on rows of the same context), and their argmax; `q_tail_gate` (Original envelope: d_top1 p99 <= 0.22, max <= 0.43, flips <= 2.8 %).
|
||||
|
||||
**Result: not bitwise identical, and it cannot be.** The adaptive policy chooses widths from measured times, so two runs of the SAME build cut their windows differently, and the verifier rounds a row differently at different batch widths (the batch-rounding envelope of `docs/adaptive-spec.md`). The A/A floor is 518 of 1,159 common rows identical (P1) and 119 of 1,057 (P2), not 100 %. So the gate is read against that floor:
|
||||
|
||||
| comparison | common rows | identical | argmax flips | d_top1 of the differing rows (median / p99 / max) |
|
||||
| --- | ---: | ---: | ---: | --- |
|
||||
| A/A, P1 (legacy), I2 against I1 | 1,159 | 518 | 18 (1.55 %) | 0.0021 / 0.2299 / 0.5727 |
|
||||
| A/A, P2 (new default), I2 against I1 | 1,057 | 119 | 14 (1.32 %) | 0.0039 / 0.1950 / 0.4622 |
|
||||
| new against legacy, arm I1 | 1,012 | 6 | 19 (1.88 %) | 0.0043 / 0.1978 / 0.6390 |
|
||||
| new against legacy, arm I2 | 1,016 | 6 | 20 (1.97 %) | 0.0047 / 0.1997 / 0.5466 |
|
||||
| `q_tail_gate`, P1 (I2 vs I1, rows 1,208) | | | 17 (1.41 %) | p99 0.1768, max 0.5727: outside (max), FAIL |
|
||||
| `q_tail_gate`, P2 (I2 vs I1, rows 1,205) | | | 17 (1.41 %) | p99 0.1674, max 0.3840: within, PASS |
|
||||
|
||||
The new policy against the old one is not distinguishable from the old policy's own run-to-run noise on these rows: p99 0.198-0.200 against 0.230 (A/A legacy), flips 1.9-2.0 % against 1.55 % (A/A legacy) and 1.3-1.4 % (A/A new), all below the 2.8 % bound; the largest single d_top1 (0.639) is above the legacy A/A maximum (0.573).
|
||||
This is the class of every earlier window-shape change (R3, `--spec 2`, in `docs/quality-gate.md`): the policy decides how much is speculated, the emitted token is the verifier's own argmax at its window width. What is exact: (1) the controller unit tests with the new default (`the_adaptive_window_emits_the_same_text_as_a_fixed_one_under_any_drafter`, `output_is_the_greedy_text_for_every_window_shape_noise_and_stop_rule`; fake target, perfect / poor / failing drafters) pass;
|
||||
(2) `AdaptiveConfig` under `LELEKA_SPEC_POLICY=legacy` equals the earlier constants field by field and the plan rule equals the kept earlier rule (unit tests); (3) verification, the draft numerics and the kernels are untouched (the behavioural diff is the ceiling constant). Limits: 5 requests x 240 tokens, 8000-slot tier (the product runs auto slots), greedy only.
|
||||
|
||||
|
||||
## 6. Paired A/B at 245k
|
||||
|
||||
`runs/window-policy-ab1` (the directory names end in `-v2`, an environment tag of the holder), 24 VALID runs, **one binary `dt/bin-wp1`** (claude/window-policy e57562740) for every arm, PCIe 0.45, seed off, upstream ranked profile, `--spec-min-p 0`, frozen corpus, 5 turns x 300 tokens, final-turn input 246,885-247,057, the order rotated over a b c block by block (positions balanced:
|
||||
`windowpolicy-ab.sh`), all arms with the draft attention switch: **a** = `LELEKA_SPEC_POLICY=legacy` (main f9003b7ce's policy), **b** = the new defaults, **c** = new defaults + `LELEKA_DRAFT_FUSED_COMMIT=on`. Validity as in draft-round section 5 (24 of 24 valid; `settle.txt` of every run lists no other job besides the idle holder, load1 0.46-0.64 at the start, 1.38 for the first run). tok/s = tokens over seconds of the five decode windows; tok/round = tokens over rounds; ms/round = decode seconds over rounds.
|
||||
|
||||
| block | order | a tok/s | b tok/s | c tok/s | a / b / c tok/round | a / b / c ms/round | a / b / c rows/round |
|
||||
| ---: | --- | ---: | ---: | ---: | --- | --- | --- |
|
||||
| 1 | a b c | 152.2 | 160.9 | 160.7 | 2.022 / 2.216 / 2.203 | 13.281 / 13.768 / 13.703 | 2.623 / 2.903 / 2.834 |
|
||||
| 2 | b c a | 155.3 | 157.7 | 151.9 | 2.052 / 2.125 / 2.022 | 13.213 / 13.477 / 13.307 | 2.628 / 2.684 / 2.677 |
|
||||
| 3 | c a b | 158.6 | 155.6 | 162.2 | 2.131 / 2.113 / 2.229 | 13.437 / 13.580 / 13.744 | 2.685 / 2.728 / 2.927 |
|
||||
| 4 | a c b | 155.6 | 161.2 | 153.6 | 2.066 / 2.209 / 2.044 | 13.280 / 13.709 / 13.306 | 2.657 / 2.887 / 2.707 |
|
||||
| 5 | c b a | 160.4 | 154.1 | 157.0 | 2.174 / 2.101 / 2.137 | 13.549 / 13.636 / 13.609 | 2.781 / 2.805 / 2.801 |
|
||||
| 6 | b a c | 154.4 | 154.4 | 155.3 | 2.022 / 2.134 / 2.134 | 13.096 / 13.824 / 13.736 | 2.608 / 2.787 / 2.785 |
|
||||
| 7 | a b c | 158.2 | 156.9 | 158.1 | 2.101 / 2.152 / 2.122 | 13.278 / 13.717 / 13.418 | 2.699 / 2.846 / 2.765 |
|
||||
| 8 | b c a | 153.8 | 160.9 | 157.3 | 2.033 / 2.216 / 2.140 | 13.217 / 13.771 / 13.607 | 2.612 / 2.901 / 2.739 |
|
||||
|
||||
| over the 8 blocks | a (legacy) | b (new default) | c (new + fused commit) |
|
||||
| --- | --- | --- | --- |
|
||||
| tok/s | 156.06 (sd 2.78) | 157.69 (sd 2.98) | 157.01 (sd 3.43) |
|
||||
| tok/round | 2.075 (sd 0.056) | 2.158 (sd 0.048) | 2.129 (sd 0.070) |
|
||||
| ms/round | 13.294 (sd 0.140) | 13.685 (sd 0.115) | 13.554 (sd 0.185) |
|
||||
| rows/round, accepted/round, chain steps/round | 2.662, 1.080, 0.900 | 2.818, 1.164, 1.233 | 2.779, 1.134, 1.262 |
|
||||
| `round.draft_committed`, `commit.wait`, `mtp.finish_first_step` (ms/round) | 1.228, 0.465, 0.034 | 1.400, 0.465, 0.035 | 1.349, 0.084, 0.410 |
|
||||
|
||||
| block-paired difference (mean, se) | tok/s | tok/round | ms/round | rows/round | blocks better |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| **b - a** | **+1.63 (+1.09 %), se 1.86** | +0.083 (+4.1 %), se 0.033 | +0.391 (+3.0 %), se 0.076 | +0.156 (+5.9 %) | tok/s 4 of 8, tok/round 6 of 8, ms/round longer in 8 of 8 |
|
||||
| c - a | +0.96 (+0.64 %), se 1.46 | +0.054 (+2.6 %), se 0.029 | +0.260 (+2.0 %), se 0.076 | +0.118 | tok/s 4 of 8, tok/round 5 of 8 |
|
||||
| c - b | -0.67 (-0.39 %), se 1.66 | -0.029 (-1.3 %), se 0.031 | -0.131 (-1.0 %), se 0.061 | -0.038 | tok/s 4 of 8, ms/round shorter in 7 of 8 |
|
||||
|
||||
Per-block b - a tok/s: +8.7 +2.4 -3.0 +5.6 -6.4 -0.0 -1.3 +7.1. **Reading.** The policy does what the replay predicts: it asks for 38 % more chain steps (0.90 -> 1.23 per round, 8 of 8 blocks), verifies 5.9 % more rows, gets 4.1 % more tokens per round for 3.0 % more time per round; the net is +1.1 %, which is inside the noise of 8 blocks (se 1.2 %):
|
||||
not significant, same sign as every replay. The marginal rows now cost 0.39 ms / 0.083 tok = 4.7 ms per token, the average 6.4 ms per token, so they are still worth taking (0.21 tok/ms against the average 0.156). The stopping rule (8 blocks) was fixed before the run; with a paired sd of 5.3 tok/s, resolving 1 % at two standard errors takes about 45 blocks (about 9 GPU-hours for two arms), so no extension.
|
||||
|
||||
**Fused commit** (arm c): on top of the new default it shortens the round by 0.131 +- 0.061 ms (7 of 8 blocks; `commit.wait` 0.465 -> 0.084 ms, the host waits for the first draft graph instead, `mtp.finish_first_step` 0.034 -> 0.410), consistent with draft-round section 6 (-0.024 +- 0.046 ms with the old policy). tok/s does not follow (-0.39 %, 4 of 8): neutral at best. It is bitwise and harmless, and it is not the best variant by this measurement: **it stays opt-in**.
|
||||
|
||||
|
||||
## 7. Harness and profile path
|
||||
|
||||
* `scripts/e2e/run-e2e.sh` now exports `LELEKA_SM120_ATTN_DAILY_MTP=${LELEKA_SM120_ATTN_DAILY_MTP:-1}`, like the rtx5090-32g profile (only the value `1` enables it; `=0` restores the old kernels). `draftround-ab.sh` and the older job scripts `unset` it before their own arm words, so their
|
||||
arms are unchanged.
|
||||
* The profile's `engine_env` reaches the engine: `Profile::builtin("rtx5090-32g")` -> `RunConfig.profile.engine_env` (saved in `leleka.json`) -> `RunConfig::engine_environment()` -> `Supervisor::start_engine` -> `child_env` (`command.env(key, value)` for every pair, also for the `leleka exec-inherit` wrapper that
|
||||
execs the engine). Evidence: unit test `config::tests::the_server_profile_switches_reach_the_engine_environment_through_the_saved_config` (JSON round trip of the saved config; the operator's `engine_env` wins) and
|
||||
`leleka up --dry-run --profile rtx5090-32g` (laptop, WSL), which prints `engine environment: LELEKA_CHAIN=all ... LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_SM120_ATTN_DAILY_MTP=1`. The laptop profile does not carry it.
|
||||
`engine_env` accepts only `LELEKA_ORIGINAL_SERVE_*`, `LELEKA_SM120_*` and `LELEKA_CHAIN` keys; the window policy is therefore an engine default, not a profile key.
|
||||
|
||||
## 8. Reproduce and paths
|
||||
|
||||
* Build: WSL release from an LF worktree (`git ls-files --eol` shows `w/lf` for the `.ptx`; on the laptop `git -c core.autocrlf=false checkout-index` after removing the files, and **edit shell scripts with LF line endings**: a Python text-mode edit on Windows turned two scripts into CRLF and the first replay job died with `set: pipefail: invalid option name`), binaries `dt/bin-wp1` (e57562740) and test binaries `dt/rt-wp1`, `rt-wp2`, `rt-wp3`.
|
||||
* Screening: `windowpolicy-replay.sh` (stubs `wp-rp2.sh` night5, `wp-rp3c.sh` e2e capture; summary `windowpolicy-replay-summary.py`). Identity: `windowpolicy-id.sh` (stub `wp-id1.sh`). A/B: `windowpolicy-ab.sh` + `windowpolicy-analyze.py` (stub `wp-ab1.sh`); inputs installed read-only with a sha256 manifest by `windowpolicy-install.sh`
|
||||
(`/data/leleka-e2e/window-policy/{tools,scripts,MANIFEST.sha256}`). Observation runs: `wp-obs-a/b/c` (bin-dr2), `wp-obs2` (bin-wp1, bar in the trace), capture run `wp-cap`.
|
||||
* Server paths created (all under `/data/leleka-e2e`): `window-policy/{tools,scripts,src,capture/corpus245,MANIFEST.sha256}`, `runs/window-policy-{obs,obs2,scan,cap,rp1,rp2,rp3c,id1,ab1}`, `decode/dt/{bin-wp1,rt-wp1,rt-wp2,rt-wp3}`, stubs `wp-*.sh` in `~/work/gpu-runs/holder2/jobs`. `runs/window-policy-rp1` is the killed replay with a single CPU worker (not the product shape; kept as evidence of that mistake);
|
||||
`runs/window-policy-scan` (fixed-window scan: spec 3 / 5 / 6 at floor 0.5, spec 4 / 5 at floor 0.3) overlaps other agents' cold-load I/O experiments and is indicative only.
|
||||
* Disturbances: between 19:05Z and 19:50Z on 2026-11-02 another agent's `bulk_read_bench` (32 O_DIRECT readers on the KAR file, load average 33) ran during my fixed-window scan (one turn at 22.7 ms/round); the server then lost its Wi-Fi link 21:35-22:46Z (not caused by these jobs). The A/B and the replays above ran after both.
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bash
|
||||
# window-policy: paired ours-vs-ours A/B on the RTX 5090 at ~245k context (copy of draftround-ab.sh with three arms and its own manifest). HOLDER JOB (rnr5090).
|
||||
# Install: scripts/e2e/decode/windowpolicy-install.sh (copies the tools and scripts/e2e to /data/leleka-e2e/window-policy, read-only, MANIFEST.sha256 of every input);
|
||||
# stub ~/work/gpu-runs/holder2/jobs/<job>.sh = `#!/usr/bin/env bash` + env lines + `exec bash /data/leleka-e2e/window-policy/tools/windowpolicy-ab.sh`.
|
||||
#
|
||||
# Arms "a", "b" and (optional) "c" are configurations of ours: A_BIN/B_BIN/C_BIN (a directory under dt/, may be the same) and A_ENV/B_ENV/C_ENV (extra KEY=VALUE words).
|
||||
# BLOCKS: with two arms odd blocks run a b and even blocks b a; with C_BIN set every block is a rotation of a b c (block 1 a b c, 2 b c a, 3 c a b, 4 a c b, 5 c b a, 6 b a c, ...).
|
||||
# Everything else is the shipped shape of baseline-pair-ab.sh `ours45`: seed off, upstream ranked profile, auto expert slots, budget 32819404800, spec-min-p 0,
|
||||
# prefix cache auto, PCIe share pinned (PCIE_FRAC, default 0.45), 5 turns to ~245k, --max-output 300, final-turn input >= 200k tokens, no vanilla lossy switch.
|
||||
# BLOCKS="1 2 3 4 5": odd block runs a then b, even block b then a (alternating order). A block is the unit of pairing.
|
||||
# PROFILE=1: every run also loads the CUPTI tracer and writes one 20 s window over turn 5 (dir <run>/win-turn5.lct); the window perturbs the run slightly, profile runs are not A/B data.
|
||||
set -uo pipefail
|
||||
DR=/data/leleka-e2e/window-policy
|
||||
DRT=/data/leleka-e2e/draft-round
|
||||
D=/data/leleka-e2e/decode/dt
|
||||
LOCK=/data/leleka-e2e/gpu.lock
|
||||
OUTR=${OUTR:?OUTR}
|
||||
CORPUS=/data/leleka-e2e/decode/corpus/src/crates
|
||||
UP=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin
|
||||
BLOCKS=${BLOCKS:-"1 2 3 4 5"}
|
||||
RUN_TAG=${RUN_TAG:-}
|
||||
PCIE_FRAC=${PCIE_FRAC:-0.45}
|
||||
SPEC_MIN_P=${SPEC_MIN_P:-0} # the request's draft confidence floor (the product profile: 0 with the adaptive window)
|
||||
A_BIN=${A_BIN:?A_BIN}; B_BIN=${B_BIN:-$A_BIN}; C_BIN=${C_BIN:-}; A_ENV=${A_ENV:-}; B_ENV=${B_ENV:-}; C_ENV=${C_ENV:-}
|
||||
SESSION_ARGS="--turns 5 --target-tokens 245000 --max-output 300 --min-final-tokens 200000"
|
||||
WIN_S=${WIN_S:-20}
|
||||
LIB=$DRT/tools/libleleka_cupti_trace.so
|
||||
mkdir -p "$OUTR"
|
||||
|
||||
( cd / && sha256sum --quiet -c "$DR/MANIFEST.sha256" ) || { echo "window-policy: MANIFEST.sha256 check failed" >&2; exit 3; }
|
||||
for f in "$UP" "$CORPUS/backend-api/src/lib.rs" "$D/$A_BIN/leleka-inference" "$D/$B_BIN/leleka-inference" "$DRT/tools/ts-wrap.sh"; do
|
||||
[ -r "$f" ] || { echo "missing $f" >&2; exit 3; }
|
||||
done
|
||||
|
||||
settle() { # $1 run dir
|
||||
local n=0 t l
|
||||
while [ $n -lt 30 ]; do
|
||||
t=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits | head -1)
|
||||
[ "${t:-99}" -le 48 ] && break
|
||||
sleep 5; n=$((n + 1))
|
||||
done
|
||||
echo "gpu_temp_c=$t cooled_after_s=$((n * 5))" >"$1/settle.txt"
|
||||
n=0
|
||||
while [ $n -lt 24 ]; do
|
||||
l=$(cut -d" " -f1 /proc/loadavg)
|
||||
awk -v l="$l" 'BEGIN{exit !(l < 0.5)}' && break
|
||||
sleep 5; n=$((n + 1))
|
||||
done
|
||||
echo "load1=$l quiet_after_s=$((n * 5))" >>"$1/settle.txt"
|
||||
{ date -u +%FT%TZ; uptime; free -m | sed -n 2p; nvidia-smi --query-gpu=clocks.sm,clocks.mem,temperature.gpu,power.draw,pstate --format=csv,noheader
|
||||
echo "top processes by cpu (other agents' work shows here):"; ps -eo pid,etime,pcpu,cmd --sort=-pcpu | sed -n 2,6p | cut -c1-200; } >>"$1/settle.txt"
|
||||
}
|
||||
|
||||
watch_and_trigger() { # $1 client log, $2 trigger file, $3 out dir
|
||||
for _ in $(seq 1 15000); do
|
||||
if grep -q '"turn": 4' "$1" 2>/dev/null; then
|
||||
printf '{"seconds": %s, "out": "%s/win-turn5", "label": "turn5"}\n' "$WIN_S" "$3" >"$2.tmp" && mv "$2.tmp" "$2"
|
||||
echo "$(date +%s.%N) trigger written" >>"$3/trigger.log"; return 0
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
}
|
||||
|
||||
ours() { # $1 tag, $2 run dir, $3 bin dir, $4 extra env words
|
||||
local tag=$1 R=$2 bin=$3 xenv=$4
|
||||
( export E2E_BIN=$D/$bin E2E_OUT=$R
|
||||
export LELEKA_BRINGUP_TRACE=1 LELEKA_PREFIX_TRACE=1
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto E2E_GPU_BUDGET=${GPU_BUDGET:-32819404800}
|
||||
export E2E_ENGINE_ARGS="--prefix-cache-mib auto --prefix-cache-tail reply --original-prefill-capacity 8192 --prefix-cache-block 8192 --spec-min-p ${SPEC_MIN_P:-0}"
|
||||
export E2E_SAMPLE_S=10 LELEKA_CHAIN=all
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$UP
|
||||
unset LELEKA_FOOTPRINT_LEGACY LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS LELEKA_SM120_ATTN_DAILY LELEKA_SM120_GU_SWIGLU LELEKA_SM120_SIDE_MIXER LELEKA_SM120_PERF LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB LELEKA_ROUTE_TAIL_SKIP
|
||||
unset LELEKA_HUGEPAGES LELEKA_BANK_THP LELEKA_DRAFT_FUSED_COMMIT LELEKA_DRAFT_ROUND LELEKA_SM120_ATTN_DAILY_MTP LELEKA_SPEC LELEKA_SPEC_ADAPTIVE LELEKA_SPEC_POLICY LELEKA_SPEC_EXPLORE LELEKA_SPEC_DRAFT_STEP_MS LELEKA_SPEC_MARGIN LELEKA_SPEC_MIN_P_LO LELEKA_SPEC_COST_ALPHA LELEKA_SPEC_DECAY LELEKA_SPEC_BIAS_RATE
|
||||
export LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_ORIGINAL_SERVE_PCIE_FRAC=$PCIE_FRAC
|
||||
for kv in $xenv; do export "$kv"; done
|
||||
{ echo "tag=$tag bin=$bin extra=[$xenv]"; date -u +%FT%TZ; free -g | sed -n 2p; uptime; sha256sum "$UP" "$E2E_BIN"/leleka-inference "$E2E_BIN"/leleka-daemon "$E2E_BIN"/leleka-cli "$E2E_BIN"/strata-next
|
||||
cat "$E2E_BIN/COMMIT.txt" 2>/dev/null; head -1 /data/leleka-e2e/decode/corpus/MANIFEST.txt
|
||||
env | grep -E '^(LELEKA_|STRATA_|E2E_)' | sort; } >"$R/env-arm.txt"
|
||||
export E2E_RUN_CMD="bash $DRT/tools/ts-wrap.sh $R/client.ts.log python3 -I $D/tools/long-session.py --src $CORPUS $SESSION_ARGS"
|
||||
if [ "${PROFILE:-0}" = 1 ]; then
|
||||
export LELEKA_CUPTI_LIB=$LIB LELEKA_CUPTI_TRIGGER=$R/cupti.trigger LCT_MAX_SECONDS=60 LD_LIBRARY_PATH=$DRT/cupti/lib:${LD_LIBRARY_PATH:-}
|
||||
watch_and_trigger "$R/client.ts.log" "$R/cupti.trigger" "$R" &
|
||||
W=$!
|
||||
fi
|
||||
bash "$DR/scripts/e2e/run-e2e.sh" 2>&1 | grep -a -E "^\{|expert cache|request outcome|ready after|rc=|refus|error|Error|long_session|client exit|\[lct\]" | cut -c1-300
|
||||
if [ "${PROFILE:-0}" = 1 ]; then for _ in $(seq 1 60); do [ -e "$R/cupti.trigger.done" ] && break; sleep 1; done; kill $W 2>/dev/null; fi
|
||||
echo "run-e2e done $tag $(date -u +%FT%TZ)" )
|
||||
}
|
||||
|
||||
validity() { # $1 run dir
|
||||
python3 -I - "$1" <<'PY'
|
||||
import json, os, re, sys
|
||||
d = sys.argv[1]
|
||||
f = os.path.join(d, "long-session.json")
|
||||
verdict = "INVALID: no long-session.json"
|
||||
if os.path.exists(f):
|
||||
t = json.load(open(f))
|
||||
final = (t[-1].get("input_tokens") or 0) if t else 0
|
||||
if any("error" in r for r in t):
|
||||
verdict = "INVALID: a turn failed"
|
||||
elif len(t) < 5 or final < 200000:
|
||||
verdict = "INVALID: %d turns, final-turn input tokens %d < 200000 (short corpus?)" % (len(t), final)
|
||||
else:
|
||||
verdict = "VALID: 5 turns, final-turn input tokens %d" % final
|
||||
wins, last = [], []
|
||||
for ln in open(os.path.join(d, "inference.log"), errors="replace"):
|
||||
if ln.startswith("DBG window "):
|
||||
last.append(dict((k, float(v)) for k, v in re.findall(r"(\w+)=([-\d.]+)", ln)))
|
||||
elif "leleka-serve request outcome" in ln:
|
||||
wins.append(last); last = []
|
||||
w = wins[-1] if wins else []
|
||||
ple = sum(x.get("ple", 0) for x in w) / max(len(w), 1)
|
||||
verdict += "; turn-5 window.ple mean %.2f ms over %d windows" % (ple, len(w))
|
||||
if not w:
|
||||
verdict = "INVALID: no turn-5 window lines (trace env missing?)"
|
||||
elif ple >= 5:
|
||||
verdict = "INVALID: turn-5 window.ple mean %.2f ms >= 5 ms (PLE scan back?)" % ple
|
||||
open(os.path.join(d, "VALIDITY.txt"), "w").write(verdict + "\n")
|
||||
print(os.path.basename(d), verdict)
|
||||
PY
|
||||
}
|
||||
|
||||
LIST=""
|
||||
if [ -n "${ENTRIES:-}" ]; then LIST="$ENTRIES"
|
||||
else
|
||||
for b in $BLOCKS; do
|
||||
if [ -n "$C_BIN" ]; then
|
||||
case $(( (b - 1) % 6 )) in
|
||||
0) o="a b c" ;; 1) o="b c a" ;; 2) o="c a b" ;; 3) o="a c b" ;; 4) o="c b a" ;; 5) o="b a c" ;;
|
||||
esac
|
||||
set -- $o; LIST="$LIST $b:1:$1 $b:2:$2 $b:3:$3"
|
||||
elif [ $((b % 2)) = 1 ]; then LIST="$LIST $b:1:a $b:2:b"; else LIST="$LIST $b:1:b $b:2:a"; fi
|
||||
done
|
||||
fi
|
||||
for ent in $LIST; do
|
||||
bn=${ent%%:*}; rest=${ent#*:}; pos=${rest%%:*}; arm=${rest#*:}
|
||||
tag=$(printf "b%02dp%d-%s%s" "$bn" "$pos" "$arm" "$RUN_TAG"); R=$OUTR/$tag
|
||||
[ -e "$DR/STOP" ] && { echo "STOP file present, ending before $tag"; exit 0; }
|
||||
got=0
|
||||
for _ in $(seq 1 1080); do
|
||||
if mkdir "$LOCK" 2>/dev/null; then echo "window-policy $tag $(date -u +%FT%TZ)" >"$LOCK/owner"; got=1; break; fi
|
||||
sleep 5
|
||||
done
|
||||
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; exit 3; }
|
||||
echo "=== $tag $(date -u +%FT%TZ)"
|
||||
if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader)" ]; then
|
||||
echo "GPU busy, skipping $tag"; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; continue
|
||||
fi
|
||||
mkdir -p "$R"; echo "block=$bn pos=$pos arm=$arm" >"$R/ARM.txt"
|
||||
settle "$R"
|
||||
case $arm in
|
||||
a) ours "$tag" "$R" "$A_BIN" "$A_ENV" ;;
|
||||
b) ours "$tag" "$R" "$B_BIN" "$B_ENV" ;;
|
||||
c) ours "$tag" "$R" "$C_BIN" "$C_ENV" ;;
|
||||
esac
|
||||
for lg in "$R/inference.log"; do [ -r "$lg" ] && grep -a -E "arena|huge|PCIe probe|pcie_frac|CPU pool|pool workers|expert cache|memory guard|Cpus|pinned|affin" "$lg" | head -60 | cut -c1-300; done >"$R/startup.txt"
|
||||
{ echo "after the run: $(date -u +%FT%TZ) $(cat /proc/loadavg)"; ps -eo pid,etime,pcpu,cmd --sort=-pcpu | sed -n 2,4p | cut -c1-200; } >>"$R/settle.txt"
|
||||
validity "$R"
|
||||
echo "arm done $tag $(date -u +%FT%TZ)"
|
||||
rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null
|
||||
sleep 15
|
||||
done
|
||||
[ -r "$DR/tools/windowpolicy-analyze.py" ] && python3 -I "$DR/tools/windowpolicy-analyze.py" "$OUTR" > "$OUTR/ANALYSIS.$(date -u +%Y%m%dT%H%M%SZ).txt" 2>&1
|
||||
echo "window-policy job done $(date -u +%FT%TZ)"
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Analysis of windowpolicy-ab.sh runs (arms a, b and optionally c): per run all-turn tok/s (tokens over seconds), tok/round, ms/round, verified rows per round,
|
||||
accepted per round, chain steps per round; per arm mean/sd; block-paired differences b - a, c - a, c - b with the per-block values.
|
||||
|
||||
python3 -I windowpolicy-analyze.py <outroot> [<outroot> ...]
|
||||
|
||||
A run directory is <root>/b<NN>p<P>-<a|b|c>[tag]; VALIDITY.txt must start with VALID or the run is listed and left out (a block missing an arm drops out of the pairs it needs).
|
||||
tok/s = total output tokens / total decode seconds (decode seconds of a turn = tokens / the client's decode_tok_s)
|
||||
tok/round = tokens / rounds ('rounds=' of the request outcome lines); ms/round = decode seconds / rounds * 1000
|
||||
rows/round, accepted/round, chain steps/round: the profile spans round.T, round.acc, mtp.chain_step (count) of the request profile lines, summed over the requests / rounds
|
||||
"""
|
||||
import glob, json, math, os, re, statistics, sys
|
||||
|
||||
SPANS = ["round.run_window", "round.apply_pending", "round.draft_committed", "commit.wait", "mtp.finish_first_step", "mtp.chain_step"]
|
||||
|
||||
|
||||
def run_stats(d):
|
||||
j = json.load(open(os.path.join(d, "long-session.json")))
|
||||
toks = [r["output_tokens"] for r in j]
|
||||
secs = [r["output_tokens"] / r["decode_tok_s"] for r in j]
|
||||
rounds, prof = [], []
|
||||
cur = None
|
||||
for ln in open(os.path.join(d, "inference.log"), errors="replace"):
|
||||
if ln.startswith("DBG profile request:"):
|
||||
cur = {m[0]: (float(m[1]), int(m[2])) for m in re.findall(r"(\S+?)=([\d.]+)/(\d+)", ln)}
|
||||
elif "leleka-serve request outcome" in ln:
|
||||
rounds.append(int(re.search(r"rounds=(\d+)", ln).group(1)))
|
||||
prof.append(cur or {})
|
||||
cur = None
|
||||
R = sum(rounds)
|
||||
out = {"turns": [r["decode_tok_s"] for r in j], "tok_s": sum(toks) / sum(secs), "tok_round": sum(toks) / R, "ms_round": sum(secs) / R * 1000, "rounds": R}
|
||||
out["rows_round"] = sum(p.get("round.T", (0, 0))[0] for p in prof) / R
|
||||
out["acc_round"] = sum(p.get("round.acc", (0, 0))[0] for p in prof) / R
|
||||
out["steps_round"] = sum(p.get("mtp.chain_step", (0, 0))[1] for p in prof) / R
|
||||
for s in SPANS:
|
||||
out[s] = sum(p.get(s, (0.0, 0))[0] for p in prof) / R
|
||||
return out
|
||||
|
||||
|
||||
def sd(v):
|
||||
return statistics.stdev(v) if len(v) > 1 else float("nan")
|
||||
|
||||
|
||||
def main():
|
||||
runs = {}
|
||||
for root in sys.argv[1:]:
|
||||
for d in sorted(glob.glob(os.path.join(root, "b*p*-*"))):
|
||||
m = re.match(r"b(\d+)p(\d+)-([abc])(.*)", os.path.basename(d))
|
||||
if not os.path.isdir(d) or not m:
|
||||
continue
|
||||
ver = open(os.path.join(d, "VALIDITY.txt")).read().strip() if os.path.exists(os.path.join(d, "VALIDITY.txt")) else "no VALIDITY"
|
||||
if not ver.startswith("VALID"):
|
||||
print("%s %s (left out)" % (os.path.basename(d), ver))
|
||||
continue
|
||||
try:
|
||||
runs[(root, int(m.group(1)), int(m.group(2)), m.group(3))] = run_stats(d)
|
||||
except Exception as e: # noqa
|
||||
print("%s analysis failed: %s" % (os.path.basename(d), e))
|
||||
print("%-26s %-5s %-26s %8s %8s %8s %8s" % ("run", "pos", "turns tok/s", "tok/s", "tok/rnd", "ms/rnd", "rows/rnd"))
|
||||
for (root, b, p, arm), s in sorted(runs.items(), key=lambda kv: (kv[0][1], kv[0][2])):
|
||||
print("%-26s b%02dp%d %-26s %8.1f %8.3f %8.3f %8.3f" % (os.path.basename(root.rstrip("/")) + "/" + arm, b, p, " ".join("%.0f" % t for t in s["turns"]),
|
||||
s["tok_s"], s["tok_round"], s["ms_round"], s["rows_round"]))
|
||||
arms = {}
|
||||
for (root, b, p, arm), s in runs.items():
|
||||
arms.setdefault(arm, []).append(s)
|
||||
print()
|
||||
for arm, ss in sorted(arms.items()):
|
||||
print("arm %s n=%d tok/s %.2f (sd %.2f, %.1f..%.1f) tok/round %.3f (sd %.3f) ms/round %.3f (sd %.3f) rows/round %.3f accepted/round %.3f chain steps/round %.3f" % (
|
||||
arm, len(ss), statistics.mean(s["tok_s"] for s in ss), sd([s["tok_s"] for s in ss]), min(s["tok_s"] for s in ss), max(s["tok_s"] for s in ss),
|
||||
statistics.mean(s["tok_round"] for s in ss), sd([s["tok_round"] for s in ss]), statistics.mean(s["ms_round"] for s in ss), sd([s["ms_round"] for s in ss]),
|
||||
statistics.mean(s["rows_round"] for s in ss), statistics.mean(s["acc_round"] for s in ss), statistics.mean(s["steps_round"] for s in ss)))
|
||||
print("\nspans, ms per round (mean over the arm's runs):")
|
||||
print("%-26s" % "span", *["%10s" % a for a in sorted(arms)])
|
||||
for sp in SPANS:
|
||||
print("%-26s" % sp, *["%10.3f" % statistics.mean(s[sp] for s in ss) for a, ss in sorted(arms.items())])
|
||||
byb = {}
|
||||
for (root, b, p, arm), s in runs.items():
|
||||
byb.setdefault((root, b), {})[arm] = s
|
||||
for x, y in (("a", "b"), ("a", "c"), ("b", "c")):
|
||||
pairs = [(k, v[x], v[y]) for k, v in sorted(byb.items(), key=lambda kv: kv[0][1]) if x in v and y in v]
|
||||
if len(pairs) < 2:
|
||||
continue
|
||||
print("\nblock-paired, %s - %s (n=%d blocks: %s):" % (y, x, len(pairs), " ".join(str(k[1]) for k, _, _ in pairs)))
|
||||
for key, name in (("tok_s", "tok/s"), ("tok_round", "tok/round"), ("ms_round", "ms/round"), ("rows_round", "rows/round"), ("steps_round", "steps/round")):
|
||||
d = [pb[key] - pa[key] for _, pa, pb in pairs]
|
||||
rel = [100.0 * (pb[key] - pa[key]) / pa[key] for _, pa, pb in pairs]
|
||||
se = sd(d) / math.sqrt(len(d))
|
||||
print(" %-11s per block %s mean %+.3f (sd %.3f, se %.3f) %+.2f %% %s better in %d of %d" % (
|
||||
name, " ".join("%+.3f" % v for v in d), statistics.mean(d), sd(d), se, statistics.mean(rel), y, sum(1 for v in d if v > 0), len(d)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
# window-policy identity gate: teacher-forced replay of the 256k-class capture night5-long-256k (5 requests, recorded replies, decode capped at MAX_NEW forced tokens
|
||||
# each), production shape WITH THE ADAPTIVE WINDOW (the draft-round gate ran a fixed window, LELEKA_SPEC=4, whose widths cannot move), top-16 logprobs of every row, seed OFF,
|
||||
# ONE test binary (dt/$ID_BIN) for all processes, one process per setting, two arms in each (I1 I2: the A/A floor). HOLDER JOB (copy of draftround-id.sh).
|
||||
# The window policy picks the widths from measured times, so two runs cut their windows differently; q_pair keys a row by (request, position, the window's inputs up to the row),
|
||||
# i.e. it compares the rows whose context is the same whatever the window around them was, and the A/A floor (I2 against I1 of one process, adaptive on both) says how much of a
|
||||
# difference is the run-to-run width noise alone. What is compared: the top-16 logprob rows (ids and IEEE logprobs as printed) of the common rows, and the argmax of each.
|
||||
# ID_BIN test binary directory name under /data/leleka-e2e/decode/dt (required)
|
||||
# P1_ENV extra env of the reference process (default: nothing)
|
||||
# P2_ENV extra env of the changed process (required)
|
||||
# P3_ENV, P4_ENV optional third and fourth process
|
||||
# ID_OUT output directory (required) MAX_NEW (default 240) ADAPT (default 4: the adaptive tier swaps, as dt-id2)
|
||||
# SKIP_P1=1 reuse $ID_OUT/idP1.full of an earlier job (same binary, same environment) as the reference instead of running it again
|
||||
# ~10 GPU-min a process. Verdict: q_pair (top-16 logprob rows of the common rows: identical or not, read against the A/A floor) and q_tail_gate.
|
||||
set -uo pipefail
|
||||
LOCK=/data/leleka-e2e/gpu.lock
|
||||
D=/data/leleka-e2e/decode/dt
|
||||
DR=/data/leleka-e2e/draft-round
|
||||
WP=/data/leleka-e2e/window-policy
|
||||
O=${ID_OUT:?ID_OUT}
|
||||
ID_BIN=${ID_BIN:?ID_BIN}
|
||||
MAX_NEW=${MAX_NEW:-240}
|
||||
ADAPT=${ADAPT:-4}
|
||||
mkdir -p "$O"
|
||||
( cd / && sha256sum --quiet -c "$DR/MANIFEST.sha256" ) || { echo "draft-round: MANIFEST.sha256 check failed" >&2; exit 3; }
|
||||
export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
||||
A=$HOME/leleka-gates/assets
|
||||
G=$HOME/work/gpu-runs
|
||||
CAP=/data/leleka-e2e/sm120/capture
|
||||
export LELEKA_STRA169_KAR_PROVENANCE=$A/qwen-iq3-s-l2-v4.kar.provenance.json
|
||||
export LELEKA_STRA169_IQ3S_SHARD0=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf
|
||||
export LELEKA_STRA169_IQ3S_SHARD1=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf
|
||||
export LELEKA_STRA169_MTP_PACK=$A/data/mtp-rt LELEKA_STRA169_MTP_STAGING=$G/mtp-staging-own LELEKA_ORIGINAL_SERVE_BUDGET_GIB=30
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.45
|
||||
export LELEKA_SMOKE_PROMPT_CACHE=0 LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin
|
||||
export LELEKA_ORIGINAL_SERVE_RT_DIR=$A/data/mtp-rt
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=8000 LELEKA_CHAIN=all
|
||||
export LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=$ADAPT LELEKA_ORIGINAL_SERVE_SEED=off
|
||||
unset LELEKA_SPEC LELEKA_SPEC_ADAPTIVE LELEKA_SPEC_SUFFIX LELEKA_SPEC_POLICY
|
||||
unset LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_FOOTPRINT_LEGACY LELEKA_SM120_ATTN_DAILY_MTP LELEKA_DRAFT_FUSED_COMMIT LELEKA_DRAFT_ROUND
|
||||
for f in $D/$ID_BIN $D/tools/q_pair.py $D/tools/q_tail_gate.py $DR/tools/draftround-idcmp.py $CAP/night5-long-256k; do
|
||||
[ -e "$f" ] || { echo "missing $f" >&2; exit 3; }
|
||||
done
|
||||
sha256sum $D/$ID_BIN | tee $O/rt.sha256
|
||||
shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan"
|
||||
run() { # label extra-env
|
||||
got=0
|
||||
for i in $(seq 1 1080); do
|
||||
if mkdir $LOCK 2>/dev/null; then echo "window-policy identity $1 $(date -u +%FT%TZ)" >$LOCK/owner; got=1; break; fi
|
||||
sleep 5
|
||||
done
|
||||
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; return 3; }
|
||||
avail=$(awk '/MemAvailable/{print int($2/1048576)}' /proc/meminfo); echo "=== $1 extra=[$2] MemAvailable GiB: $avail"
|
||||
if [ "$avail" -lt 60 ]; then echo "abort: less than 60 GiB available"; rm -f $LOCK/owner; rmdir $LOCK; return 4; fi
|
||||
date -u +%FT%TZ
|
||||
env $2 LELEKA_SPEC_STATS=1 LELEKA_SPEC_TRACE=1 LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_BRINGUP_TRACE=1 LELEKA_REPLAY_DIR=$CAP/night5-long-256k LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 LELEKA_TRACE_PREFILL_R=1 LELEKA_TRACE_LOGPROBS=16 \
|
||||
LELEKA_REPLAY_MAX_NEW=$MAX_NEW LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS="I1=$shape,I2=$shape" \
|
||||
nice -n 5 $D/$ID_BIN --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke > $O/$1.full 2>&1
|
||||
echo "rc=$? label=$1"; date -u +%FT%TZ
|
||||
grep -a -E "^REPLAY #|test result|panicked|FAILED|expert cache [0-9]+ slots" $O/$1.full | cut -c1-200 | tail -14
|
||||
grep -a -c "^DBG spec-trace" $O/$1.full
|
||||
rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null
|
||||
sleep 15
|
||||
}
|
||||
if [ "${SKIP_P1:-0}" = 1 ]; then [ -s "$O/idP1.full" ] || { echo "SKIP_P1 set but $O/idP1.full is missing" >&2; exit 3; }; else run idP1 "${P1_ENV:-LELEKA_X=1}"; fi
|
||||
run idP2 "${P2_ENV:?P2_ENV}"
|
||||
PROCS="idP1 idP2"
|
||||
if [ -n "${P3_ENV:-}" ]; then run idP3 "$P3_ENV"; PROCS="idP1 idP2 idP3"; fi
|
||||
if [ -n "${P4_ENV:-}" ]; then run idP4 "$P4_ENV"; PROCS="$PROCS idP4"; fi
|
||||
T=$D/tools
|
||||
for p in $PROCS; do echo "== q_tail_gate $p"; python3 $T/q_tail_gate.py $O/$p.full $CAP/night5-long-256k 2>&1 | tail -8; done
|
||||
python3 - <<PY
|
||||
import sys
|
||||
sys.path.insert(0, "$T")
|
||||
import q_pair
|
||||
procs = "$PROCS".split()
|
||||
rows = {p: [q_pair.rows_of("$O/%s.full" % p, i) for i in (0, 1)] for p in procs}
|
||||
q_pair.compare(rows["idP1"][0], rows["idP1"][1], "reference process, arm I2 against arm I1 (A/A noise floor)")
|
||||
for p in procs[1:]:
|
||||
q_pair.compare(rows[p][0], rows[p][1], p + ", arm I2 against arm I1 (A/A)")
|
||||
q_pair.compare(rows["idP1"][0], rows[p][0], p + " against the reference, arm I1")
|
||||
q_pair.compare(rows["idP1"][1], rows[p][1], p + " against the reference, arm I2")
|
||||
PY
|
||||
# (the draft trace of draft-round is not compared here: a policy with another chain floor drafts other tokens by design)
|
||||
sha256sum $O/*.full
|
||||
date -u +%FT%TZ
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install the window-policy A/B inputs on rnr5090 (run on the server from the directory that holds the scripts):
|
||||
# bash windowpolicy-install.sh <repo scripts/e2e dir> [bin dir under dt/ ...]
|
||||
# Copies the A/B tools to /data/leleka-e2e/window-policy/tools and the repository's scripts/e2e (run-e2e.sh and its client files) to /data/leleka-e2e/window-policy/scripts/e2e
|
||||
# (read-only afterwards) and writes MANIFEST.sha256 with the digest of every input a run depends on: the tools, the e2e scripts, the draft-round harness helper,
|
||||
# the binaries named on the command line, the long-session client, the upstream profile and the corpus manifest. windowpolicy-ab.sh refuses to start on a mismatch.
|
||||
set -euo pipefail
|
||||
WP=/data/leleka-e2e/window-policy
|
||||
DRT=/data/leleka-e2e/draft-round/tools
|
||||
D=/data/leleka-e2e/decode/dt
|
||||
SRC=$(cd "$(dirname "$0")" && pwd)
|
||||
E2E=$(cd "${1:?usage: windowpolicy-install.sh <scripts/e2e dir> [bin ...]}" && pwd)
|
||||
shift
|
||||
chmod -R u+w "$WP/tools" "$WP/scripts" 2>/dev/null || true
|
||||
mkdir -p "$WP/tools"
|
||||
for f in windowpolicy-ab.sh windowpolicy-analyze.py windowpolicy-replay.sh windowpolicy-replay-summary.py windowpolicy-id.sh windowpolicy-install.sh; do
|
||||
if [ -e "$SRC/$f" ]; then install -m 0555 "$SRC/$f" "$WP/tools/$f"; fi
|
||||
done
|
||||
rm -rf "$WP/scripts"
|
||||
mkdir -p "$WP/scripts/e2e"
|
||||
for f in "$E2E"/*.sh "$E2E"/*.py; do
|
||||
if [ -f "$f" ]; then install -m 0555 "$f" "$WP/scripts/e2e/$(basename "$f")"; fi
|
||||
done
|
||||
chmod a-w "$WP/tools" "$WP/scripts/e2e" "$WP/scripts"
|
||||
{
|
||||
sha256sum "$WP"/tools/* "$WP"/scripts/e2e/* "$DRT"/ts-wrap.sh
|
||||
for b in "$@"; do
|
||||
for x in leleka-inference leleka-daemon leleka-cli strata-next; do
|
||||
sha256sum "$D/$b/$x"
|
||||
done
|
||||
done
|
||||
sha256sum "$D/tools/long-session.py" /data/leleka-e2e/decode/assets/expert-profile-upstream.bin /data/leleka-e2e/decode/corpus/MANIFEST.txt
|
||||
} >"$WP/MANIFEST.sha256.new"
|
||||
mv "$WP/MANIFEST.sha256.new" "$WP/MANIFEST.sha256"
|
||||
echo "installed; $(wc -l <"$WP/MANIFEST.sha256") inputs in $WP/MANIFEST.sha256"
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Per-arm summary of windowpolicy-replay.sh: REPLAY PASS lines (warm-up pass discarded), tokens / decode time / rounds summed over the passes of an arm,
|
||||
the per-pass tok/s, and the paired difference to the first arm of every repetition. usage: windowpolicy-replay-summary.py <replay.full>"""
|
||||
import re, statistics as st, sys
|
||||
|
||||
# the REPLAY PASS line rounds the decode time to 0.1 s (1.2 % of a pass): the per-request lines carry decode_ms to 0.1 ms, so the passes are rebuilt from them
|
||||
reqs = {}
|
||||
labels = {}
|
||||
for ln in open(sys.argv[1], errors="replace"):
|
||||
m = re.match(r"REPLAY #(\d+) pass=(\d+) (\S+) arm=(\S+) .*? produced=(\d+) rounds=(\d+) tok_per_round=\S+ decode_ms=([\d.]+)", ln)
|
||||
if m:
|
||||
n, ps, lab, arm, produced, rounds, ms = m.groups()
|
||||
r = reqs.setdefault(int(ps), dict(lab=lab, arm=arm, tok=0, sec=0.0, rounds=0))
|
||||
r["tok"] += int(produced)
|
||||
r["sec"] += float(ms) / 1000.0
|
||||
r["rounds"] += int(rounds)
|
||||
passes = []
|
||||
for ps, r in sorted(reqs.items()):
|
||||
passes.append(dict(n=ps, lab=r["lab"], arm=r["arm"], tps=r["tok"] / r["sec"], tok=r["tok"], sec=r["sec"], rounds=r["rounds"]))
|
||||
rows = [p for p in passes if p["lab"] != "warm"]
|
||||
arms = []
|
||||
for p in rows:
|
||||
if p["arm"] not in arms:
|
||||
arms.append(p["arm"])
|
||||
print("passes %d (+%d warm-up), arms %d" % (len(rows), len(passes) - len(rows), len(arms)))
|
||||
print("%-34s %3s %9s %8s %9s %9s per-pass tok/s" % ("arm", "n", "tok/s", "sd", "tok/round", "ms/round"))
|
||||
by = {}
|
||||
for a in arms:
|
||||
v = [p for p in rows if p["arm"] == a]
|
||||
by[a] = v
|
||||
tps = [p["tps"] for p in v]
|
||||
tok, sec, rd = sum(p["tok"] for p in v), sum(p["sec"] for p in v), sum(p["rounds"] for p in v)
|
||||
print("%-34s %3d %9.2f %8.2f %9.3f %9.3f %s" % (a, len(v), tok / sec, st.pstdev(tps) if len(tps) > 1 else 0.0, tok / rd, 1000 * sec / rd, " ".join("%.1f" % x for x in tps)))
|
||||
ref = arms[0]
|
||||
print("\npaired against %s (same repetition, same forced text): mean difference tok/s (se), arms better in n of N" % ref)
|
||||
reps = sorted({p["lab"] for p in rows})
|
||||
for a in arms[1:]:
|
||||
d = []
|
||||
for r in reps:
|
||||
x = [p for p in by[a] if p["lab"] == r]
|
||||
y = [p for p in by[ref] if p["lab"] == r]
|
||||
if x and y:
|
||||
d.append(x[0]["tps"] - y[0]["tps"])
|
||||
if len(d) > 1:
|
||||
print("%-34s %+7.2f (se %.2f) %d of %d [%s]" % (a, st.mean(d), st.stdev(d) / len(d) ** 0.5, sum(1 for z in d if z > 0), len(d), " ".join("%+.1f" % z for z in d)))
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
# window-policy screening: teacher-forced replay of the 256k-class capture night5-long-256k (5 requests, prompts 46k .. 243k tokens, the recorded reply decoded
|
||||
# exactly, MAX_NEW forced tokens each), PRODUCTION decode shape (auto expert slots, seed off, adaptive tier swaps every 4 rounds, chain kernels, upstream ranked profile,
|
||||
# prefix cache reply@8192, PCIe share 0.45), several window policies in ONE process on the SAME forced text (LELEKA_SPEC_ARMS), so the arms differ only in how they
|
||||
# speculate: tokens per round, ms per round and decode tok/s of every arm come from identical work, rotated over the repetitions. HOLDER JOB (rnr5090).
|
||||
# RT_BIN test binary directory name under /data/leleka-e2e/decode/dt (required, e.g. rt-wp1)
|
||||
# ARMS LELEKA_SPEC_ARMS list (required): fixed4@0.5,adaptive@0,adaptive@0.7,adaptive@0~step=0.3 ... ; arm 0 is also the warm-up pass (discarded)
|
||||
# REPS repetitions of the arm list (default 4) MAX_NEW forced tokens per request (default 240)
|
||||
# CAPDIR capture directory (default the night5-long-256k capture; /data/leleka-e2e/window-policy/capture/corpus245 = the 245k corpus session of the e2e A/B)
|
||||
# OUT output directory (required) ENVX extra KEY=VALUE words for the process (e.g. LELEKA_SM120_ATTN_DAILY_MTP=1)
|
||||
# One model load; a pass is ~1 min with the prefix cache warm. Summary: windowpolicy-replay-summary.py.
|
||||
set -uo pipefail
|
||||
LOCK=/data/leleka-e2e/gpu.lock
|
||||
D=/data/leleka-e2e/decode/dt
|
||||
RT=${RT_BIN:?RT_BIN}; ARMS=${ARMS:?ARMS}; O=${OUT:?OUT}; REPS=${REPS:-4}; MAX_NEW=${MAX_NEW:-240}
|
||||
mkdir -p "$O"
|
||||
export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
||||
A=$HOME/leleka-gates/assets
|
||||
G=$HOME/work/gpu-runs
|
||||
CAP=/data/leleka-e2e/sm120/capture
|
||||
export LELEKA_STRA169_KAR_PROVENANCE=$A/qwen-iq3-s-l2-v4.kar.provenance.json
|
||||
export LELEKA_STRA169_IQ3S_SHARD0=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf
|
||||
export LELEKA_STRA169_IQ3S_SHARD1=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf
|
||||
export LELEKA_STRA169_MTP_PACK=$A/data/mtp-rt LELEKA_STRA169_MTP_STAGING=$G/mtp-staging-own LELEKA_ORIGINAL_SERVE_BUDGET_GIB=30
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.45
|
||||
export LELEKA_SMOKE_PROMPT_CACHE=0 LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin
|
||||
export LELEKA_ORIGINAL_SERVE_RT_DIR=$A/data/mtp-rt
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto LELEKA_CHAIN=all LELEKA_ORIGINAL_SERVE_SEED=off
|
||||
unset LELEKA_SPEC LELEKA_SPEC_ADAPTIVE LELEKA_SPEC_SUFFIX LELEKA_ORIGINAL_SERVE_ADAPT_EVERY LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_FOOTPRINT_LEGACY LELEKA_SM120_ATTN_DAILY_MTP LELEKA_DRAFT_FUSED_COMMIT LELEKA_DRAFT_ROUND
|
||||
CAPDIR=${CAPDIR:-$CAP/night5-long-256k}
|
||||
for f in "$D/$RT" "$CAPDIR" "$LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE"; do [ -e "$f" ] || { echo "missing $f" >&2; exit 3; }; done
|
||||
sha256sum "$D/$RT" "$LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE" | tee "$O/inputs.sha256"
|
||||
echo "arms=$ARMS reps=$REPS max_new=$MAX_NEW capdir=$CAPDIR envx=[${ENVX:-}]" | tee "$O/args.txt"
|
||||
CAPDIR=${CAPDIR:-$CAP/night5-long-256k}
|
||||
shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan"
|
||||
got=0
|
||||
for i in $(seq 1 1080); do
|
||||
if mkdir $LOCK 2>/dev/null; then echo "window-policy replay $(date -u +%FT%TZ)" >$LOCK/owner; got=1; break; fi
|
||||
sleep 5
|
||||
done
|
||||
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; exit 3; }
|
||||
avail=$(awk '/MemAvailable/{print int($2/1048576)}' /proc/meminfo); echo "MemAvailable GiB: $avail"
|
||||
if [ "$avail" -lt 60 ]; then echo "abort: less than 60 GiB available"; rm -f $LOCK/owner; rmdir $LOCK; exit 4; fi
|
||||
date -u +%FT%TZ
|
||||
env ${ENVX:-LELEKA_X=1} LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_BRINGUP_TRACE=1 LELEKA_REPLAY_DIR=$CAPDIR LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 \
|
||||
LELEKA_REPLAY_MAX_NEW=$MAX_NEW LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS="W=$shape" LELEKA_REPLAY_REPS=$REPS LELEKA_REPLAY_SPEC_MIN_P=0 \
|
||||
LELEKA_SPEC_ARMS="$ARMS" LELEKA_SPEC_STATS=1 LELEKA_SPEC_TRACE=1 \
|
||||
"$D/$RT" --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke >"$O/replay.full" 2>&1
|
||||
echo "rc=$?"; date -u +%FT%TZ
|
||||
grep -a -E "^REPLAY PASS|test result|panicked|FAILED|expert cache [0-9]+ slots" "$O/replay.full" | cut -c1-240 | tail -40
|
||||
rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null
|
||||
python3 -I "$(dirname "$0")/windowpolicy-replay-summary.py" "$O/replay.full" | tee "$O/SUMMARY.txt"
|
||||
@@ -80,6 +80,9 @@ chmod 600 "$KEYFILE"
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=${LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS:-2048}
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=${LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER:-yes}
|
||||
export LELEKA_ORIGINAL_SERVE_PCIE_FRAC=${LELEKA_ORIGINAL_SERVE_PCIE_FRAC:-0.45}
|
||||
# MTP draft attention = upstream pre75 chunk + merge v2 (bitwise identical to the Original, docs/experiments/draft-round-5090.md): on in the rtx5090-32g profile's
|
||||
# engine_env, so on in the harness too (set LELEKA_SM120_ATTN_DAILY_MTP=0 for the old kernels; only the value 1 enables it).
|
||||
export LELEKA_SM120_ATTN_DAILY_MTP=${LELEKA_SM120_ATTN_DAILY_MTP:-1}
|
||||
# The ranked upstream profile (data/expert-profile.bin, the file crates/deploy pins as EXPERT_PROFILE_SHA256 and vanilla Strata runs) is the default.
|
||||
# The old default, $G/baseline/profile.bin, is a PLACEHOLDER in expert-id order (47 % overlap with the ranked set at 11,280 slots): every e2e run
|
||||
# that used it started from an unranked VRAM set, which showed up as a burst of CPU/PCIe experts in the first 20 windows of each request and an
|
||||
|
||||
Reference in New Issue
Block a user