code wiki / (root) / nx_f32_llm_read_dims.nx

nx_f32_llm_read_dims.nx

buildroot/runtime/nx_f32_llm_read_dims.nx

10140 B236 linesdepth 11pulls 27 transitivereach 35 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_llm_read_dims.nx -- read model dims from GGUF metadata. Walks the GGUF metadata section to derive model dimensions and writes them into NxF32LlamaModel. Closes the "caller pre-fills dims" gap from nx_f32_llm_load_weights_from_gguf. Architecture awareness: Reads "general.architecture" string; uses it as the key prefix for "<arch>.block_count" etc. Supports qwen2, llama (Llama-2), llama (Llama-3 same key namespace), and any other arch that follows the standard <arch>.{block_count,embedding_length,...} convention. Keys read: general.architecture (string) <arch>.block_count (u32 -> n_layers) <arch>.embedding_length (u32 -> hidden_dim) <arch>.attention.head_count (u32 -> n_heads) <arch>.attention.head_count_kv (u32 -> n_kv_heads, optional; defaults to n_heads if missing -- the no-GQA case) <arch>.feed_forward_length (u32 -> ffn_dim) vocab_size derived from token_embd.weight's dim_0. head_dim = hidden_dim / n_heads. genealogy_id: gguf_v3_metadata_spec_gerganov_2024 + llama_qwen_arch_keys lineage_id: substrate_f32_llm_read_dims_v1

dependencies 6 imports · 35 importers

nx_syscalls.nx nx_tier.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_f32_llm.nx nx_f32_llm_read_dims.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_embed_gate.nx nx_f32_llm_bench_test.nx nx_f32_llm_chat_test.nx

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

imports: nx_syscalls.nxnx_tier.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_f32_llm.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_embed_gate.nxnx_f32_llm_bench_test.nxnx_f32_llm_chat_test.nxnx_f32_llm_cohere_test.nxnx_f32_llm_embed_diag_test.nxnx_f32_llm_live_dims_test.nxnx_f32_llm_live_gen_test.nxnx_f32_llm_live_load_only_test.nxnx_f32_llm_live_load_test.nxnx_f32_llm_probe.nxnx_f32_llm_read_dims_test.nxnx_f32_llm_serve.nxnx_f32_qwen_capital_gate.nxnx_llm_argmax_probe.nxnx_llm_batch_serve.nxnx_llm_diff_probe.nxnx_llm_forward_profile.nxnx_llm_france_probe.nxnx_llm_layerlens_probe.nxnx_llm_sched_gate.nxnx_lowrank_kv_real.nxnx_paged_fwd_gate.nxnx_qwen_native_gate.nxnx_qwen_wsl_timing_gate.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning_gate.nxnx_specdec_gate.nx

structs

none

consts

37const NX_FLD_OK: nx_int = 0
38const NX_FLD_ERR_NULL: nx_int = 1
39const NX_FLD_ERR_NO_ARCH: nx_int = 2
40const NX_FLD_ERR_NO_KEY: nx_int = 3
41const NX_FLD_ERR_BAD_TYPE: nx_int = 4
42const NX_FLD_ERR_NO_EMBED: nx_int = 5
43const NX_FLD_ERR_BAD_DIM: nx_int = 6
44const NX_FLD_N_VERDICTS: nx_int = 7
46const NX_GGUF_TYPE_U32: i64 = 4
47const NX_GGUF_TYPE_STR: i64 = 8

functions

49func nx_fld_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
57func _fld_concat_key(arch: *u8, arch_len: nx_int,
called by 1: _fld_read_arch_u32
77func _fld_read_arch_u32(buf: *u8, len: i64, hdr: *NxGgufHeader,
96func _fld_read_vocab_size_from_embed(hdr: *NxGgufHeader) -> i64
115func nx_f32_llm_read_dims_from_gguf(buf: *u8, len: i64, hdr: *NxGgufHeader,