code wiki / _hdl_build / nx_ssm_lm_gate.nx

nx_ssm_lm_gate.nx

buildroot/runtime/_hdl_build/nx_ssm_lm_gate.nx

12645 B271 linesdepth 6pulls 15 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_ssm_lm_gate.nx -- GATE for MODEL-003: a CAUSAL AUTOREGRESSIVE next-token language model (GPT-shaped, decoder) with NO attention. The causal SSM scan makes next-token prediction legal (each position's state sees only the past): tokens -> EMBED(trained) -> TA_SSM causal mix -> per-position SLICE -> shared relu-FFN head -> softmax-CE predicting token t+1 from tokens 0..t. AdamW trains the embedding + the SSM decay + the head jointly. Corpus = 4 cyclic-shift sequences over vocab 4 (a simple deterministic language, next = (cur+1) mod 4); 12 next-token predictions. G_train next-token accuracy >= 11/12 AND final loss < first loss. G_repro bit-exact: train twice -> identical accuracy + final-loss bits. Evidence -> knowledge/status/ssm_lm.log (SSMLMGATE authored=organ ... verdict=GREEN). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_autograd_tensor.nx nx_syscalls.nx nx_ssm_lm_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 lm_train ta_det_init 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 lm_zero ta_constf ↻ sys_mmap ↻ lm_build ta_leaf ta_new sys_mmap ↻ lm_embed ta_ssm ta_new ↻ 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 ↻ ta_slice ta_new ↻ lm_head ta_relu ta_new ↻ nx_f32_gt nx_f32_lt

structs

none

consts

16const LV: i64 = 4 // vocab
17const LN: i64 = 4 // sequence length
18const LD: i64 = 4 // d_model
19const LH: i64 = 8 // FFN hidden
20const LP: i64 = 3 // predictions per sequence (positions 0..LN-2)
21const LM_LOG: *u8 = "knowledge/status/ssm_lm.log"

functions

23func lm_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
24func lm_wn(fd: i64, v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
35func lm_embed(E: *i64, seq: *i64, soff: i64, xout: *i64) -> i64
called by 2: lm_buildlm_predict
47func lm_head(tape: *i64, vals: *i64, st: *i64, row: i64, nW1: i64, nb1: i64, nW2: i64, nb2: i64) -> i64
52func lm_build(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64,
88func lm_predict(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, seqs: *i64, s: i64, pos: i64) -> i64
111func lm_adamw(p: *i64, m: *i64, v: *i64, g: *i64, n: i64, lr: i64, beta1: i64, beta2: i64, om1: i64, om2: i64, eps: i64, c1: i64, c2: i64) -> i64
123func lm_zero(a: *i64, n: i64) -> i64 { var i: i64 = 0; while i < n { a[i] = TA_F32_ZERO; i = i + 1 } return 0 }
called by 1: lm_train
125func lm_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64,
196func lm_accuracy(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, seqs: *i64) -> i64
called by 1: main calls 1: lm_predict
210func main() -> i64