code wiki / _hdl_build / nx_train_r2_gate.nx

nx_train_r2_gate.nx

buildroot/runtime/_hdl_build/nx_train_r2_gate.nx

13816 B291 linesdepth 6pulls 15 transitivereach 0 importersview sourcekind gate/prooftopic train
docsdependenciesstructsconstsfunctions

about

nx_train_r2_gate.nx -- GATE for TRAIN-R2 (T6): tensor autograd. Proves, by RUNNING: A MLP GRADCHECK: loss = MSE(W2*relu(W1*x+b1)+b2, t), W1 2x2/b1 2/W2 1x2/b2 1 = 9 params (values off the relu kinks). Each param: analytic (reverse-mode) vs central finite diff (h=1/128), rel<1/32 floor 1/64. Exercises every identity (matvec x2, vadd x2, relu, mse) through a real nonlinear composition. B RECOVER AN AFFINE MAP: train W(2x2)+b(2) to recover y=A*x+c (A=[[3/2,-1/2],[1/4,1]], c=[-1/2,3/4]) from 8 deterministic samples; full-batch GD lr=1/10, 400 epochs. Assert loss<1/1000 AND every W,b elt within 1/16 of truth. (LINEAR model: zero-init is convex-safe; nonconvex needs an init strategy = next rung.) C BIT-EXACT: run Gate-B training twice from scratch -> identical final bits for all 6 cells. D AdamW: the same affine recovery via AdamW (m/v moments + bias correction + sqrt) also converges -- the optimizer the FNet/transformer models will actually use. Evidence -> knowledge/status/train_r2.log (TRAINR2GATE authored=organ ... verdict=GREEN). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_autograd_tensor.nx nx_syscalls.nx nx_train_r2_gate.nx

imports: nx_autograd_tensor.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap ta_constf nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_i32_to_f32 g_mlp_build ta_leaf ta_new ta_vadd ta_new ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ta_matvec ta_new ↻ nx_f32_add ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ta_relu ta_new ↻ nx_f32_gt nx_f32_lt nx_f32_is_nan nx_f32_classify ↻ nx_f32_is_zero nx_f32_classify ↻ ta_mse ta_new ↻ nx_f32_sub

structs

none

consts

16const T2_LOG: *u8 = "knowledge/status/train_r2.log"

functions

18func t2_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 }
called by 1: main calls 1: sys_write
19func t2_wn(fd: i64, v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
31func g_mlp_build(tape: *i64, vals: *i64, st: *i64, p: *i64, x: *i64, t: *i64, lv: *i64) -> i64
46func g_mlp_loss(tape: *i64, vals: *i64, st: *i64, p: *i64, x: *i64, t: *i64) -> i64
called by 1: main calls 3: sys_mmapg_mlp_buildta_val
51func g_param_grad(tape: *i64, grads: *i64, lv: *i64, pi: i64) -> i64
called by 1: main calls 1: ta_grad
59func g_affine_build(tape: *i64, vals: *i64, st: *i64, p: *i64, xs: *i64, ys: *i64, c1: *i64, wb: *i64) -> i64
78func g_read6(tape: *i64, grads: *i64, wb: *i64, g: *i64) -> i64
called by 2: g_train_gdg_train_adamw calls 1: ta_grad
86func g_train_gd(tape: *i64, vals: *i64, grads: *i64, st: *i64, xs: *i64, ys: *i64, epochs: i64, pout: *i64, lossout: *i64) -> i64
110func g_train_adamw(tape: *i64, vals: *i64, grads: *i64, st: *i64, xs: *i64, ys: *i64, epochs: i64, pout: *i64, lossout: *i64) -> i64
155func main() -> i64