code wiki / (root) / nx_zimage_weights.nx

nx_zimage_weights.nx

buildroot/runtime/nx_zimage_weights.nx

8291 B183 linesdepth 8pulls 14 transitivereach 0 importersview sourcekind tooltopic zimage
docsdependenciesstructsconstsfunctions

about

nx_zimage_weights.nx -- the LAYER-WEIGHT RESOLVER: (layer L, slot k) -> where that tensor lives. sd-server -> Nishi migration, the binding brick between the GGUF and the encoder. nx_zimage_layout DUMPS blk.0's offsets to a text file for a human to read; that is a diagnostic, not an API. The full-scale assembly needs to ask, 36 x 11 times, "where is layer L's slot k?" -- so that question becomes a function here instead of being inlined into whichever organ needs it next. SLOT ORDER IS THE ENCODER'S ARGUMENT ORDER, deliberately, so a binder can fill the per-layer pointer arrays of nx_f32_qwen_encoder_layers by looping slots with no mapping table: 0 attn_norm 1 attn_q 2 attn_k 3 attn_v 4 attn_output 5 ffn_norm 6 ffn_gate 7 ffn_up 8 ffn_down 9 attn_q_norm 10 attn_k_norm <- Qwen3 QK-norm, see below ***FINDING (2026-07-30, debt 1785449705): slots 9/10 EXIST IN ALL 36 LAYERS, and the sovereign nx_f32_qwen_layer DOES NOT CONSUME THEM.*** Their existence was not guessed -- it was FORCED by arithmetic: 36 x 9 = 324 but tensor_count = 398, and 36*11 + token_embd + output_norm = 398 EXACTLY. Running real weights through the 9-slot encoder therefore yields finite, plausible, WRONG numbers with nothing erroring. LAW: tensor_count is a checksum on your architecture understanding. FAIL-CLOSED: an unknown slot or a missing tensor returns -1 and writes NOTHING to the box. It never invents an offset -- a fabricated offset would read arbitrary bytes out of a 6.5GB file and the resulting garbage would look like a numerical bug thirty layers later. METADATA ONLY: resolves offsets/dims/types from the parsed header. No tensor is materialized, so this is cheap enough to call for every layer at startup. license_tier: ORIGINAL expect_exit: 0

dependencies 10 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_strconv.nx nx_tensor.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_placement.nx nx_gguf_load_lazy.nx nx_zimage_weights.nx

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_strconv.nxnx_tensor.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_placement.nxnx_gguf_load_lazy.nx

imported by: nobody (leaf or entry point)

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

main sys_openat_rd sys_mmap sys_read sys_close nx_gguf_parse nx_le_read_u32 nx_le_read_u64 nx_le_read_u32 ↻ _gguf_skip_value nx_le_read_u64 ↻ nx_le_read_u32 ↻ _gguf_skip_value ↻ sys_mmap ↻ zw_resolve sys_mmap ↻ zw_slot_suffix zw_blk_name sys_mmap ↻ nx_strconv_format_i64 nx_gguf_find_tensor nx_gguf_tensor_at nx_gguf_name_equals nx_gguf_tensor_at ↻ sys_openat_wr nx_strconv_format_i64 ↻ sys_write

structs

none

consts

37const ZW_MAGIC_201326592: i64 = 201326592
38const ZW_MAGIC_1024: i64 = 1024
40const ZW_NSLOTS: i64 = 11

functions

43func zw_blk_name(out: *u8, n: i64, suffix: *u8, suffix_len: i64) -> i64
62func zw_slot_suffix(slot: i64, sp: *i64) -> i64
called by 1: zw_resolve
80func zw_resolve(hdr: *NxGgufHeader, layer: i64, slot: i64, box: *i64) -> i64
106func main() -> i64