nx_gguf_load_block.nx
buildroot/runtime/nx_gguf_load_block.nx
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
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
| 74 | const NX_GBL_OK: nx_int = 0 |
| 75 | const NX_GBL_ERR_NOT_FOUND: nx_int = 1 |
| 76 | const NX_GBL_ERR_BAD_LAYER: nx_int = 2 |
| 77 | const NX_GBL_ERR_BAD_DIM: nx_int = 3 |
| 78 | const NX_GBL_ERR_OOM: nx_int = 4 |
| 79 | const NX_GBL_ERR_LOAD_FAIL: nx_int = 5 |
| 80 | const NX_GBL_ERR_NAME_TOO_BIG: nx_int = 6 |
| 81 | const NX_GBL_ERR_ROPE_FAIL: nx_int = 7 |
| 82 | const NX_GBL_N_VERDICTS: nx_int = 8 |
| 94 | const NX_GBL_MAX_NAME: nx_int = 64 |
functions
| 84 | func nx_gbl_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 103 | func _gbl_fmt_blk_name(layer_idx: nx_int, |
| 146 | func _gbl_load_blk_tensor(buf: *u8, hdr: *NxGgufHeader, |
| 176 | func nx_gguf_load_block_weights(buf: *u8, hdr: *NxGgufHeader, called by 1: nx_transformer_stack_forward calls 3: sys_mmap_gbl_load_blk_tensornx_rope_compute_inv_freq |