nx_blockfloat_mha_gate.nx
buildroot/runtime/nx_blockfloat_mha_gate.nx
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
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
structs
| none |
consts
| none |
functions
| 15 | func 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 } |
| 16 | func bb_pn(v: i64) -> i64 |
| 26 | func bb_chk(name: *u8, ok: i64) -> i64 |
| 30 | func bb_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } |
| 31 | func 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 |
| 32 | func bf_scale_abs(W: *i64, off: i64, B: i64, MB: i64) -> i64 |
| 39 | func bf_quant_mat(W: *i64, rows: i64, cols: i64, B: i64, MB: i64, out: *i64) -> i64 |
| 54 | func bf_quant_pt(W: *i64, n: i64, MB: i64, out: *i64) -> i64 |
| 61 | func fill_mixed(W: *i64, n: i64, B: i64, sgn: i64) -> i64 called by 1: main |
| 73 | func 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 called by 1: mha_out calls 10: nfa_leafnfa_rmsnorm_rowsnfa_matmulnfa_slice_colsnfa_ropenfa_matmul_nt+4 |
| 105 | func 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 |
| 112 | func 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 } |
| 114 | func main() -> i64 |