code wiki / (root) / nx_moe_gate.nx

nx_moe_gate.nx

buildroot/runtime/nx_moe_gate.nx

6674 B174 linesdepth 9pulls 21 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_moe_gate.nx -- MEASURED gate for the sovereign MoE sparse FFN (nx_moe). PURE (no model, fast): NEG alloc rejects k > n_experts and zero dims ROUTE organ's top-k == an INDEPENDENT largest-logits scan (same tie rule); renormalized probs sum to 1 within 2^-15 ONE==FFN n_experts=1, top_k=1: nx_moe_forward BIT-EXACT equals the bare expert FFN (softmax(single)=1.0 exactly, p*y=y) SPARSE n=8, k=2, m=3: touch counters total EXACTLY m*k=6 -- the sparsity is measured, not asserted MIX forward's accumulation BIT-EXACT vs an oracle assembling route + expert_ffn + p-weighted sum in the same documented order DET forward twice -> identical bits license_tier: ORIGINAL expect_exit: 0

dependencies 10 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_cvt.nx nx_f32_div.nx nx_f32_softmax.nx nx_f32_matmul_t.nx nx_f32_activations.nx nx_moe.nx nx_fmt.nx nx_moe_gate.nx

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_cvt.nxnx_f32_div.nxnx_f32_softmax.nxnx_f32_matmul_t.nxnx_f32_activations.nxnx_moe.nxnx_fmt.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_moe_layer_alloc sys_mmap fmt_puts fmt_puts_fd sys_write mg_nl fmt_puts ↻ sys_mmap ↻ mg_fill_layer mg_fill mg_lcg nx_i32_to_f32 mg_fill ↻ nx_moe_route sys_mmap ↻ nx_f32_matmul_t mmt_range sys_mmap_shared sys_fork sys_exit sys_mmap ↻ sys_wait4 nx_f32_softmax _f32_gt nx_f32_sub nx_f32_add nx_f32_classify nx_f32_sign nx_f32_mant_field nx_f32_exp_field nx_f32_neg nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_sub ↻ nx_f32_exp nx_f32_classify ↻ nx_f32_sign ↻ _f32_to_i32_rne nx_f32_classify ↻

structs

none

consts

60const MG_HD: nx_int = 8
61const MG_FD: nx_int = 16

functions

29func mg_nl() -> i64 { fmt_puts("\n" as *u8); return 0 }
called by 1: main calls 1: fmt_puts
30func mg_lcg(s: i64) -> i64 { var v: i64 = s * 1103515245 + 12345; v = v & 2147483647; return v }
called by 1: mg_fill
31func mg_fill(p: *i64, n: nx_int, state: *i64) -> i64
43func mg_fill_layer(L: *NxMoeLayer, state: *i64) -> i64
called by 1: main calls 1: mg_fill
54func mg_cmp(a: *i64, b: *i64, n: nx_int) -> i64
called by 1: main
63func main() -> i64