[HIP] SiTU interleaved gate/up + F32 router: generation matches reference

Root-cause fixes that make Inkling-2-Mini generation match strata-inkling:

- k_situ: w13 rows are INTERLEAVED gate/up (row 2j=gate[j], 2j+1=up[j]), exact strata k_moe_direct_w13_situ. Was reading block layout gu[j]/gu[inter+j] -> sign-flipped y_part. Now gu[2j]/gu[2j+1].

- k_router_gemv (new): B=1 router reads F32 mlpin @ bf16 gate promoted to f32 (strata launch_f32_linear). bf16-rounding the router input flipped top-k expert selection. Used in both layer_forward_swa/full.

- situ_cpu oracle + situ_parity_vs_cpu updated to interleaved.

- real_full_layer/full_attn CPU oracle: router reads F32 mlpin (was bf16) -> experts now match GPU exactly.

- real_attention_block parity: allclose (atol 2e-3 + rtol 3e-3). Stage bisection proved aout matches CPU to <1e-6 abs; pure-relative metric exploded only at near-cancellation O-proj elements after bf16 cast (benign accumulation artifact).

- gated VETTA_DBG_NORM per-visit norm dumps for future bisection.

Verified: 'The capital of France is' -> ' Paris.' (152717, exact ref). cargo test --workspace green (-D warnings), 17 ld GPU + 17 hip GPU green, 5 Lean files 0 sorryAx.
This commit is contained in:
adm committed 2026-12-01 16:31:18 +01:00
1 parent df120e6f5f
commit 08514e81b1
5 files changed
+114 -22

No files matched your search

+16 -2
View File
@@ -40,6 +40,10 @@ mod ffi {
x: *const u16, w: *const u16, y: *mut c_float,
m: c_int, n: c_int, k: c_int, stream: *mut c_void,
) -> c_int;
pub fn vetta_router_gemv(
x: *const c_float, w: *const u16, y: *mut c_float,
n: c_int, k: c_int, stream: *mut c_void,
) -> c_int;
pub fn vetta_flash_gqa_decode(
q: *const c_float, k: *const c_float, v: *const c_float, out: *mut c_float,
n_head: c_int, n_kv: c_int, seq: c_int, hd: c_int, scale: c_float, stream: *mut c_void,
@@ -193,6 +197,16 @@ pub fn gemm_bf16(x: &DeviceBuf, w: &DeviceBuf, y: &DeviceBuf, m: i32, n: i32, k:
Ok(())
}
/// Launch k_router_gemv: y[n] = x_f32[k] @ w_bf16[n,k]^T (F32 router input).
#[cfg(feature = "hip")]
pub fn router_gemv(x: &DeviceBuf, w: &DeviceBuf, y: &DeviceBuf, n: i32, k: i32) -> Result<(), String> {
let rc = unsafe {
ffi::vetta_router_gemv(x.ptr as *const f32, w.ptr as *const u16, y.ptr as *mut f32, n, k, std::ptr::null_mut())
};
if rc != 0 { return Err("router_gemv launch failed".into()); }
Ok(())
}
/// Launch k_flash_gqa_decode: single-token GQA attention over a f32 KV cache.
#[cfg(feature = "hip")]
pub fn flash_gqa_decode(q: &DeviceBuf, k: &DeviceBuf, v: &DeviceBuf, out: &DeviceBuf, n_head: i32, n_kv: i32, seq: i32, hd: i32, scale: f32) -> Result<(), String> {
@@ -712,8 +726,8 @@ mod gpu_tests {
for &inter in &[1152usize, 64, 256] {
let gu: Vec<f32> = (0..2 * inter).map(|i| ((i % 61) as f32 - 30.0) * 0.3).collect();
let want: Vec<f32> = (0..inter).map(|j| {
let g = gu[j];
let u = gu[inter + j];
let g = gu[2 * j];
let u = gu[2 * j + 1];
let sig = 1.0 / (1.0 + (-g).exp());
let ga = beta * (g / beta).tanh() * sig;
let ua = lb * (u / lb).tanh();