code wiki / _hdl_build / nx_lowrank_train.nx

nx_lowrank_train.nx

buildroot/runtime/_hdl_build/nx_lowrank_train.nx

13813 B273 linesdepth 6pulls 9 transitivereach 0 importersview sourcekind tooltopic lowrank
docsdependenciesstructsconstsfunctions

about

nx_lowrank_train.nx -- M2: does a LOW-RANK bottleneck IMPROVE quality (not just preserve it)? The MLA/ inductive-bias thesis (operator: "quality UP, VRAM down -- not just quant shrinking quality"). Trains models on a NOISY rank-2 target, scored on a CLEAN held-out test set, swept over many SEEDS (robustness) AND over bottleneck RANK (the U-curve -- guards the over-claim "smaller is always better"): FULL: y = W x (W is D x D = 64 params) -- can overfit the noise LOWRANK: y = Wu (Wd x) (Wd r x D, Wu D x r = 2*r*D params, the rank-r bottleneck) CLAIM (precise, not over-claimed): the OPTIMAL bottleneck rank MATCHES the data's true rank R0=2 -- too small (r=1) UNDERFITS, too large (r=4) OVERFITS like full, and at r=R0 it beats full at HALF the VRAM. Sovereign autograd (nx_tgrad_core tg_* + AdamW ad_step; the proven _t4 recipe). nx_cc UNTOUCHED (operator: it's the parallel effort). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_tgrad_core.nx nx_lowrank_train.nx

imports: nx_syscalls.nxnx_tgrad_core.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 m2_puts sys_write m2_putn sys_write ↻ sys_mmap ↻ m2_sweep_rank sys_mmap ↻ m2_rf tg_q 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 m2_lcg m2_gen m2_rf ↻ m2_apply sys_mmap ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_add ↻ tg_q ↻ m2_lcg ↻ m2_rsmall tg_q ↻ m2_lcg ↻

structs

none

consts

13const M2_MAGIC_1103515245: i64 = 1103515245
14const M2_MAGIC_12345: i64 = 12345
15const M2_MAGIC_2048: i64 = 2048
16const M2_MAGIC_4096: i64 = 4096
17const M2_MAGIC_20480: i64 = 20480
18const M2_MAGIC_16384: i64 = 16384
19const M2_MAGIC_100000: i64 = 100000
20const M2_MAGIC_1000003: i64 = 1000003
21const M2_MAGIC_7919: i64 = 7919
23const M2_D: i64 = 8
24const M2_R0: i64 = 2 // TRUE target rank
25const M2_R: i64 = 2 // low-rank model bottleneck (matched to R0)
26const M2_RMAX: i64 = 4 // max bottleneck rank in the sweep (buffer sizing)
27const M2_NTR: i64 = 12 // train samples
28const M2_NTE: i64 = 8 // test samples
29const M2_EPOCHS: i64 = 500
30const M2_NSEED: i64 = 9 // seed sweep -- robustness, not one lucky draw

functions

32func m2_puts(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
33func m2_putn(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
43func m2_lcg(st: *i64) -> i64 { st[0] = st[0] * M2_MAGIC_1103515245 + M2_MAGIC_12345; return (st[0] >> 20) & 0xfff }
44func m2_rf(st: *i64) -> i64 { return tg_q(m2_lcg(st) - M2_MAGIC_2048, M2_MAGIC_4096) } // ~[-0.5, 0.5]
called by 2: m2_genm2_sweep_rank calls 2: tg_qm2_lcg
45func m2_rsmall(st: *i64) -> i64 { return tg_q(m2_lcg(st) - M2_MAGIC_2048, M2_MAGIC_20480) } // ~[-0.1, 0.1] (weight init)
called by 1: m2_sweep_rank calls 2: tg_qm2_lcg
48func m2_apply(x: *i64, U: *i64, V: *i64, y: *i64) -> i64
called by 1: m2_gen calls 3: sys_mmapnx_f32_addnx_f32_mul
66func m2_gen(X: *i64, Y: *i64, n: i64, U: *i64, V: *i64, st: *i64, noisy: i64) -> i64
81func m2_train_full(tape: *i64, nb: *i64, arena: *i64, ab: *i64, X: *i64, Y: *i64, W: *i64, mW: *i64, vW: *i64) -> i64
107func m2_train_low(tape: *i64, nb: *i64, arena: *i64, ab: *i64, X: *i64, Y: *i64, Wd: *i64, Wu: *i64, mWd: *i64, vWd: *i64, mWu: *i64, vWu: *i64, r: i64) -> i64
135func m2_eval_full(tape: *i64, nb: *i64, arena: *i64, ab: *i64, X: *i64, Y: *i64, n: i64, W: *i64) -> i64
154func m2_eval_low(tape: *i64, nb: *i64, arena: *i64, ab: *i64, X: *i64, Y: *i64, n: i64, Wd: *i64, Wu: *i64, r: i64) -> i64
177func m2_sweep_rank(tape: *i64, nb: *i64, arena: *i64, ab: *i64, st: *i64, r: i64, out: *i64) -> i64
228func main() -> i64