code wiki / (root) / nx_gguf_meta.nx

nx_gguf_meta.nx

buildroot/runtime/nx_gguf_meta.nx

8371 B238 linesdepth 6pulls 8 transitivereach 129 importersview sourcekind librarytopic gguf
docsdependenciesstructsconstsfunctions

about

nx_gguf_meta.nx -- GGUF metadata key-value walker + typed readers. Extends nx_gguf.nx by parsing the metadata section that nx_gguf_parse currently SKIPS. Unblocks reading model architecture parameters (n_layers / hidden_dim / rope_base / n_heads / vocab_size) + the BPE tokenizer vocab from real Llama / Mistral / Qwen GGUF files, rather than requiring the caller to know the spec a priori. Canonical Llama metadata keys (public spec, ggml docs): "general.architecture" STRING -> "llama" "llama.attention.head_count" UINT32 -> n_heads "llama.attention.head_count_kv" UINT32 -> n_kv_heads "llama.embedding_length" UINT32 -> hidden_dim "llama.block_count" UINT32 -> n_layers "llama.feed_forward_length" UINT32 -> ffn_dim "llama.context_length" UINT32 -> max_seq_len "llama.rope.freq_base" FLOAT32 -> rope_base "llama.attention.layer_norm_rms_epsilon" FLOAT32 -> rms eps "tokenizer.ggml.tokens" ARRAY of STRING -> BPE vocab "tokenizer.ggml.scores" ARRAY of FLOAT32 -> BPE merge scores Bits-up composition: nx_gguf.nx -- header + skip-value canonical helper nx_gguf_load.nx -- _gguf_f32_to_q10 (composed for f32 read) nx_le.nx -- LE binary readers genealogy_id: gguf_v3_metadata_spec_gerganov_2024 lineage_id: substrate_gguf_meta_v1_walker

dependencies 6 imports · 89 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_le.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_batched_gate.nx nx_batched_tput.nx nx_chat_warmcache.nx nx_coder_gen_f32.nx nx_companion_chat.nx nx_companion_voice.nx nx_embed_bench.nx nx_f32_bpe_load.nx nx_f32_bpe_load_test.nx nx_f32_embed_gate.nx

diagram shows first 10 each side; +0 more imports, +79 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_le.nxnx_gguf.nxnx_gguf_load.nx

imported by: nx_batched_gate.nxnx_batched_tput.nxnx_chat_warmcache.nxnx_coder_gen_f32.nxnx_companion_chat.nxnx_companion_voice.nxnx_embed_bench.nxnx_f32_bpe_load.nxnx_f32_bpe_load_test.nxnx_f32_embed_gate.nxnx_f32_llm_bench_test.nxnx_f32_llm_chat_test.nxnx_f32_llm_cohere_test.nxnx_f32_llm_live_dims_test.nxnx_f32_llm_live_gen_test.nxnx_f32_llm_live_load_test.nxnx_f32_llm_probe.nxnx_f32_llm_read_dims.nxnx_f32_llm_read_dims_test.nxnx_f32_llm_serve.nxnx_f32_llm_special_tokens.nxnx_f32_llm_special_tokens_test.nxnx_f32_qwen_capital_gate.nxnx_gguf_dequant_kat_gate.nxnx_gguf_meta_test.nxnx_gguf_write_gate.nxnx_gpu_export.nxnx_gpu_serve_gate.nxnx_llm_argmax_probe.nxnx_llm_batch_serve.nxnx_llm_capcheck.nxnx_llm_diff_probe.nxnx_llm_forward_profile.nxnx_llm_france_probe.nxnx_llm_layerlens_probe.nxnx_llm_loopb_gate.nxnx_llm_ppl_bench_gate.nxnx_llm_sched_gate.nxnx_lowrank_kv_real.nxnx_lowrank_weight_spectrum.nxnx_nofloat_arch.nxnx_nofloat_arch_config_gate.nxnx_nofloat_arch_moe_gate.nxnx_nofloat_moe_real_gate.nxnx_nofloat_olmoe_forward_gate.nxnx_nofloat_olmoe_gate.nxnx_nofloat_qwen_config_gate.nxnx_nofloat_qwen_decode_gate.nxnx_nofloat_qwen_diag_gate.nxnx_nofloat_qwen_dqprobe_gate.nxnx_nofloat_qwen_encode_gate.nxnx_nofloat_qwen_encode_prep_gate.nxnx_nofloat_qwen_fastgen_gate.nxnx_nofloat_qwen_fastgen_i32_gate.nxnx_nofloat_qwen_fastgen_i8_gate.nxnx_nofloat_qwen_gen_gate.nxnx_nofloat_qwen_kvgen_gate.nxnx_nofloat_qwen_text_gate.nxnx_nofloat_qwen_tok_gate.nxnx_nofloat_serve_core.nxnx_nofloat_tok.nxnx_olmoe_recon2_gate.nxnx_paged_fwd_gate.nxnx_q4k_dot_simd.nxnx_q4k_gemm_mt.nxnx_q4k_linear.nxnx_q4k_linear_hp.nxnx_q4k_real_gemm.nxnx_q4k_speed_bench.nxnx_q5k_dot_simd.nxnx_qwen_blk0_types.nxnx_qwen_hybrid_attn.nxnx_qwen_hybrid_ffn.nxnx_qwen_hybrid_qkv.nxnx_qwen_native_gate.nxnx_qwen_wsl_timing_gate.nxnx_real_gguf_test.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning_gate.nxnx_specdec_gate.nxnx_zimage_dequant_block.nxnx_zimage_gguf_arch.nxnx_zimage_gguf_probe.nxnx_zimage_layout.nxnx_zimage_real_op.nxnx_zimage_real_proj.nxnx_zimage_real_qkv.nxnx_zimage_weights.nx

structs

none

consts

54const NX_MAGIC_32768: i64 = 32768
55const NX_MAGIC_65536: i64 = 65536
56const NX_MAGIC_2147483648: i64 = 2147483648
57const NX_MAGIC_4294967296: i64 = 4294967296
61const NX_GMETA_OK: nx_int = 0
62const NX_GMETA_NOT_FOUND: nx_int = 1
63const NX_GMETA_ERR_OOB: nx_int = 2
64const NX_GMETA_ERR_BAD_TYPE: nx_int = 3
65const NX_GMETA_ERR_TRUNCATED: nx_int = 4
66const NX_GMETA_N_VERDICTS: nx_int = 5

functions

68func nx_gmeta_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
75func _gmeta_bytes_equal(a: *u8, b: *u8, n: nx_int) -> nx_int
called by 1: nx_gguf_meta_find
97func nx_gguf_meta_find(buf: *u8, len: i64, hdr: *NxGgufHeader,
138func nx_gguf_meta_read_u8(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u8
142func nx_gguf_meta_read_u16(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u16
146func nx_gguf_meta_read_u32(buf: *u8, off: i64) -> i64
150func nx_gguf_meta_read_u64(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u64
157func nx_gguf_meta_read_i8(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u8
163func nx_gguf_meta_read_i16(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u16
169func nx_gguf_meta_read_i32(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u32
178func nx_gguf_meta_read_f32_q10(buf: *u8, off: i64) -> i64
185func nx_gguf_meta_read_bool(buf: *u8, off: i64) -> i64
calls 1: nx_le_read_u8
195func nx_gguf_meta_read_string_len(buf: *u8, off: i64) -> i64
199func nx_gguf_meta_read_string_ptr(buf: *u8, off: i64) -> *u8
219func nx_gguf_meta_array_inner_type(buf: *u8, off: i64) -> i64
223func nx_gguf_meta_array_count(buf: *u8, off: i64) -> i64
227func nx_gguf_meta_array_first_elt_off(buf: *u8, off: i64) -> i64
235func nx_gguf_meta_array_advance(buf: *u8, len: i64, off: i64,
called by 1: main calls 1: nx_gguf_skip_value