NaN guard with self-healing for verify windows (plan 1.2; upstream f332a855, 894f133b)
A verify window whose logits or stage outputs are not finite (NonFinite, e.g. the laptop's NonFiniteMmqOutput, STRA-235) used to end the request after the controller restored its checkpoints. With LELEKA_ORIGINAL_SERVE_NAN_GUARD=on the same restore is followed by running the round again (up to 2 times by default); any other error, a failed restore, or a window that stays non-finite fails as before. Every healed or unhealed window is logged, counted in the spec stats and published in the telemetry document. LELEKA_ORIGINAL_SERVE_NAN_INJECT=n[xK] exercises the path on a good window. Default off until the live replay (queued) shows no change of normal output. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
4654f01b15
commit
5dc20b66a6
@@ -78,6 +78,10 @@ struct State {
|
||||
decode_ema: Option<f64>,
|
||||
context_live: u64,
|
||||
context_max: u64,
|
||||
/// Non-finite verify windows (upstream's NaN guard): retried from the round's checkpoint and then fine, or given up on.
|
||||
nan_healed: u64,
|
||||
nan_unhealed: u64,
|
||||
nan_last: Option<String>,
|
||||
}
|
||||
|
||||
static STATE: Mutex<Option<State>> = Mutex::new(None);
|
||||
@@ -131,6 +135,23 @@ pub fn tokens_delivered(count: u64) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The NaN guard retried a window whose logits or stage outputs were not finite from the round's checkpoint, and the retry was good.
|
||||
/// `what` names it for the operator (position, rows, attempt, the error class); the last one is kept in the document.
|
||||
pub fn nan_guard_healed(what: &str) {
|
||||
with_state(|s| {
|
||||
s.nan_healed += 1;
|
||||
s.nan_last = Some(format!("healed: {what}"));
|
||||
});
|
||||
}
|
||||
|
||||
/// The NaN guard gave up on a non-finite window (no retry left, or the checkpoint could not be restored): the request fails as before.
|
||||
pub fn nan_guard_unhealed(what: &str) {
|
||||
with_state(|s| {
|
||||
s.nan_unhealed += 1;
|
||||
s.nan_last = Some(format!("unhealed: {what}"));
|
||||
});
|
||||
}
|
||||
|
||||
/// A request ended without numbers worth folding in (cancelled or failed): the engine is idle again.
|
||||
pub fn request_aborted() {
|
||||
with_state(|s| {
|
||||
@@ -274,6 +295,13 @@ struct Cache {
|
||||
last_reused_tokens: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct NanGuard {
|
||||
healed_windows: u64,
|
||||
unhealed_windows: u64,
|
||||
last: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Context {
|
||||
live_tokens: u64,
|
||||
@@ -302,6 +330,7 @@ struct Document {
|
||||
throughput: Rates,
|
||||
cache: Cache,
|
||||
context: Context,
|
||||
nan_guard: NanGuard,
|
||||
settings: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
@@ -381,6 +410,7 @@ fn render(state: &State, measured: &Measured) -> String {
|
||||
max_tokens: state.context_max,
|
||||
used_pct: ratio(state.context_live, state.context_max).map(|r| (r * 1e4).round() / 1e2),
|
||||
},
|
||||
nan_guard: NanGuard { healed_windows: state.nan_healed, unhealed_windows: state.nan_unhealed, last: state.nan_last.clone() },
|
||||
settings: lock(&SETTINGS).clone(),
|
||||
};
|
||||
serde_json::to_string(&document).unwrap_or_default()
|
||||
@@ -485,6 +515,22 @@ mod tests {
|
||||
assert!((process - 7.4).abs() < 1e-9 && (system - 15.0).abs() < 1e-9, "{process} {system}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_nan_guard_reports_each_healed_and_unhealed_window() {
|
||||
let _serial = lock(&SERIAL);
|
||||
*lock(&STATE) = None;
|
||||
let doc: serde_json::Value = serde_json::from_str(&render_now(&measured())).unwrap();
|
||||
assert_eq!((doc["nan_guard"]["healed_windows"].as_u64(), doc["nan_guard"]["unhealed_windows"].as_u64()), (Some(0), Some(0)));
|
||||
assert!(doc["nan_guard"]["last"].is_null());
|
||||
nan_guard_healed("position 4096, 4 rows, retry 1 of 2: NonFinite");
|
||||
nan_guard_healed("position 4100, 2 rows, retry 1 of 2: NonFinite");
|
||||
nan_guard_unhealed("position 8000, 4 rows, retry 2 of 2: NonFinite");
|
||||
let doc: serde_json::Value = serde_json::from_str(&render_now(&measured())).unwrap();
|
||||
assert_eq!((doc["nan_guard"]["healed_windows"].as_u64(), doc["nan_guard"]["unhealed_windows"].as_u64()), (Some(2), Some(1)));
|
||||
assert_eq!(doc["nan_guard"]["last"], "unhealed: position 8000, 4 rows, retry 2 of 2: NonFinite");
|
||||
*lock(&STATE) = None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requests_fold_into_rates_cache_and_context() {
|
||||
let _serial = lock(&SERIAL);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! `OriginalMtpDrafter::draft_from_verifier` owners. No default port exists:
|
||||
//! a missing owner is `Error::Unsupported`, never a synthesized result.
|
||||
use super::contract::{Error,Result};
|
||||
use super::original_spec_controller::{OriginalSpecController,OriginalSpecEngine,SpecConfig,SpecError};
|
||||
use super::original_spec_controller::{NanGuard,OriginalSpecController,OriginalSpecEngine,SpecConfig,SpecError};
|
||||
use super::original_spec_draft::{DraftPick,OriginalDraftEngine,OriginalFirstDraftEngine};
|
||||
use super::original_spec_adaptive::AdaptiveConfig;
|
||||
use super::original_spec_policy::MAX_T;
|
||||
@@ -352,13 +352,15 @@ pub(crate) struct OriginalServeSettings {
|
||||
pub(crate) suffix_min_match:usize,pub(crate) coupled:bool,
|
||||
/// `LELEKA_SPEC_ADAPTIVE`: the adaptive window policy (`original_spec_adaptive.rs`).
|
||||
pub(crate) adaptive:Option<AdaptiveConfig>,
|
||||
/// Re-run a verify window with non-finite output from its round's checkpoint (`NanGuard`); off in mode17 itself.
|
||||
pub(crate) nan_guard:NanGuard,
|
||||
/// An arm's own `spec_min_p` for the requests it serves (`fixed4@0`), overriding the harness default; `None` = the harness's.
|
||||
pub(crate) request_min_p:Option<f32>,
|
||||
}
|
||||
impl OriginalServeSettings {
|
||||
pub(crate) fn mode17(max_context:i64,vocabulary:u32,coupled:bool)->Self {
|
||||
const SPEC:usize=4;const SUFFIX:usize=3;
|
||||
Self{max_t:(SPEC+2).min(MAX_T),mtp_max_t:SPEC,max_context,vocabulary,suffix_min_match:SUFFIX,coupled,adaptive:None,request_min_p:None}
|
||||
Self{max_t:(SPEC+2).min(MAX_T),mtp_max_t:SPEC,max_context,vocabulary,suffix_min_match:SUFFIX,coupled,adaptive:None,nan_guard:NanGuard::off(),request_min_p:None}
|
||||
}
|
||||
/// Mode17 with the operator's overrides from the environment (read once per stack):
|
||||
/// `LELEKA_SPEC` (the Original's `--spec`: MTP window, verify windows up to `spec + 2`, at most 8),
|
||||
@@ -368,6 +370,7 @@ impl OriginalServeSettings {
|
||||
pub(crate) fn from_environment(max_context:i64,vocabulary:u32,coupled:bool)->Self {
|
||||
let num=|name:&str|std::env::var(name).ok().and_then(|v|v.trim().parse::<usize>().ok());
|
||||
let mut s=Self::mode17(max_context,vocabulary,coupled);
|
||||
s.nan_guard=NanGuard::from_environment();
|
||||
if let Some(spec)=num("LELEKA_SPEC") {
|
||||
let spec=spec.clamp(2,MAX_T);s.max_t=(spec+2).min(MAX_T);s.mtp_max_t=spec;
|
||||
}
|
||||
@@ -428,7 +431,7 @@ impl OriginalServeSettings {
|
||||
/// The one production call of `OriginalSpecController::new`.
|
||||
pub(crate) fn controller(&self)->Result<OriginalSpecController> {
|
||||
OriginalSpecController::new(SpecConfig::new(self.max_t,self.mtp_max_t,self.max_context,self.vocabulary,
|
||||
self.suffix_min_match,self.coupled)?.with_adaptive(self.adaptive))
|
||||
self.suffix_min_match,self.coupled)?.with_adaptive(self.adaptive).with_nan_guard(self.nan_guard))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +531,7 @@ impl<P: OriginalServePort> OriginalServePort for TracePort<P> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::super::original_spec_controller::{OriginalSpecController,SpecConfig,SpecError};
|
||||
use super::super::original_spec_controller::{NanGuard,OriginalSpecController,SpecConfig,SpecError};
|
||||
use super::super::original_spec_draft::DraftPreparation;
|
||||
use std::cell::RefCell;
|
||||
|
||||
@@ -1063,7 +1066,7 @@ mod tests {
|
||||
fn serve_in(p:&[i32],max_new:usize,eos:&[i32],mut cancel:impl FnMut()->bool,fail_emit_after:Option<usize>,max_context:i64)
|
||||
->(std::result::Result<ServeOutcome,SpecError>,Vec<i32>,OriginalSpecController,OriginalServeEngine<Fake>,Rc<RefCell<World>>) {
|
||||
let (f,w)=Fake::new(p);
|
||||
let s=OriginalServeSettings{max_t:4,mtp_max_t:0,max_context,vocabulary:VOCAB,suffix_min_match:0,coupled:false,adaptive:None,request_min_p:None};
|
||||
let s=OriginalServeSettings{max_t:4,mtp_max_t:0,max_context,vocabulary:VOCAB,suffix_min_match:0,coupled:false,adaptive:None,nan_guard:NanGuard::off(),request_min_p:None};
|
||||
let mut e=OriginalServeEngine::new(f,VOCAB,s.max_t,s.max_t-1).unwrap();
|
||||
let mut c=s.controller().unwrap();
|
||||
let mut out=Vec::new();
|
||||
|
||||
@@ -501,6 +501,8 @@ pub(crate) struct SpecStats {
|
||||
pub(crate) offered: u64,
|
||||
pub(crate) accepted: u64,
|
||||
pub(crate) total_ms: f64,
|
||||
/// Windows the NaN guard ran again from their checkpoint and that then passed.
|
||||
pub(crate) healed: u64,
|
||||
}
|
||||
impl SpecStats {
|
||||
pub(crate) fn record(&mut self, t: usize, accepted: usize, lookup: bool, explored: bool, ms: f64) {
|
||||
@@ -521,10 +523,10 @@ impl SpecStats {
|
||||
.map(|t| if self.by_t[t] > 0 { format!("{:.1}", self.ms_by_t[t] / self.by_t[t] as f64) } else { "-".into() })
|
||||
.collect();
|
||||
format!(
|
||||
"rounds={} tokens={} tok_per_round={:.3} lookup_rounds={} explored={} accepted={}/{} round_ms={:.2} T_hist[0..={}]={} acc_hist={} ms_by_T={}",
|
||||
"rounds={} tokens={} tok_per_round={:.3} lookup_rounds={} explored={} accepted={}/{} round_ms={:.2} T_hist[0..={}]={} acc_hist={} ms_by_T={} healed={}",
|
||||
self.rounds, self.tokens,
|
||||
self.tokens as f64 / self.rounds.max(1) as f64, self.lookup_rounds, self.explored, self.accepted, self.offered,
|
||||
self.total_ms / self.rounds.max(1) as f64, MAX_T, hist(&self.by_t), hist(&self.acc_hist), mean_ms.join(",")
|
||||
self.total_ms / self.rounds.max(1) as f64, MAX_T, hist(&self.by_t), hist(&self.acc_hist), mean_ms.join(","), self.healed
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,19 +56,67 @@ pub(crate) trait OriginalSpecEngine:OriginalDraftEngine<Self::Verified> {
|
||||
fn wait_commit(&mut self)->Result<()>;
|
||||
}
|
||||
|
||||
/// Upstream's NaN guard with self-healing (`STRATA_NAN_GUARD`, f332a855 / 894f133b): how many times a verify window whose logits or stage
|
||||
/// outputs are not finite (`Error::NonFinite`) is run again from its round's checkpoint before the request fails. Upstream ends the request
|
||||
/// and lets its gateway send it again from token 0; here the window itself is repeated, which costs one window and keeps the request.
|
||||
/// `LELEKA_ORIGINAL_SERVE_NAN_GUARD=on|off` (a profile `engine_env` key), `..._NAN_GUARD_RETRIES=N` (default 2),
|
||||
/// `..._NAN_INJECT=n[xK]` (debug: the n-th checked window reads as non-finite K times, default 1, to exercise the path).
|
||||
#[derive(Clone,Copy,Debug,Eq,PartialEq)]
|
||||
pub(crate) struct NanGuard {pub(crate) retries:u32,inject_at:u64,inject_times:u32}
|
||||
impl NanGuard {
|
||||
/// Whether an unset switch means on. Off until the replay with the guard on showed no change of normal output.
|
||||
pub(crate) const DEFAULT_ON:bool=false;
|
||||
pub(crate) const DEFAULT_RETRIES:u32=2;
|
||||
pub(crate) const fn off()->Self {Self{retries:0,inject_at:0,inject_times:0}}
|
||||
pub(crate) const fn with_retries(retries:u32)->Self {Self{retries,inject_at:0,inject_times:0}}
|
||||
/// The injection (tests and the live proof): the `at`-th checked window fails `times` times in a row.
|
||||
pub(crate) const fn with_injection(mut self,at:u64,times:u32)->Self {self.inject_at=at;self.inject_times=times;self}
|
||||
/// From the three values; a malformed one is refused with its name (a guard that silently differs from what the operator wrote is worse than none).
|
||||
pub(crate) fn parse(switch:Option<&str>,retries:Option<&str>,inject:Option<&str>)->std::result::Result<Self,String> {
|
||||
let on=match switch.map(|v|v.trim().to_ascii_lowercase()).as_deref() {
|
||||
None|Some("")=>Self::DEFAULT_ON,
|
||||
Some("on"|"1"|"yes"|"true")=>true,
|
||||
Some("off"|"0"|"no"|"false")=>false,
|
||||
Some(other)=>return Err(format!("LELEKA_ORIGINAL_SERVE_NAN_GUARD={other}: expected on or off")),
|
||||
};
|
||||
let retries=match retries.map(str::trim).filter(|v|!v.is_empty()) {
|
||||
None=>Self::DEFAULT_RETRIES,
|
||||
Some(v)=>v.parse::<u32>().ok().filter(|&n|n<=8).ok_or_else(||format!("LELEKA_ORIGINAL_SERVE_NAN_GUARD_RETRIES={v}: expected 0..=8"))?,
|
||||
};
|
||||
let mut guard=if on {Self::with_retries(retries)} else {Self::off()};
|
||||
if let Some(v)=inject.map(str::trim).filter(|v|!v.is_empty()) {
|
||||
let (at,times)=match v.split_once('x') {Some((a,k))=>(a,k),None=>(v,"1")};
|
||||
let bad=||format!("LELEKA_ORIGINAL_SERVE_NAN_INJECT={v}: expected n or nxK");
|
||||
let (at,times)=(at.parse::<u64>().ok().filter(|&n|n>0).ok_or_else(bad)?,times.parse::<u32>().ok().filter(|&n|n>0).ok_or_else(bad)?);
|
||||
guard=guard.with_injection(at,times);
|
||||
}
|
||||
Ok(guard)
|
||||
}
|
||||
/// Read once per stack from the process environment; a malformed value is reported and the guard stays at its default.
|
||||
pub(crate) fn from_environment()->Self {
|
||||
let get=|k:&str|std::env::var(k).ok();
|
||||
Self::parse(get("LELEKA_ORIGINAL_SERVE_NAN_GUARD").as_deref(),get("LELEKA_ORIGINAL_SERVE_NAN_GUARD_RETRIES").as_deref(),get("LELEKA_ORIGINAL_SERVE_NAN_INJECT").as_deref())
|
||||
.unwrap_or_else(|why|{eprintln!("leleka-serve nan-guard: {why}; the guard keeps its default");if Self::DEFAULT_ON {Self::with_retries(Self::DEFAULT_RETRIES)} else {Self::off()}})
|
||||
}
|
||||
/// The injected failure applies to window number `window` (1-based, per controller) on attempt `attempt` (0-based).
|
||||
fn injects(&self,window:u64,attempt:u32)->bool {self.retries>0&&self.inject_at==window&&attempt<self.inject_times}
|
||||
}
|
||||
pub(crate) struct SpecConfig {
|
||||
max_t:usize,mtp_t:usize,max_context:i64,vocabulary:u32,
|
||||
suffix_min_match:usize,coupled:bool,
|
||||
/// `LELEKA_SPEC_ADAPTIVE`: the adaptive window policy replaces the fixed `mtp_t` / min_p / DraftPolicy choice.
|
||||
adaptive:Option<AdaptiveConfig>,
|
||||
/// See [`NanGuard`]; off unless the caller asks (the controller's own tests rely on the first failure aborting).
|
||||
nan_guard:NanGuard,
|
||||
}
|
||||
impl SpecConfig {
|
||||
pub(crate) fn new(max_t:usize,mtp_max_t:usize,max_context:i64,vocabulary:u32,suffix_min_match:usize,coupled:bool)->Result<Self> {
|
||||
if !(1..=MAX_T).contains(&max_t)||max_context<1||max_context>crate::qwen_forward::contract::serving_cells() as i64||vocabulary==0||vocabulary>262144 {return Err(Error::InvalidDimension);}
|
||||
// Original --mtp-max-t<=0 means S; public usize zero carries that case.
|
||||
let mtp_t=if mtp_max_t==0 {max_t} else {mtp_max_t.min(max_t)};
|
||||
Ok(Self{max_t,mtp_t,max_context,vocabulary,suffix_min_match,coupled,adaptive:None})
|
||||
Ok(Self{max_t,mtp_t,max_context,vocabulary,suffix_min_match,coupled,adaptive:None,nan_guard:NanGuard::off()})
|
||||
}
|
||||
pub(crate) fn with_nan_guard(mut self,guard:NanGuard)->Self {self.nan_guard=guard;self}
|
||||
/// Select the adaptive window policy (`max_t` is the widest verify window, `mtp_t - 1` the longest MTP chain).
|
||||
pub(crate) fn with_adaptive(mut self,adaptive:Option<AdaptiveConfig>)->Self {
|
||||
self.adaptive=adaptive.map(|mut a|{a.max_t=a.max_t.min(self.max_t);a.max_drafts=a.max_drafts.min(self.mtp_t.saturating_sub(1)).min(a.max_t.saturating_sub(1));a});
|
||||
@@ -88,6 +136,8 @@ pub(crate) struct OriginalSpecController {
|
||||
adaptive:Option<AdaptivePolicy>,plan:Option<DraftPlan>,stats:SpecStats,
|
||||
/// The last draft stage ran a chain shortened by the context's end: the next stage restores the full chain in the engine's plan.
|
||||
chain_clamped:bool,
|
||||
/// Verify windows checked by the NaN guard so far (the injection counts them).
|
||||
windows_checked:u64,
|
||||
}
|
||||
/// Holds the authentic complete verification receipt until MTP catch-up has
|
||||
/// consumed all T residuals. It cannot be cloned or used as a state checkpoint.
|
||||
@@ -125,7 +175,7 @@ impl OriginalSpecController {
|
||||
let suffix=SuffixDrafter::new(config.suffix_min_match.max(1),64,cap)?;
|
||||
let policy=DraftPolicy::new(config.max_t,0.03)?;
|
||||
let adaptive=config.adaptive.map(AdaptivePolicy::new);
|
||||
Ok(Self{config,policy,suffix,request:None,rounds:0,failed:false,owner:Rc::new(()),final_draft:false,adaptive,plan:None,stats:SpecStats::default(),chain_clamped:false})
|
||||
Ok(Self{config,policy,suffix,request:None,rounds:0,failed:false,owner:Rc::new(()),final_draft:false,adaptive,plan:None,stats:SpecStats::default(),chain_clamped:false,windows_checked:0})
|
||||
}
|
||||
/// See `final_draft`; set before `begin_request`.
|
||||
pub(crate) fn set_final_draft(&mut self,on:bool) {self.final_draft=on;}
|
||||
@@ -229,15 +279,62 @@ impl OriginalSpecController {
|
||||
for i in 1..t {inputs[i]=if lookup {suffix_tokens[i-1]} else {r.drafts.ids()[i-1]};}
|
||||
let next_round=self.rounds.checked_add(1).ok_or(Error::Overflow)?;
|
||||
let target=engine.checkpoint_target()?;let draft=engine.checkpoint_draft()?;
|
||||
let prepare=(||{engine.apply_pending()?;engine.verify(p,&inputs[..t],&r.consumed)})();
|
||||
let mut verified=match prepare {Ok(v)=>v,Err(e)=>return Err(self.abort(engine,&target,&draft,e.into()))};
|
||||
let admission=(|| {
|
||||
engine.validate_verified(&verified,p,&inputs[..t])?;
|
||||
let out=engine.outputs(&verified);
|
||||
if out.len()!=t {return Err(Error::IdentityMismatch);}
|
||||
if out.iter().any(|&v|v<0||v as u32>=self.config.vocabulary) {return Err(Error::InvalidToken);}Ok(())
|
||||
})();
|
||||
if let Err(e)=admission {let _=engine.drain_verified(verified);return Err(self.abort(engine,&target,&draft,e.into()));}
|
||||
// NaN guard (upstream STRATA_NAN_GUARD, f332a855 / 894f133b): a window whose logits or stage outputs are not finite is run again from
|
||||
// this round's checkpoints instead of failing the request. Nothing of the window is committed or emitted before it passed, and the
|
||||
// restore is the one `abort` does. Off: the first failure aborts, exactly as before.
|
||||
let guard=self.config.nan_guard;
|
||||
self.windows_checked=self.windows_checked.saturating_add(1);
|
||||
let mut attempt=0u32;
|
||||
let mut verified=loop {
|
||||
let prepared=(||{engine.apply_pending()?;engine.verify(p,&inputs[..t],&r.consumed)})();
|
||||
let judged=match prepared {
|
||||
Err(e)=>Err((e,None)),
|
||||
Ok(v)=>{
|
||||
let admission=(|| {
|
||||
engine.validate_verified(&v,p,&inputs[..t])?;
|
||||
let out=engine.outputs(&v);
|
||||
if out.len()!=t {return Err(Error::IdentityMismatch);}
|
||||
if out.iter().any(|&x|x<0||x as u32>=self.config.vocabulary) {return Err(Error::InvalidToken);}Ok(())
|
||||
})();
|
||||
match admission {
|
||||
Err(e)=>Err((e,Some(v))),
|
||||
// the debug injection of upstream's STRATA_NAN_INJECT: the n-th checked window (first `times` attempts) reads as non-finite
|
||||
Ok(())=>if guard.injects(self.windows_checked,attempt) {Err((Error::NonFinite,Some(v)))} else {Ok(v)},
|
||||
}
|
||||
}
|
||||
};
|
||||
match judged {
|
||||
Ok(v)=>break v,
|
||||
Err((e,leftover))=>{
|
||||
if let Some(v)=leftover {let _=engine.drain_verified(v);}
|
||||
let what=format!("position {p}, {t} rows, attempt {} of {}: {e:?}",attempt+1,guard.retries);
|
||||
if guard.retries>attempt&&matches!(e,Error::NonFinite)&&!cancel() {
|
||||
let restored=(engine.restore_target(&target),engine.restore_draft(&draft));
|
||||
if restored.0.is_ok()&&restored.1.is_ok() {
|
||||
attempt+=1;
|
||||
eprintln!("leleka-serve nan-guard: a non-finite window ({what}); the round restarts from its checkpoint");
|
||||
continue;
|
||||
}
|
||||
// the checkpoint could not be restored: the state is unknown, nothing to retry on
|
||||
self.failed=true;
|
||||
if let Some(rq)=self.request.as_mut() {rq.finished=true;}
|
||||
leleka_memory::telemetry::nan_guard_unhealed(&format!("{what}; the checkpoint could not be restored"));
|
||||
eprintln!("leleka-serve nan-guard: a non-finite window ({what}) and its checkpoint could not be restored");
|
||||
return Err(e.into());
|
||||
}
|
||||
if guard.retries>0&&matches!(e,Error::NonFinite) {
|
||||
leleka_memory::telemetry::nan_guard_unhealed(&what);
|
||||
eprintln!("leleka-serve nan-guard: a non-finite window ({what}) was not healed; the request fails");
|
||||
}
|
||||
return Err(self.abort(engine,&target,&draft,e.into()));
|
||||
}
|
||||
}
|
||||
};
|
||||
if attempt>0 {
|
||||
self.stats.healed+=1;
|
||||
leleka_memory::telemetry::nan_guard_healed(&format!("position {p}, {t} rows, after {attempt} restart(s)"));
|
||||
eprintln!("leleka-serve nan-guard: healed the window at position {p} ({t} rows) after {attempt} restart(s)");
|
||||
}
|
||||
if cancel() {let _=engine.drain_verified(verified);return Err(self.abort(engine,&target,&draft,SpecError::Cancelled));}
|
||||
let mut outputs=[0;MAX_T];outputs[..t].copy_from_slice(engine.outputs(&verified));
|
||||
let mut accepted=0;while accepted<t-1&&inputs[accepted+1]==outputs[accepted] {accepted+=1;}
|
||||
@@ -389,12 +486,16 @@ mod tests {
|
||||
bad_output:Option<(usize,i32)>,cancel_after_verify:bool,
|
||||
/// the highest cell a window row or a draft touched (+1), and the chain lengths the controller asked for
|
||||
max_end:i64,plans:Vec<(usize,f32)>,
|
||||
/// how many times the named failure repeats (0 = once)
|
||||
fail_n:u32,
|
||||
/// every restore of the target fails (the checkpoint cannot be reached)
|
||||
fail_restore_target:bool,
|
||||
}
|
||||
impl Fake {
|
||||
fn new(prompt_prefix:&[i32])->Self {Self{committed:prompt_prefix.to_vec(),probs:vec![0.9;8],..Default::default()}}
|
||||
fn trip(&mut self,op:&'static str)->Result<()> {
|
||||
self.log.push(op.to_string());
|
||||
if let Some((name,e))=self.fail {if name==op {self.fail=None;return Err(e);}}
|
||||
if let Some((name,e))=self.fail {if name==op {if self.fail_n>1 {self.fail_n-=1;} else {self.fail=None;}return Err(e);}}
|
||||
Ok(())
|
||||
}
|
||||
fn count(&self,op:&str)->usize {self.log.iter().filter(|l|l.as_str()==op).count()}
|
||||
@@ -427,7 +528,7 @@ mod tests {
|
||||
}
|
||||
fn checkpoint_target(&self)->Result<usize> {Ok(self.committed.len())}
|
||||
fn checkpoint_draft(&self)->Result<u8> {Ok(7)}
|
||||
fn restore_target(&mut self,c:&usize)->Result<()> {self.trip("restore_target")?;self.committed.truncate(*c);Ok(())}
|
||||
fn restore_target(&mut self,c:&usize)->Result<()> {self.trip("restore_target")?;if self.fail_restore_target {return Err(Error::CudaExecution);}self.committed.truncate(*c);Ok(())}
|
||||
fn restore_draft(&mut self,c:&u8)->Result<()> {assert_eq!(*c,7);self.trip("restore_draft")}
|
||||
fn apply_pending(&mut self)->Result<()> {self.trip("apply_pending")}
|
||||
fn verify(&mut self,position:i64,inputs:&[i32],consumed:&[i32])->Result<Verif> {
|
||||
@@ -738,6 +839,155 @@ mod tests {
|
||||
assert_eq!(out,expected(&p,40));
|
||||
}
|
||||
|
||||
/// Upstream 41cf05a0 `f332a855` / `894f133b` (STRATA_NAN_GUARD, #879): a window whose output is not finite is not emitted; upstream ends the
|
||||
/// request and its gateway repeats it. Here the window itself is run again from its round's checkpoint.
|
||||
fn guarded(guard:NanGuard,max_new:usize)->(Fake,OriginalSpecController,Vec<i32>) {
|
||||
let p=prompt(6);let e=Fake::new(&p[..5]);
|
||||
let c=OriginalSpecController::new(config(4,4,0).with_nan_guard(guard)).unwrap();
|
||||
let _=max_new;
|
||||
(e,c,p)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_guard_reads_its_three_switches_and_refuses_a_malformed_one() {
|
||||
assert_eq!(NanGuard::parse(None,None,None),Ok(if NanGuard::DEFAULT_ON {NanGuard::with_retries(NanGuard::DEFAULT_RETRIES)} else {NanGuard::off()}));
|
||||
assert_eq!(NanGuard::parse(Some("on"),None,None),Ok(NanGuard::with_retries(2)));
|
||||
assert_eq!(NanGuard::parse(Some(" ON "),Some("5"),None),Ok(NanGuard::with_retries(5)));
|
||||
assert_eq!(NanGuard::parse(Some("off"),Some("5"),None),Ok(NanGuard::off()));
|
||||
assert_eq!(NanGuard::parse(Some("1"),Some("0"),None),Ok(NanGuard::with_retries(0)));
|
||||
assert_eq!(NanGuard::parse(Some("on"),None,Some("3")),Ok(NanGuard::with_retries(2).with_injection(3,1)));
|
||||
assert_eq!(NanGuard::parse(Some("on"),None,Some("4x2")),Ok(NanGuard::with_retries(2).with_injection(4,2)));
|
||||
for bad in [(Some("maybe"),None,None),(Some("on"),Some("9"),None),(Some("on"),Some("x"),None),(Some("on"),None,Some("0")),(Some("on"),None,Some("2x0")),(Some("on"),None,Some("a"))] {
|
||||
assert!(NanGuard::parse(bad.0,bad.1,bad.2).is_err(),"{bad:?}");
|
||||
}
|
||||
// an injection under a guard that is off does nothing: the guard has to be on to heal what it injects
|
||||
let off=NanGuard::parse(Some("off"),None,Some("2")).unwrap();
|
||||
assert!(!off.injects(2,0));
|
||||
assert!(NanGuard::with_retries(2).with_injection(2,1).injects(2,0));
|
||||
assert!(!NanGuard::with_retries(2).with_injection(2,1).injects(2,1),"only the first attempt");
|
||||
assert!(!NanGuard::with_retries(2).with_injection(2,1).injects(3,0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_non_finite_window_is_run_again_from_its_checkpoint_and_the_request_completes() {
|
||||
let want=expected(&prompt(6),20);
|
||||
for retries in [1u32,2,5] {
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(retries),20);
|
||||
e.fail=Some(("verify",Error::NonFinite));
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
let out=drive(&mut c,&mut e,&mut||false).unwrap();
|
||||
c.finish_request(&mut e).unwrap();
|
||||
assert_eq!(out,want,"retries {retries}: the text is the greedy one, nothing lost or repeated");
|
||||
assert!(!c.is_failed()&&c.finished());
|
||||
// one restore of each checkpoint, and the window was run twice: one more verify than a clean run
|
||||
assert_eq!((e.count("restore_target"),e.count("restore_draft")),(1,1));
|
||||
let (mut clean,mut cc,p2)=guarded(NanGuard::with_retries(retries),20);
|
||||
cc.begin_request(&p2,20,0.0,&[]).unwrap();
|
||||
drive(&mut cc,&mut clean,&mut||false).unwrap();
|
||||
assert_eq!(e.count("verify"),clean.count("verify")+1);
|
||||
assert_eq!(c.take_stats().healed,1);
|
||||
// what the session committed is exactly what the clean run committed
|
||||
assert_eq!(e.committed,clean.committed);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_guard_costs_nothing_when_nothing_is_wrong() {
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(2),30);
|
||||
c.begin_request(&p,30,0.0,&[]).unwrap();
|
||||
let out=drive(&mut c,&mut e,&mut||false).unwrap();
|
||||
assert_eq!(out,expected(&prompt(6),30));
|
||||
assert_eq!((e.count("restore_target"),e.count("restore_draft")),(0,0));
|
||||
assert_eq!(c.take_stats().healed,0);
|
||||
// and the same request with the guard off runs the identical sequence of engine calls
|
||||
let mut off=Fake::new(&prompt(6)[..5]);
|
||||
let mut co=OriginalSpecController::new(config(4,4,0)).unwrap();
|
||||
co.begin_request(&prompt(6),30,0.0,&[]).unwrap();
|
||||
drive(&mut co,&mut off,&mut||false).unwrap();
|
||||
assert_eq!(e.log,off.log);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_that_stays_non_finite_fails_the_request_after_the_retries() {
|
||||
for retries in [1u32,2] {
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(retries),20);
|
||||
e.fail=Some(("verify",Error::NonFinite));e.fail_n=retries+1;
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
let err=c.verify_commit(&mut e,&mut||false).err().unwrap();
|
||||
assert_eq!(err,SpecError::Forward(Error::NonFinite));
|
||||
assert!(c.finished()&&!c.is_failed(),"the request ends, the controller stays usable (the checkpoints were restored)");
|
||||
// retries restores for the retries, one more for the abort that gives up
|
||||
assert_eq!((e.count("restore_target"),e.count("restore_draft")),(retries as usize+1,retries as usize+1));
|
||||
assert_eq!(e.count("verify"),retries as usize+1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_non_finite_failure_is_retried_and_a_guard_that_is_off_retries_nothing() {
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(3),20);
|
||||
e.fail=Some(("verify",Error::CudaExecution));
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert_eq!(c.verify_commit(&mut e,&mut||false).err(),Some(SpecError::Forward(Error::CudaExecution)));
|
||||
assert_eq!((e.count("verify"),e.count("restore_target")),(1,1),"not retried");
|
||||
let (mut e,mut c,p)=guarded(NanGuard::off(),20);
|
||||
e.fail=Some(("verify",Error::NonFinite));
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert_eq!(c.verify_commit(&mut e,&mut||false).err(),Some(SpecError::Forward(Error::NonFinite)));
|
||||
assert_eq!((e.count("verify"),e.count("restore_target")),(1,1),"guard off: the first failure aborts as before");
|
||||
// a failed apply_pending of the adaptive tier is not a window either
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(3),20);
|
||||
e.fail=Some(("apply_pending",Error::CudaExecution));
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert!(c.verify_commit(&mut e,&mut||false).is_err());
|
||||
assert_eq!(e.count("verify"),0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_checkpoint_that_cannot_be_restored_ends_the_healing_with_the_original_error() {
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(3),20);
|
||||
e.fail=Some(("verify",Error::NonFinite));
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
// the restore the guard asks for fails: the state is unknown
|
||||
e.fail_restore_target=true;
|
||||
let err=c.verify_commit(&mut e,&mut||false).err().unwrap();
|
||||
assert_eq!(err,SpecError::Forward(Error::NonFinite),"the primary error is kept");
|
||||
assert!(c.is_failed()&&c.finished(),"the controller is unusable: its state is unknown");
|
||||
assert_eq!(e.count("verify"),1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_injection_exercises_the_same_path_on_a_good_window_and_counts_windows_across_requests() {
|
||||
// the 3rd checked window fails once: healed, text unchanged
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(2).with_injection(3,1),20);
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
let out=drive(&mut c,&mut e,&mut||false).unwrap();
|
||||
assert_eq!(out,expected(&prompt(6),20));
|
||||
assert_eq!(c.take_stats().healed,1);
|
||||
assert_eq!((e.count("restore_target"),e.count("restore_draft")),(1,1));
|
||||
// the window that was injected was a real, good one: it was drained before the retry
|
||||
assert_eq!(e.count("drain_verified"),e.count("verify"));
|
||||
// two failures in a row on one window, two retries: healed after two restarts
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(2).with_injection(2,2),20);
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert_eq!(drive(&mut c,&mut e,&mut||false).unwrap(),expected(&prompt(6),20));
|
||||
assert_eq!((e.count("restore_target"),e.count("restore_draft")),(2,2));
|
||||
// three failures, two retries: the request fails and says why
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(2).with_injection(2,3),20);
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert_eq!(drive(&mut c,&mut e,&mut||false).err(),Some(SpecError::Forward(Error::NonFinite)));
|
||||
// windows are counted across the requests of one controller
|
||||
let (mut e,mut c,p)=guarded(NanGuard::with_retries(2).with_injection(4,1),6);
|
||||
c.begin_request(&p,6,0.0,&[]).unwrap();
|
||||
drive(&mut c,&mut e,&mut||false).unwrap();
|
||||
c.finish_request(&mut e).unwrap();
|
||||
let first_request_windows=e.count("verify");
|
||||
assert!(first_request_windows<4,"{first_request_windows}");
|
||||
let mut e2=Fake::new(&p[..5]);
|
||||
c.begin_request(&p,20,0.0,&[]).unwrap();
|
||||
assert_eq!(drive(&mut c,&mut e2,&mut||false).unwrap(),expected(&p,20));
|
||||
assert_eq!(e2.count("restore_target"),1,"the injected window was one of the second request's");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_failure_restores_both_checkpoints_and_poisons_nothing_else() {
|
||||
let p=prompt(5);let mut e=Fake::new(&p[..4]);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# Numerical robustness ported from Strata 41cf05a0 (plan rows 1.1 and 1.2)
|
||||
|
||||
Evidence tables are in `docs/upstream-port-plan.md`; this page is the how-to.
|
||||
|
||||
## 1.1 q8_1 scale and sum stay finite
|
||||
|
||||
A q8_1 block stores `d = amax / 127` and the sum of its 32 activations as fp16. One massive activation (amax above 8.3 million, or a block
|
||||
sum past 65504) rounds to inf, the dot products then read `inf * 0 = NaN`, and the window ends in `NonFiniteMmqOutput` (upstream: one token
|
||||
repeated, issue #606). The quantizers now use `strata/kernels/q8_1_finite.hpp` (read from `engine/strata/include`, not modified): `d` and the
|
||||
sum are clamped to 65504, the codes to +-127, a NaN input keeps a NaN sum. A block that was finite before is stored bit for bit as before.
|
||||
|
||||
Sites that carry it (production decode path): `head_quant` (`mtp_original_full_head_native`, `native_head_native`), `mtp_original_quantize`
|
||||
(`mtp_original_tail`, `mtp_original_full_checks`), `quantize_q8_1_kernel` (`mtp_original_full_head_iq`, `native_head_iq`: input and SwiGLU
|
||||
output of the routed experts), `chain_swiglu_quant_kernel` (`chain_window`, `LELEKA_CHAIN`). Not changed: the MMQ prompt quantizers
|
||||
(ggml `quantize_mmq_q8_1`, `mtp_prefill_q8`: upstream did not clamp them) and the Q8_0 quantizers of the CPU-consistent expert path.
|
||||
|
||||
### Why the PTX is patched entry by entry
|
||||
|
||||
`mtp_original_{tail,full_checks,full_head_iq}.ptx` were built with CUDA 13.0.88, which is not installed anywhere we run; the others with
|
||||
13.2.86. A recompile renames every hashed anonymous-namespace entry (`_GLOBAL__N__<hash of the compile command>`, which the Rust window code
|
||||
looks up) and may reorder unrelated kernels. So only the quantizer entries are replaced:
|
||||
|
||||
```
|
||||
bash scripts/q8/rebuild_quantizer_ptx.sh # nvcc 13.2.86: compile the modified .cu, splice the quantizer entries into the sealed files (scripts/q8/splice_ptx.py)
|
||||
python3 scripts/q8/repin.py OLD_DIR NEW_DIR NAMES # move the Rust pins and the seal-plan digests to the new bodies
|
||||
python3 scripts/gpu-bringup/sm86_assets.py build --toolkit ~/cuda-toolkits/13.2.2 --work /tmp/sm86w # companions + MANIFEST + sm86_table.rs
|
||||
bash scripts/q8/probe_all.sh OLD_DIR NEW_DIR # the identity probe on the GPU (tools/q8-probe/q8_probe.cpp)
|
||||
```
|
||||
|
||||
The recipe was checked on the entries that were built with 13.2.86: recompiling the unchanged source gives a `head_quant` entry text identical
|
||||
to the sealed one. `mtp_original_tail.ptx` and `mtp_original_full_checks.ptx` have no Rust sha pin (only the `UNSEALED` marker is refused).
|
||||
|
||||
## 1.2 NaN guard with self-healing
|
||||
|
||||
`OriginalSpecController::verify_commit` runs a window from checkpoints it takes first. A verify window whose logits or stage outputs are not
|
||||
finite (`Error::NonFinite`: `NonFiniteMmqOutput` from the window's finite guards, STRA-235) used to abort: both checkpoints restored, the
|
||||
request fails. With the guard on, the same restore is followed by running the round again, up to `retries` times (default 2); only
|
||||
`NonFinite` is retried, a restore that fails ends the healing with the original error, and a window that stays non-finite fails the request
|
||||
as before. Nothing of a window is committed or emitted before it passed, so a healed round is indistinguishable from a clean one.
|
||||
|
||||
Upstream (`STRATA_NAN_GUARD`, #879) ends the request and has its gateway repeat it from token 0; here the window is repeated, so a request
|
||||
keeps its place. Not covered: non-finite output in a prefill chunk (the deferred prompt guards poison the CUDA context by design, so there is
|
||||
nothing to retry on) and a failure after the commit was enqueued.
|
||||
|
||||
| switch | meaning |
|
||||
| --- | --- |
|
||||
| `LELEKA_ORIGINAL_SERVE_NAN_GUARD=on\|off` | the guard (a profile `engine_env` key); unset = `NanGuard::DEFAULT_ON` |
|
||||
| `LELEKA_ORIGINAL_SERVE_NAN_GUARD_RETRIES=N` | 0..=8, default 2 |
|
||||
| `LELEKA_ORIGINAL_SERVE_NAN_INJECT=n[xK]` | debug (upstream `STRATA_NAN_INJECT`): the n-th checked window of the process reads as non-finite K times (default 1) after it ran well, so the path is exercised on a real window |
|
||||
|
||||
Every healed or unhealed window is written to stderr (`leleka-serve nan-guard: ...`), counted in `SpecStats` (`healed=` in `DBG spec-stats`) and
|
||||
published in the telemetry document: `nan_guard.healed_windows`, `nan_guard.unhealed_windows`, `nan_guard.last`.
|
||||
@@ -29,7 +29,7 @@ the run-to-run control); **L** live Codex session.
|
||||
| # | Item | Action | Gate | Status |
|
||||
|---|---|---|---|---|
|
||||
| 1.1 | q8_1 scale/sum overflow becomes NaN (`2b726ba6`, `f6601bf8`, `7a0e3023`, `e372d4ff`) | port the clamps to our sealed quantizers (`q8_1_store`, `native_quantize_q8_1`, SwiGLU quantizer, `gr_q8_*`) and regenerate the PTX; probe with extreme activations | I, Q | **U/I done, Q queued** (2026-10-26). Ours had the old formula everywhere (`d = amax / 127`, `make_half2(d, sum)`, `roundf(xi / d)` stored as int8): the entries `head_quant` (`mtp_original_full_head_native`, `native_head_native`), `mtp_original_quantize` (`mtp_original_tail`, `mtp_original_full_checks`), `quantize_q8_1_kernel` (`mtp_original_full_head_iq`, `native_head_iq`: the routed experts' input and SwiGLU output) and `chain_swiglu_quant_kernel` (`chain_window`). `gr_q8_*`, `q8_1_store` and the shared-expert SwiGLU quantizer have no separate copy in our sealed set (the GR reads and the shared expert quantize through `head_quant`; the experts through `quantize_q8_1_kernel`). Not changed: the MMQ prompt quantizers (ggml `quantize_mmq_q8_1`, `mtp_prefill_q8`; upstream did not clamp them either) and the Q8_0 CPU-consistent quantizers. **PTX not regenerated by a full compile:** three of the sealed files were built with CUDA 13.0.88 (not installed anywhere) and a recompile renames the hashed anonymous-namespace entries, so only the quantizer entries are replaced (`scripts/q8/splice_ptx.py`, recipe `scripts/q8/rebuild_quantizer_ptx.sh`, nvcc 13.2.86; the recipe reproduces the sealed `head_quant` text byte for byte on a recompile of the old source); every other byte of each sealed file is unchanged. Pins (`original_verify_window_{proj,moe,chain}.rs`, `native_head.rs`), the seal-plan digests and the sm_86 companions (`sm86_assets.py build`: 131 companions, `check` OK; it also added the companions of `chain_window` and `original_verify_window_pcie_fast` that were missing before) moved with them (`scripts/q8/repin.py`). Tests on the server: `leleka-cuda-driver` lib 387 passed with `--features "cuda-driver sm86"`, `leleka-runtime` lib 564, `ptxas -arch=sm_120` accepts every spliced file. **I (`tools/q8-probe`, `scripts/q8/probe_all.sh`, run directly on the 5090, log `~/work/gpu-runs/q8/probe_all.log`): all 7 assets OK.** 65,536 random blocks per asset (scales 1e-6..1e3, zero blocks, subnormals, ties, one big lane): 64,676 identical byte for byte, the 860 that differ are exactly the blocks whose float sum is past 65,000 or whose scale is past the half range (OLD stored inf there); 0 `h` words differ in the chain kernel. 15 edge/extreme blocks (sum 65504/65520/4e6, amax 8.0e6/8.4e6/1e9/1e30/FLT_MAX, +-inf, +inf and -inf, NaN lane, all NaN, zero): OLD stored a non-finite scale in 9 and a non-finite sum in 12; NEW stores a finite scale and sum in all of them except where the block really sums to NaN (it stays NaN so `STRATA_DBG_NAN`-style guards still see it), codes inside +-127 and equal to clamp(round(x / d)); a block that was finite before is the same bytes. **Q (queued behind the other agent's `upspeed-31-*` jobs, job `up2-q8-quality`, log `~/work/gpu-runs/holder2/jobs/up2-q8-quality.log`, runs `~/work/gpu-runs/quality/runs/Q8-*`; NOT run yet):** `rt-old` (this branch before the change) twice and `rt-new` once, teacher-forced along the Original paths, static tier, seed off, plus both with `LELEKA_CHAIN=all`; compare with `python3 scripts/quality/q_pair.py Q8-A1-old/port.log Q8-B1-new/port.log --control Q8-A2-old/port.log` (identical rows expected; if the port is not bit-deterministic run to run, read the deviation against the A1/A2 control with `q_tail_gate.py`'s rule). Until that runs, "outputs for normal activations are bit-identical" is established for the quantizer kernels (I) and not end to end |
|
||||
| 1.2 | NaN guard with self-healing, prompt retry after a non-finite window (`f332a855`, `894f133b`; `STRATA_NAN_GUARD=1`) | non-finite detection on the window logits, re-read from the last good checkpoint; port to the serve loop | U, L | todo |
|
||||
| 1.2 | NaN guard with self-healing, prompt retry after a non-finite window (`f332a855`, `894f133b`; `STRATA_NAN_GUARD=1`) | non-finite detection on the window logits, re-read from the last good checkpoint; port to the serve loop | U, L | **U done, L queued, default OFF** (2026-10-26). Detection already existed (the verify window's finite guards return `NonFiniteMmqOutput`, mapped to `Error::NonFinite`, without poisoning the context); what failed was the whole request (`abort` restores both checkpoints, the request ends as `Failed(NonFinite)`: STRA-235 on the laptop). `OriginalSpecController::verify_commit` now takes its round checkpoints and, with `LELEKA_ORIGINAL_SERVE_NAN_GUARD=on` (profile `engine_env` key; `..._RETRIES` 0..8, default 2), runs the round again after the same restore when a window fails with `NonFinite` (verify, validation or output admission); other errors, a failed restore (then the original error, controller marked failed) and a window that stays non-finite after the retries behave as before. Each healed and unhealed window is logged (`leleka-serve nan-guard: ...`), counted (`healed=` in `DBG spec-stats`) and published in the telemetry document (`nan_guard.healed_windows`, `unhealed_windows`, `last`: `leleka-memory` `telemetry::nan_guard_healed/unhealed`). `LELEKA_ORIGINAL_SERVE_NAN_INJECT=n[xK]` (upstream `STRATA_NAN_INJECT`) makes the n-th checked window read as non-finite K times after it ran well. Details: `docs/upstream-port-numerics.md`. Tests (server, `cargo test --release`): `leleka-runtime` lib 564 passed (new in `original_spec_controller`: `the_guard_reads_its_three_switches_and_refuses_a_malformed_one`, `a_non_finite_window_is_run_again_from_its_checkpoint_and_the_request_completes` (retries 1/2/5: greedy text, one restore of each checkpoint, one extra verify, same committed tokens as a clean run), `the_guard_costs_nothing_when_nothing_is_wrong` (identical engine call log with the guard on and off), `a_window_that_stays_non_finite_fails_the_request_after_the_retries`, `only_a_non_finite_failure_is_retried_and_a_guard_that_is_off_retries_nothing`, `a_checkpoint_that_cannot_be_restored_ends_the_healing_with_the_original_error`, `the_injection_exercises_the_same_path_on_a_good_window_and_counts_windows_across_requests`), `leleka-memory` lib 84 (`the_nan_guard_reports_each_healed_and_unhealed_window`). **Live (queued behind the other agent's `upspeed-31-*` jobs; job `up3-nan-guard-live`, runs `~/work/gpu-runs/quality/runs/Q8-G{0,1,2}-*`; NOT run yet):** binary `rt-guard`, guard on; G0 no injection, G1 window 7 once, G2 window 25 twice; every row of G1/G2 must equal G0 (`q_pair.py Q8-G0-guard-on/port.log Q8-G1-inject-7/port.log`), the log must show the `nan-guard` lines, and G0 must equal the Q8-A runs of the build without the guard. Default stays OFF (`NanGuard::DEFAULT_ON`) until that run shows no change of normal output; the unit test above shows the guard changes no engine call when nothing fails. Not covered: a non-finite prefill chunk (the deferred prompt guards poison the CUDA context by design, so there is nothing to retry on), a failure after the commit was enqueued, and upstream's gateway retry from token 0 |
|
||||
|
||||
## Phase 2: decode speed, bitwise (no change of output)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user