[LD] correctness debugging infra: full-attn CPU parity + stage bisect + dbg taps

Reference-ground-truth debugging continues (strata-inkling --serve gives the
correct continuations). Added diagnostics to isolate the remaining divergence:

- real_full_attn_layer_end_to_end: full CPU oracle for the full-attn layer
  (ip=5): 3-query mix split + separate q/k/v norms + distinct-input projections
  + dyn ShortConv (reversed taps) + global attention + MoE. Currently FAILS
  (max_rel_err 5.876) with IDENTICAL expert selection GPU==CPU — so the bug is
  downstream of routing, in the attention-output -> MoE-input path, not a
  router tie-flip. Kept as an #[ignore] diagnostic tracking the open bug.
- full_attn_bisect: stage-by-stage GPU-vs-CPU comparison (mix/norm/projections/
  dyn-shortconv) reporting max_rel + max_abs + rel-on-large-values. Findings:
  mix/norm match (~1e-6); GEMM absolute error ~1e-3 (benign bf16 rounding, the
  large max_rel is an artifact of the 1e-3 floor on near-zero outputs).
- sconv_dyn_step CPU helper; env-gated VETTA_DBG_NORM (residual/block norms)
  and VETTA_DBG_IDS (selected experts) taps in the layer forwards.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (5 files) green. The full-attn parity diagnostic is #[ignore] and
known-failing (open correctness bug under investigation).
This commit is contained in:
adm committed 2026-12-01 15:36:03 +01:00
1 parent b1bb4e13be
commit edcfab6548
2 files changed
+203

No files matched your search

+12
View File
@@ -217,6 +217,7 @@ pub fn layer_forward_swa(
let weights = DeviceBuf::alloc(d.top_k * 4)?;
vetta_infer_hip::moe_router_topk(&rlog, Some(&w.gate_b), &ids, &weights, 1, d.n_experts as i32, d.top_k as i32, d.route_scale)?;
let ids_h = { let mut b = vec![0u8; d.top_k * 4]; ids.d2h_bytes(&mut b)?; b.chunks_exact(4).map(|c| i32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect::<Vec<_>>() };
if std::env::var("VETTA_DBG_IDS").is_ok() { eprintln!("[dbg] ip={} GPU experts={:?}", w.ip, ids_h); }
let gu = DeviceBuf::alloc(2 * d.inter * 4)?;
let act = DeviceBuf::alloc(d.inter * 4)?;
let mut y_part_h = vec![0f32; d.top_k * h];
@@ -362,6 +363,10 @@ pub fn forward_inkling_with_state(
for ip in 0..6 { run_layer(ar, d, ip, &cur, &mut blocks, states, max_seq, pos, None)?; }
let mut prelude = vec![0f32; h]; cur.d2h(&mut prelude)?;
let n_prelude_blocks = blocks.len();
if std::env::var("VETTA_DBG_NORM").is_ok() {
let n = prelude.iter().map(|v| v * v).sum::<f32>().sqrt();
eprintln!("[dbg] after prelude: cur_norm={n:.3} blocks={}", blocks.len());
}
// Core: 3 passes.
for p in 0..3 {
let mut bank: Vec<DeviceBuf> = Vec::new();
@@ -396,6 +401,12 @@ pub fn forward_inkling_with_state(
}
// Coda.
for ip in 18..24 { run_layer(ar, d, ip, &cur, &mut blocks, states, max_seq, pos, None)?; }
if std::env::var("VETTA_DBG_NORM").is_ok() {
let mut ch = vec![0f32; h]; cur.d2h(&mut ch).unwrap();
let n = ch.iter().map(|v| v * v).sum::<f32>().sqrt();
eprintln!("[dbg] after coda: cur_norm={n:.3} blocks={}", blocks.len());
for (i, b) in blocks.iter().enumerate() { let mut bh = vec![0f32; h]; b.d2h(&mut bh).unwrap(); let bn = bh.iter().map(|v| v * v).sum::<f32>().sqrt(); eprintln!("[dbg] block[{i}]_norm={bn:.3}"); }
}
final_logits(ar, &cur, &blocks, h, vocab, d.eps, cap)
}
@@ -559,6 +570,7 @@ pub fn layer_forward_full(
let weights = DeviceBuf::alloc(d.top_k * 4)?;
vetta_infer_hip::moe_router_topk(&rlog, Some(&w.gate_b), &ids, &weights, 1, d.n_experts as i32, d.top_k as i32, d.route_scale)?;
let ids_h = { let mut b = vec![0u8; d.top_k * 4]; ids.d2h_bytes(&mut b)?; b.chunks_exact(4).map(|c| i32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect::<Vec<_>>() };
if std::env::var("VETTA_DBG_IDS").is_ok() { eprintln!("[dbg] ip={} GPU experts={:?}", w.ip, ids_h); }
let gu = DeviceBuf::alloc(2 * d.inter * 4)?;
let act = DeviceBuf::alloc(d.inter * 4)?;
let mut y_part_h = vec![0f32; d.top_k * h];