code wiki / _hdl_build / nx_train_r2_gate.nx
nx_train_r2_gate.nx
buildroot/runtime/_hdl_build/nx_train_r2_gate.nx
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
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
structs
| none |
consts
| 16 | const T2_LOG: *u8 = "knowledge/status/train_r2.log" |
functions
| 18 | func 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 } |
| 19 | func t2_wn(fd: i64, v: i64) -> i64 |
| 31 | func g_mlp_build(tape: *i64, vals: *i64, st: *i64, p: *i64, x: *i64, t: *i64, lv: *i64) -> i64 |
| 46 | func g_mlp_loss(tape: *i64, vals: *i64, st: *i64, p: *i64, x: *i64, t: *i64) -> i64 |
| 51 | func g_param_grad(tape: *i64, grads: *i64, lv: *i64, pi: i64) -> i64 |
| 59 | func g_affine_build(tape: *i64, vals: *i64, st: *i64, p: *i64, xs: *i64, ys: *i64, c1: *i64, wb: *i64) -> i64 |
| 78 | func g_read6(tape: *i64, grads: *i64, wb: *i64, g: *i64) -> i64 |
| 86 | func g_train_gd(tape: *i64, vals: *i64, grads: *i64, st: *i64, xs: *i64, ys: *i64, epochs: i64, pout: *i64, lossout: *i64) -> i64 |
| 110 | func g_train_adamw(tape: *i64, vals: *i64, grads: *i64, st: *i64, xs: *i64, ys: *i64, epochs: i64, pout: *i64, lossout: *i64) -> i64 |
| 155 | func main() -> i64 |