code wiki / _hdl_build / nx_intfp_mlp_gradcheck_gate.nx

nx_intfp_mlp_gradcheck_gate.nx

buildroot/runtime/_hdl_build/nx_intfp_mlp_gradcheck_gate.nx

6155 B102 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic intfp
docsdependenciesstructsconstsfunctions

about

nx_intfp_mlp_gradcheck_gate.nx -- SECOND brick of integer training: prove the CHAIN RULE in fixed-point. A 2-layer MLP h=W1@x ; a=ReLU(h) ; y=W2@a ; L=sum(y^2) done ENTIRELY in Q16 integer, with full backprop (gradients flow y<-a<-h<-W1 through the ReLU kink) and a gold-standard INTEGER finite-difference gradcheck on BOTH W1 (the DEEP matrix -- its gradient traverses the whole chain) and W2. If the deep gradients match numeric, the fixed-point chain rule is sound and a multi-op integer autograd tape is buildable. No float anywhere. Q16 (S=2^16): h_q=(W1_q@x_q)>>16 ; a=max(0,h) ; y_q=(W2_q@a_q)>>16 ; L_q32=sum(y_q^2). gy=2y ; gW2=(gy*a)>>16 ; ga=(sum_o gy*W2)>>16 ; gh=ga*[h>0] ; gW1=(gh*x)>>16 (all Q16 of the real grad) license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_intfp_mlp_gradcheck_gate.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main w sys_write sys_mmap fwd wn sys_write ↻ sys_mmap ↻ iabs

structs

none

consts

15const S: i64 = 65536
16const K: i64 = 3
17const H: i64 = 4
18const O: i64 = 2

functions

11func w(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 1: main calls 1: sys_write
12func wn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var q: i64=k-1; var i: i64=0; while q>=0{o[i]=t[q];i=i+1;q=q-1} sys_write(1,o,i); return 0 }
called by 1: main calls 2: sys_writesys_mmap
13func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v }
called by 1: main
21func fwd(W1: *i64, x: *i64, W2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64
called by 1: main
38func main() -> i64