code wiki / _hdl_build / nx_autograd_mlp_gate.nx
nx_autograd_mlp_gate.nx
buildroot/runtime/_hdl_build/nx_autograd_mlp_gate.nx
about
nx_autograd_mlp_gate.nx -- R3.5->R4 bridge: prove the sovereign autograd trains a MULTI-LAYER MLP (the
COOL-CHIC decoder is a tiny MLP, so this is the prerequisite for the lead neural-codec avenue). Builds a
1->4->1 ReLU net + MSE loss entirely from the autograd primitives (define-by-run; rebuilt each step), then:
(a) GRADIENT-CHECKS weights across both layers vs central finite differences (proves backprop through the
full MLP graph -- the engine), and (b) runs SGD and shows the loss TRAINS DOWN overfitting |x| (a
nonlinear target a linear model cannot fit). Fixed-point Q16, no FPU/GPU/3rd-party. license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_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
| 10 | const Q: i64 = 65536 |
functions
| 12 | func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);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{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } |
| 13 | func g_w(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 } |
| 14 | func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);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{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 15 | func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v } |
| 17 | func ag_leaf(tp: *i64, np: *i64, v: i64) -> i64 { let k: i64=np[0]; tp[k*5]=v; tp[k*5+2]=0; tp[k*5+3]=0-1; tp[k*5+4]=0-1; np[0]=k+1; return k } called by 1: build_mlp |
| 18 | func ag_add(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=tp[i*5]+tp[j*5]; tp[k*5+2]=1; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k } called by 1: build_mlp |
| 19 | func ag_sub(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=tp[i*5]-tp[j*5]; tp[k*5+2]=4; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k } called by 1: build_mlp |
| 20 | func ag_mul(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=(tp[i*5]*tp[j*5])>>16; tp[k*5+2]=2; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k } called by 1: build_mlp |
| 21 | func ag_relu(tp: *i64, np: *i64, i: i64) -> i64 { let k: i64=np[0]; var v: i64=tp[i*5]; if v<0 { v=0 } tp[k*5]=v; tp[k*5+2]=3; tp[k*5+3]=i; tp[k*5+4]=0-1; np[0]=k+1; return k } called by 1: build_mlp |
| 22 | func ag_backward(tp: *i64, np: *i64, out: i64) -> i64 called by 1: main |
| 38 | func build_mlp(tp: *i64, np: *i64, w1: *i64, b1: *i64, w2: *i64, b2v: i64, H: i64, xv: i64, tgtv: i64) -> i64 |
| 59 | func close(auto: i64, num: i64) -> i64 { let dd: i64=iabs(auto-num); let tol: i64=(iabs(auto)*8)/100 + 96; if dd<=tol { return 1 } return 0 } |
| 61 | func main() -> i64 |