code wiki / (root) / nx_blockfloat_mha_gate.nx

nx_blockfloat_mha_gate.nx

buildroot/runtime/nx_blockfloat_mha_gate.nx

9792 B174 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic blockfloat
docsdependenciesstructsconstsfunctions

about

nx_blockfloat_mha_gate.nx -- BLOCK-FLOAT weights through REAL MULTI-HEAD attention. Composes the existing gradcheck-verified multi-head forward (mha_fwd/mha_out from nx_nofloat_multihead_gate: RMSNorm -> Q/K/V -> split H heads -> per-head RoPE + scaled causal-softmax + A.V -> concat -> out-proj -> residual) UNCHANGED, run with the weight matrices (Wq,Wk,Wv,Wo) BLOCK-FLOAT quantized. Extends the single-head block result to multi-head -- the defining transformer feature -- proving block-float runs real multi-head attention better than per-tensor INT8. 1 multi-head attention RUNS with block-float weights (non-trivial output) 2 EXCEED: block-float MHA error vs full-precision < per-tensor INT8 3 DETERMINISTIC: block-float MHA run twice == bit-identical 4 per-tensor is LOSSY (output != full-precision) -- block-float's win is over real info loss expect_exit: 0 license_tier: ORIGINAL

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_verdict.nx nx_blockfloat_mha_gate.nx

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main bb_puts sys_write sys_mmap fill_mixed bf_quant_mat bf_scale_abs bb_abs bf_bitlen bf_quant_pt bf_scale_abs ↻ mha_out sys_mmap ↻ mha_fwd nfa_leaf nfa_new nfa_rmsnorm_rows nfa_new ↻ nfa_qmul nfa_isqrt nfa_matmul nfa_new ↻ nfa_slice_cols nfa_new ↻ nfa_rope nfa_new ↻ nfa_fxexp nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul ↻ nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ nfa_matmul_nt nfa_new ↻ nfa_cmul nfa_new ↻

structs

none

consts

none

functions

15func bb_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 2: bb_chkmain calls 1: sys_write
16func bb_pn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
26func bb_chk(name: *u8, ok: i64) -> i64
called by 1: main calls 1: bb_puts
30func bb_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 2: bf_scale_absl1err
31func bf_bitlen(x: i64) -> i64 { var b: i64 = 0; var m: i64 = x; while m > 0 { m = m >> 1; b = b + 1 } return b }
called by 1: bf_scale_abs
32func bf_scale_abs(W: *i64, off: i64, B: i64, MB: i64) -> i64
39func bf_quant_mat(W: *i64, rows: i64, cols: i64, B: i64, MB: i64, out: *i64) -> i64
called by 1: main calls 1: bf_scale_abs
54func bf_quant_pt(W: *i64, n: i64, MB: i64, out: *i64) -> i64
called by 1: main calls 1: bf_scale_abs
61func fill_mixed(W: *i64, n: i64, B: i64, sgn: i64) -> i64
called by 1: main
73func mha_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, X: *i64, T: i64, dm: i64, hd: i64, H: i64, scale: i64, leaves: *i64) -> i64
105func mha_out(tape: *i64, vals: *i64, st: *i64, W: *i64, X: *i64, T: i64, dm: i64, hd: i64, H: i64, scale: i64, outv: *i64) -> i64
called by 1: main calls 3: sys_mmapmha_fwdnfa_val
112func l1err(a: *i64, b: *i64, n: i64) -> i64 { var e: i64 = 0; var i: i64 = 0; while i < n { e = e + bb_abs(a[i] - b[i]); i = i + 1 } return e }
called by 1: main calls 1: bb_abs
114func main() -> i64