[Core] forward_batch: batched prefill orchestration (M=B) BIT-EXACT end-to-end

forward_batch embeds B tokens and runs the proven schedule (inkling_loop.lean)
at M=B: prelude [0,6) -> core [6,18) x3 with DEVICE-SIDE bank rollback (arena
sub-range via copy_f32_sub, cur<-prelude copy, blocks.truncate) + cross-pass
msgs (attn_res_mix over bank, nq=4) + controllers on passes 1,2 -> coda [18,24)
-> final depth mix + unembed LAST token. run_layer_batched dispatches SWA/full.
No host D2H/H2D gather anywhere in the batched path (graph-capturable shape).

copy_f32_sub: device f32 copy from src offset (extract bank / last token).

forward_batch_parity (real weights, B=4, f16 KV + device MoE): logits for the
last token BIT-EXACT (max_abs=0.0) AND argmax identical (111) vs 4 sequential
forward_inkling_with_state calls. The full batched prefill is verified.
This commit is contained in:
adm committed 2026-12-02 00:27:42 +01:00
1 parent 1aaf7f12c2
commit b41a71f2f7
2 files changed
+136

No files matched your search

+11
View File
@@ -480,6 +480,17 @@ pub fn gather_channel(msgs: &DeviceBuf, dst: &DeviceBuf, ch: i32, b: i32, h: i32
Ok(())
}
/// Device-side f32 copy from `src` at element offset `src_offset` -> dst[0..n]
/// (extract a contiguous arena sub-range, e.g. the core-loop bank or last token).
#[cfg(feature = "hip")]
pub fn copy_f32_sub(src: &DeviceBuf, src_offset: usize, dst: &DeviceBuf, n: usize) -> Result<(), String> {
if src_offset * 4 + n * 4 > src.bytes { return Err("copy_f32_sub overflow".into()); }
let src_ptr = unsafe { (src.ptr as *const f32).add(src_offset) };
let rc = unsafe { ffi::vetta_copy_f32(src_ptr, dst.ptr as *mut f32, n, std::ptr::null_mut()) };
if rc != 0 { return Err("copy_f32_sub launch failed".into()); }
Ok(())
}
/// Launch k_cast_f32_bf16: f32 activation -> BF16 (round-to-nearest-even).
#[cfg(feature = "hip")]
pub fn cast_f32_bf16(x: &DeviceBuf, y: &DeviceBuf, n: usize) -> Result<(), String> {