code wiki / (root) / nx_gguf_load_block.nx

nx_gguf_load_block.nx

buildroot/runtime/nx_gguf_load_block.nx

13593 B325 linesdepth 7pulls 21 transitivereach 22 importersview sourcekind librarytopic gguf
docsdependenciesstructsconstsfunctions

about

nx_gguf_load_block.nx -- per-layer Llama-class weight bundle loader. L5 brick: composes nx_gguf_load_tensor + nx_rope_compute_inv_freq + NxTransformerBlockWeights to read the 9 named tensors for one transformer layer from a parsed GGUF and populate the bundle struct the transformer block forward consumes. This is the brick that takes nx_llm_run from v1 "API composition proof" to v2 "real-weight runner" -- caller can now load a Llama Q8_0 GGUF, ask for layer N's weights, and feed them to nx_transformer_block_forward unchanged. ===== Llama GGUF tensor naming convention (public format spec) === Per ggml docs (Gerganov 2024) -- clean-room implementation from public spec; no copied code. blk.{N}.attn_norm.weight -> gamma_attn (RMS-norm scale, 1-D) blk.{N}.attn_q.weight -> W_q blk.{N}.attn_k.weight -> W_k blk.{N}.attn_v.weight -> W_v blk.{N}.attn_output.weight -> W_o blk.{N}.ffn_norm.weight -> gamma_ffn (RMS-norm scale, 1-D) blk.{N}.ffn_gate.weight -> W_gate blk.{N}.ffn_up.weight -> W_up blk.{N}.ffn_down.weight -> W_down inv_freq is COMPUTED from rope_base via nx_rope_compute_inv_freq, not loaded -- GGUF stores rope_freq_base as metadata, not as a tensor. Caller supplies the base. Bits-up composition: nx_gguf.nx -- header + tensor_info table nx_gguf_load.nx -- per-tensor load + dequant (F32/F16/Q8_0) nx_strconv.nx -- decimal layer-index formatting nx_tensor.nx -- NxTensor return shape nx_rope.nx -- inv_freq computation nx_transformer_block.nx -- NxTransformerBlockWeights struct genealogy_id: llama_gguf_naming_gerganov_2024 +

dependencies 9 imports · 2 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_strconv.nx nx_tensor.nx nx_rope.nx nx_gguf.nx nx_gguf_load.nx nx_transformer_block.nx nx_gguf_load_block.nx nx_gguf_load_block_test.nx nx_transformer_stack.nx

imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_strconv.nxnx_tensor.nxnx_rope.nxnx_gguf.nxnx_gguf_load.nxnx_transformer_block.nx

imported by: nx_gguf_load_block_test.nxnx_transformer_stack.nx

structs

none

consts

74const NX_GBL_OK: nx_int = 0
75const NX_GBL_ERR_NOT_FOUND: nx_int = 1
76const NX_GBL_ERR_BAD_LAYER: nx_int = 2
77const NX_GBL_ERR_BAD_DIM: nx_int = 3
78const NX_GBL_ERR_OOM: nx_int = 4
79const NX_GBL_ERR_LOAD_FAIL: nx_int = 5
80const NX_GBL_ERR_NAME_TOO_BIG: nx_int = 6
81const NX_GBL_ERR_ROPE_FAIL: nx_int = 7
82const NX_GBL_N_VERDICTS: nx_int = 8
94const NX_GBL_MAX_NAME: nx_int = 64

functions

84func nx_gbl_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
103func _gbl_fmt_blk_name(layer_idx: nx_int,
146func _gbl_load_blk_tensor(buf: *u8, hdr: *NxGgufHeader,
176func nx_gguf_load_block_weights(buf: *u8, hdr: *NxGgufHeader,