code wiki / (root) / nx_model_spec.nx

nx_model_spec.nx

buildroot/runtime/nx_model_spec.nx

12091 B337 linesdepth 4pulls 4 transitivereach 29 importersview sourcekind tooltopic model
docsdependenciesstructsconstsfunctions

about

nx_model_spec.nx -- typed model configuration envelope. L4 foundational data brick. Every model-running primitive composes against this: nx_gguf loader populates an NxModelSpec from metadata; the inference scaffold reads it to size scratch buffers and dispatch the right norm + activation + position-encoding kernels. Per the bits-up cardinal: model-specific constants (n_heads, hidden_dim, etc.) belong in a TYPED struct, not scattered as magic numbers across call sites. Per the data-driven cardinal: the same substrate runs Llama / Mistral / Qwen / GPT-2 / BERT just by swapping NxModelSpec values. ===== Sealed enums ============================================== Norm kind: NX_NORM_RMS -- Zhang/Sennrich 2019 (Llama / Mistral / Qwen) NX_NORM_LAYER -- Ba/Kiros/Hinton 2016 (GPT-2 / BERT / T5 / ViT) NX_NORM_NONE -- bypass (debug / experimentation) Activation kind (FFN gate function): NX_ACT_SILU -- Ramachandran 2017 (Llama / Mistral SwiGLU) NX_ACT_GELU -- Hendrycks/Gimpel 2016 (GPT-2 / BERT GeGLU) NX_ACT_RELU -- Fukushima 1969 / Glorot 2011 (older models) Position encoding kind: NX_POS_ROPE -- Su 2021 (Llama / Mistral / Qwen) NX_POS_SINUSOIDAL -- Vaswani 2017 (original transformer) NX_POS_LEARNED -- BERT / GPT-2 absolute-learned table NX_POS_NONE -- bypass FFN gating kind: NX_FFN_SWIGLU -- SiLU(gate) * up (Llama / Mistral) NX_FFN_GEGLU -- GELU(gate) * up (newer encoder models) NX_FFN_PLAIN -- act(up) (original transformer) genealogy_id: yaml_huggingface_config_2022 + onnx_model_metadata + ggml_gguf_metadata_2024 lineage_id: substrate_model_spec_v1

dependencies 3 imports · 9 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_model_spec.nx nx_actor_role_llm_v2.nx nx_actor_role_llm_v2_autoreg_test. nx_actor_role_llm_v2_real_test.nx nx_actor_role_llm_v2_test.nx nx_gguf_fixture_tiny.nx nx_gguf_fixture_tiny_test.nx nx_llm_run.nx nx_llm_run_v2.nx nx_llm_run_v2_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_loop.nx

imported by: nx_actor_role_llm_v2.nxnx_actor_role_llm_v2_autoreg_test.nxnx_actor_role_llm_v2_real_test.nxnx_actor_role_llm_v2_test.nxnx_gguf_fixture_tiny.nxnx_gguf_fixture_tiny_test.nxnx_llm_run.nxnx_llm_run_v2.nxnx_llm_run_v2_test.nx

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

main nx_model_spec_new sys_mmap nx_model_spec_validate nx_norm_is_valid nx_act_is_valid nx_pos_is_valid nx_ffn_is_valid nx_model_spec_llama_7b nx_model_spec_new ↻ nx_model_spec_total_params nx_model_spec_attn_params_ nx_model_spec_ffn_params_p nx_model_spec_mistral_7b nx_model_spec_new ↻ nx_model_spec_gpt2_small nx_model_spec_new ↻ nx_ms_verdict_is_valid

structs

123struct NxModelSpec

consts

54const NX_NORM_RMS: nx_int = 0
55const NX_NORM_LAYER: nx_int = 1
56const NX_NORM_NONE: nx_int = 2
57const NX_NORM_N: nx_int = 3
67const NX_ACT_SILU: nx_int = 0
68const NX_ACT_GELU: nx_int = 1
69const NX_ACT_RELU: nx_int = 2
70const NX_ACT_NONE: nx_int = 3
71const NX_ACT_N: nx_int = 4
81const NX_POS_ROPE: nx_int = 0
82const NX_POS_SINUSOIDAL: nx_int = 1
83const NX_POS_LEARNED: nx_int = 2
84const NX_POS_NONE: nx_int = 3
85const NX_POS_N: nx_int = 4
95const NX_FFN_SWIGLU: nx_int = 0
96const NX_FFN_GEGLU: nx_int = 1
97const NX_FFN_PLAIN: nx_int = 2
98const NX_FFN_N: nx_int = 3
108const NX_MS_OK: nx_int = 0
109const NX_MS_ERR_BAD_DIM: nx_int = 1
110const NX_MS_ERR_BAD_HEAD_GEOM: nx_int = 2
111const NX_MS_ERR_BAD_KIND: nx_int = 3
112const NX_MS_ERR_BAD_VOCAB: nx_int = 4
113const NX_MS_N_VERDICTS: nx_int = 5
138const NX_MS_STRUCT_BYTES: nx_int = 96 // 12 fields * 8

functions

59func nx_norm_is_valid(k: nx_int) -> nx_int
73func nx_act_is_valid(k: nx_int) -> nx_int
87func nx_pos_is_valid(k: nx_int) -> nx_int
100func nx_ffn_is_valid(k: nx_int) -> nx_int
115func nx_ms_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
140func nx_model_spec_new() -> *NxModelSpec
162func nx_model_spec_validate(s: *NxModelSpec) -> nx_int
196func nx_model_spec_attn_params_per_layer(s: *NxModelSpec) -> i64
203func nx_model_spec_ffn_params_per_layer(s: *NxModelSpec) -> i64
209func nx_model_spec_total_params(s: *NxModelSpec) -> i64
225func nx_model_spec_llama_7b() -> *NxModelSpec
called by 1: main calls 1: nx_model_spec_new
242func nx_model_spec_mistral_7b() -> *NxModelSpec
called by 1: main calls 1: nx_model_spec_new
259func nx_model_spec_gpt2_small() -> *NxModelSpec
called by 3: mainmainmain calls 1: nx_model_spec_new
289func main() -> i64