code wiki / _hdl_build / nx_nofloat_block_gate.nx
nx_nofloat_block_gate.nx
buildroot/runtime/_hdl_build/nx_nofloat_block_gate.nx
about
nx_nofloat_block_gate.nx -- HARD-EVIDENCE gate for a COMPLETE pre-norm TRANSFORMER BLOCK backprop + train,
in PURE INTEGER Q16 (CAP-NF-BLOCK). The block (single-head) is the real Qwen-style shape:
H = X + Wo * Attn( RoPE, scaled, causal-softmax )( rmsnorm_rows(X) ) [attention sublayer + residual]
Y = H + SwiGLU-FFN( rmsnorm_rows(H) ) [FFN sublayer + residual]
SwiGLU-FFN(z) = Wd * ( silu(Wg*z) (*) (Wu*z) )
Composed ENTIRELY from gradcheck-verified ops (rmsnorm_rows, matmul, matmul_nt, rope, cmul, softmax_rows,
silu, hadamard, vadd, mse). No new backward math -- this proves the COMPOSITION trains.
A1 hadamard gradcheck : loss=mse(a(*)b,t); dL/da == finite diff.
A2 rmsnorm_rows gradcheck: per-token norm; dL/dx == finite diff.
A3 FULL-BLOCK gradcheck wrt Wd (down-proj, short path): dL/dWd == finite diff.
A4 FULL-BLOCK gradcheck wrt Wq (the LONGEST chain: through FFN, residual, attention, RoPE, softmax): measured.
B the BLOCK TRAINS : with all weights fixed except the down-proj Wd, Y is LINEAR in Wd (convex MSE) ->
train Wd from zero to a realizable teacher target; assert loss collapses + Wd converges. A weight DEEP in
a full transformer block is driven by the block's own end-to-end backward.
C bit-exact ; D neg-control teeth.
Evidence -> knowledge/status/nofloat_block.log. Sovereign: nx_nofloat_autograd + nx_syscalls (pure integer).
HONEST scope: single-head; multi-head/GQA + multi-block stack are the remaining COMPOSITION. expect_exit: 0
dependencies 3 imports · 0 importers
imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.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
| 24 | const BLOG: *u8 = "knowledge/status/nofloat_block.log" |
| 25 | const Q16: i64 = 65536 |
functions
| 28 | func g_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 29 | func b_ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 30 | func b_wn(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 } |
| 33 | func one_loss(tape: *i64, vals: *i64, st: *i64, op: i64, Xs: *i64, Bs: *i64, Ts: *i64, r: i64, c: i64, leaves: *i64) -> i64 |
| 44 | func one_lossval(tape: *i64, vals: *i64, st: *i64, op: i64, Xs: *i64, Bs: *i64, Ts: *i64, r: i64, c: i64) -> i64 |
| 49 | func one_gradcheck(tape: *i64, vals: *i64, grads: *i64, st: *i64, op: i64, Xs: *i64, Bs: *i64, Ts: *i64, r: i64, c: i64, h: i64, tol_q: i64, floor_q: i64, worst: *i64) -> i64 |
| 77 | func blk_fwd(tape: *i64, vals: *i64, st: *i64, X: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wg: *i64, Wu: *i64, Wd: *i64, T: i64, dm: i64, ffn: i64, scale: i64, leaves: *i64) -> i64 called by 2: blk_lossblk_out calls 10: nfa_leafnfa_rmsnorm_rowsnfa_matmulnfa_ropenfa_matmul_ntnfa_cmul+4 |
| 109 | func blk_loss(tape: *i64, vals: *i64, st: *i64, X: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wg: *i64, Wu: *i64, Wd: *i64, Ts: *i64, T: i64, dm: i64, ffn: i64, scale: i64, leaves: *i64) -> i64 |
| 114 | func blk_lossval(tape: *i64, vals: *i64, st: *i64, X: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wg: *i64, Wu: *i64, Wd: *i64, Ts: *i64, T: i64, dm: i64, ffn: i64, scale: i64) -> i64 |
| 119 | func blk_out(tape: *i64, vals: *i64, st: *i64, X: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wg: *i64, Wu: *i64, Wd: *i64, T: i64, dm: i64, ffn: i64, scale: i64, outY: *i64) -> i64 |
| 127 | func main() -> i64 |