window-policy: draft-floor ceiling default 0.60 (was 0.9), LELEKA_SPEC_POLICY=legacy restores it; spec-trace prints the bar and the row slope
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
dcf6e8bf5a
commit
e57562740e
@@ -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;
|
||||
@@ -81,7 +89,7 @@ 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,
|
||||
@@ -91,11 +99,14 @@ impl AdaptiveConfig {
|
||||
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; }
|
||||
@@ -105,6 +116,13 @@ 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.
|
||||
@@ -118,6 +136,7 @@ impl AdaptiveConfig {
|
||||
"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,
|
||||
@@ -507,11 +526,8 @@ impl AdaptivePolicy {
|
||||
|
||||
// ---- next draft chain -------------------------------------------------------------------------------------
|
||||
|
||||
/// 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));
|
||||
/// 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 {
|
||||
@@ -519,7 +535,15 @@ impl AdaptivePolicy {
|
||||
} else {
|
||||
0.04
|
||||
};
|
||||
let a_req = (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);
|
||||
(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 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;
|
||||
if self.cfg.smooth_floor {
|
||||
@@ -916,6 +940,41 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
_=>{
|
||||
|
||||
@@ -59,7 +59,7 @@ sampled target token; the policy only chooses how many rows to offer).
|
||||
| `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_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
|
||||
|
||||
@@ -47,7 +47,8 @@ settle() { # $1 run dir
|
||||
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; } >>"$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
|
||||
@@ -153,6 +154,7 @@ for ent in $LIST; do
|
||||
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
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
# 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
|
||||
@@ -27,9 +28,11 @@ export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=/data/leleka-e2e/decode/assets/exper
|
||||
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
|
||||
for f in "$D/$RT" "$CAP/night5-long-256k" "$LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE"; do [ -e "$f" ] || { echo "missing $f" >&2; exit 3; }; done
|
||||
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 envx=[${ENVX:-}]" | tee "$O/args.txt"
|
||||
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
|
||||
@@ -40,10 +43,10 @@ done
|
||||
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=$CAP/night5-long-256k LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 \
|
||||
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 \
|
||||
nice -n 5 "$D/$RT" --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke >"$O/replay.full" 2>&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
|
||||
|
||||
Reference in New Issue
Block a user