code wiki / _hdl_build / nx_train_r1_gate.nx

nx_train_r1_gate.nx

buildroot/runtime/_hdl_build/nx_train_r1_gate.nx

10115 B227 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind gate/prooftopic train
docsdependenciesstructsconstsfunctions

about

nx_train_r1_gate.nx -- GATE for TRAIN-R1: the scalar-tape autograd keystone. Proves, by RUNNING, that the team can TRAIN a model sovereignly. Three exact gates (spec 2026-06-09-tutoring-training-substrate-rung1.md): A GRADCHECK (oracle = mathematics): loss = (relu(w1*x+b1)*w2 + b2)^2 at params off the relu kink (w1=2/3, b1=1/4, w2=3/2, b2=1/4, x=3/4). For each param: analytic grad (reverse-mode backward) vs central finite difference (f(p+h)-f(p-h))/2h, h=1/128; relative error < 1/32 (floor 1/64). Catches every sign/chain-rule defect a wrong autograd could ship. B A MODEL PROVABLY LEARNS: fit y = 1.5x - 0.5 (8 points x=i/4, targets in-f32) by full-batch gradient descent, lr=1/20, 500 epochs, MSE via the tape. Assert final loss < 1/1000 AND |w-1.5| < 1/16 AND |b+0.5| < 1/16 AND final loss < first loss. The smallest EXACT statement of "we can train a model". C BIT-EXACT REPRODUCIBLE: run the whole training twice from zero-init; assert the final (w,b) f32 BITS are identical. GPU training is non-deterministic by default; the bits-up f32 substrate makes byte-identical training a GATE -- the determinism exceed-axis carried into ML. Evidence -> knowledge/status/train_r1.log (TRAINR1GATE authored=organ ... verdict=GREEN). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_autograd.nx nx_syscalls.nx nx_train_r1_gate.nx

imports: nx_autograd.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 ag_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 tr_analytic_grads sys_mmap ↻ tr_build_loss ag_leaf ag_add ag_mk nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ag_mul ag_mk ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ag_relu nx_f32_gt nx_f32_lt nx_f32_is_nan nx_f32_is_zero ag_mk ↻ ag_backward nx_f32_add ↻ nx_f32_mul ↻ nx_f32_neg nx_f32_gt ↻

structs

none

consts

19const TR_LOG: *u8 = "knowledge/status/train_r1.log"

functions

21func tr_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: tr_emit calls 1: sys_write
22func tr_wn(fd: i64, v: i64) -> i64
called by 1: tr_emit calls 2: sys_mmapsys_write
35func tr_f32_to_milli(v: i64) -> i64
54func tr_build_loss(tape: *i64, np: *i64, w1: i64, b1: i64, w2: i64, b2: i64, x: i64, leaves: *i64) -> i64
69func tr_loss_val(w1: i64, b1: i64, w2: i64, b2: i64, x: i64) -> i64
77func tr_analytic_grads(w1: i64, b1: i64, w2: i64, b2: i64, x: i64, gout: *i64) -> i64
89func tr_fd_grad(p: *i64, pi: i64, h: i64) -> i64
102func tr_train(epochs: i64, wout: *i64, bout: *i64, lfirst: *i64, llast: *i64) -> i64
149func tr_emit(fd: i64, r: *i64) -> i64
called by 1: main calls 2: tr_wtr_wn
161func main() -> i64