nx_moe.nx
buildroot/runtime/nx_moe.nx
about
nx_moe.nx -- sovereign MIXTURE-OF-EXPERTS sparse FFN (the last census
OPPORTUNITY axis "Mixture of experts (sparse)", momentum 3; Mixtral /
Switch-class, Shazeer 2017 / Fedus 2021 / Jiang 2024).
Per token: router logits = x @ W_router^T -> softmax -> TOP-K experts
-> renormalize the k probs -> out = sum_k p_i * SwiGLU_FFN_expert_i(x).
Only k of n_experts FFNs run per token (the sparsity that lets total
parameters scale past per-token compute). Experts accumulate in
SELECTION ORDER (prob-descending; ties -> lowest index) --
deterministic, documented, and mirrored by the gate's oracle.
Composes the EXISTING primitives: nx_f32_matmul_t (weights transposed,
the LLM convention), nx_f32_softmax, nx_f32_silu. Weights here are
plain F32 buffers; binding real MoE GGUF expert tensors (and the lazy/
quantized paths) is the documented follow-on once an MoE model is on
disk. Touch counters per expert make the sparsity MEASURABLE (gated),
not asserted.
genealogy_id: shazeer_2017_moe + fedus_2021_switch + jiang_2024_mixtral
lineage_id: substrate_moe_v1
dependencies 7 imports · 1 importers
imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_div.nxnx_f32_softmax.nxnx_f32_matmul_t.nxnx_f32_activations.nx
imported by: nx_moe_gate.nx
structs
| 39 | struct NxMoeLayer |
consts
| 30 | const NX_MOE_OK: nx_int = 0 |
| 31 | const NX_MOE_ERR_NULL: nx_int = 1 |
| 32 | const NX_MOE_ERR_BAD_DIM: nx_int = 2 |
| 51 | const NX_MOE_LAYER_BYTES: nx_int = 72 |
functions
| 53 | func nx_moe_layer_alloc(n_experts: nx_int, top_k: nx_int, |
| 87 | func nx_moe_route(L: *NxMoeLayer, x_row: *i64, called by 2: nx_moe_forwardmain calls 6: sys_mmapnx_f32_matmul_tnx_f32_softmaxnx_f32_gtnx_f32_addnx_f32_div |
| 135 | func nx_moe_expert_ffn(L: *NxMoeLayer, e: nx_int, x_row: *i64, |
| 164 | func nx_moe_forward(L: *NxMoeLayer, X: *i64, m: nx_int, |