[LD][GW] Fix systematic token-2+ parity gap: per-pass KV cache + unpadded logit vocab
Two root causes found by bisecting the pos-27/28 forward against strata-inkling (per-visit cur-norm dumps, STRATA_INK_NORM/POS, reverted after): 1. KV cache was shared across the 3 core loop passes. The reference assigns a DISTINCT KV pool per visit (visit_kv_slot: 40 SWA + 8 global), so each core pass reads its own KV history. Sharing one cache corrupted multi-token attention from the first core visit (visit6) onward. LayerState.k_cache/ v_cache are now [DeviceBuf; 3] indexed by pass (prelude/coda use pass 0). 2. Served/logit vocab used the PADDED size (201024). Padding tokens >= the unpadded vocab (200058) carry arbitrary logits and outranked real tokens (e.g. 200193 beat end_message 200010). Engine now uses unpadded_vocab, matching strata k_unembed_softcap V = vocab_unpadded. Verified: chat parity EXACT vs reference for 16 and 40 greedy tokens, both F32 (default) and FP16 KV. pos-28 per-visit norms now agree to ~3e-3 (was diverging by 50-80). Added serve_gen_multi_token_parity GPU regression. Suite: workspace -D warnings green; 18 ld + 18 hip + 4 gw GPU; 5 Lean 0 sorryAx.
This commit is contained in:
1 parent
cd853cda8b
commit
b9cac6d0df
2 files changed
+51
-17
No files matched your search
@@ -87,7 +87,11 @@ impl InklingEngine {
|
||||
Ok(Self {
|
||||
ar,
|
||||
d,
|
||||
vocab: t.vocab,
|
||||
// The served/logit vocab is the UNPADDED size (exact strata
|
||||
// k_unembed_softcap V = vocab_unpadded): rows >= unpadded are padding
|
||||
// tokens whose arbitrary logits must never win the argmax. Using the
|
||||
// padded vocab let padding tokens (e.g. 200193) outrank real ones.
|
||||
vocab: t.unpadded_vocab,
|
||||
n_layers: t.n_layers,
|
||||
eos: cfg.eos_token_id as i32,
|
||||
cap: t.final_logit_softcapping as f32,
|
||||
@@ -394,4 +398,29 @@ mod tests {
|
||||
assert!(!lines.iter().any(|l| l.starts_with("T ")), "pre-warm emits no tokens");
|
||||
assert!(lines.iter().any(|l| l.starts_with("DONE 0 2")), "DONE 0 2 ...");
|
||||
}
|
||||
|
||||
/// GPU regression: multi-token decode must match the reference EXACTLY. This
|
||||
/// locks in the two correctness fixes that eliminated the systematic token-2+
|
||||
/// divergence: (1) per-pass KV cache (each core pass owns a distinct KV pool,
|
||||
/// exact strata visit_kv_slot) and (2) unpadded logit vocab (padding tokens
|
||||
/// >= unpadded_vocab_size must never win the argmax). Sequence measured against
|
||||
/// strata-inkling --native model.gguf for "The capital of France is" (greedy).
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn serve_gen_multi_token_parity() {
|
||||
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
|
||||
let g = match parse_serve_line("GEN 16 temperature=0 371,151451,149879,151194,149884", eng.vocab()).unwrap() {
|
||||
ServeCommand::Gen(g) => g,
|
||||
_ => panic!("expected Gen"),
|
||||
};
|
||||
let stop = AtomicBool::new(false);
|
||||
let mut lines: Vec<String> = Vec::new();
|
||||
serve_gen(&eng, &g, &stop, &mut |l| lines.push(l));
|
||||
let tokens: Vec<i32> = lines.iter()
|
||||
.filter(|l| l.starts_with("T "))
|
||||
.map(|l| l[2..].trim().parse().unwrap())
|
||||
.collect();
|
||||
let want = [152717, 13, 68014, 32, 13, 220, 44781, 164452, 68014, 33, 13, 220, 57345, 745, 164452, 68014];
|
||||
assert_eq!(tokens, want, "multi-token decode must match reference exactly");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user