code wiki / _hdl_build / nx_ssm_lm_gate.nx

nx_ssm_lm_gate.nx

buildroot/runtime/_hdl_build/nx_ssm_lm_gate.nx

13177 B279 linesdepth 6pulls 16 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 3 imports · 0 importers

nx_autograd_tensor.nx nx_syscalls.nx nx_gate_verdict.nx nx_ssm_lm_gate.nx

imports: nx_autograd_tensor.nxnx_syscalls.nxnx_gate_verdict.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 nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ 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 ↻

structs

none

consts

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

functions

24func 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
25func lm_wn(fd: i64, v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
36func lm_embed(E: *i64, seq: *i64, soff: i64, xout: *i64) -> i64
called by 2: lm_buildlm_predict
48func lm_head(tape: *i64, vals: *i64, st: *i64, row: i64, nW1: i64, nb1: i64, nW2: i64, nb2: i64) -> i64
53func lm_build(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64,
89func 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
112func 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
124func 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
126func lm_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64,
197func 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
211func main() -> i64