code wiki / _hdl_build / nx_intfp_train_gate.nx

nx_intfp_train_gate.nx

buildroot/runtime/_hdl_build/nx_intfp_train_gate.nx

7556 B111 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic intfp
docsdependenciesstructsconstsfunctions

about

nx_intfp_train_gate.nx -- THIRD brick of integer training: prove an integer model actually LEARNS. A Q16 2-layer MLP (W1->ReLU->W2) trained by INTEGER SGD to fit NEX input->target examples, loss L=sum(y-t)^2. Everything -- forward, backprop, AND the weight update -- is fixed-point integer, NO float. If the loss falls by >10x over the run, the sovereign integer optimizer works end-to-end (the last unknown before the full tape). Q16 (S=2^16): fwd as before; gy=2*(y-t); grads accumulate over examples; SGD W_q -= (lr_q * gW_q) >> 16. This is where fixed-point can bite: small gradients can UNDERFLOW the update (truncate to 0). We MEASURE whether it converges anyway -- honest data on integer training dynamics, not an assertion. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_intfp_train_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 wn sys_write ↻ sys_mmap sys_mmap ↻ train_step sys_mmap ↻

structs

none

consts

13const S: i64 = 65536
14const K: i64 = 3
15const H: i64 = 8
16const O: i64 = 2
17const NEX: i64 = 3
18const STEPS: i64 = 2000

functions

10func 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
11func 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
21func train_step(W1: *i64, X: *i64, W2: *i64, T: *i64, gW1: *i64, gW2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64
called by 1: main calls 1: sys_mmap
47func main() -> i64