code wiki / (root) / nx_genarch.nx

nx_genarch.nx

buildroot/runtime/nx_genarch.nx

5914 B151 linesdepth 7pulls 17 transitivereach 13 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_genarch.nx -- derive a DiT's architecture FROM THE MODEL FILE, so parts are hot-swappable. Operator, 2026-08-07: *"make sure that they are hot swappable with other models till we can pay to make our own model"*. Z-Image Turbo is a MIX of parts (DiT + Qwen text encoder + VAE); the right goal is not to rebuild each part but to be able to drop a different one in. A hardcoded architecture constant is the thing that prevents that. This lane has already been burned four times by assumed constants -- layer count (30, not the 36 I assumed), norm_eps, adaLN chunk order, SDPA scale -- and each was silently wrong rather than loudly wrong. ★★★★★ AN ARCHITECTURE CONSTANT IN THE CODE IS A MODEL THAT CANNOT BE SWAPPED. Everything below is read off tensor SHAPES, because this GGUF carries zero metadata KV pairs (measured: `kv 0`) -- so the shapes are the only self-description the file has. SLOTS 0 hidden D from attention.qkv.weight dim0 1 head_dim from attention.q_norm.weight length 2 n_heads qkv_width / 3 / head_dim (q,k,v equal-width; verified, not assumed) 3 qkv_width from attention.qkv.weight dim1 4 ffn_dim from feed_forward.w1.weight dim1 5 n_layers probed: layers.N until absent 6 n_refiners probed: context_refiner.N until absent 7 adaln_embed from adaLN_modulation.0.weight dim0 8 n_chunks adaLN_modulation.0.weight dim1 / D 9 out_dim from final_layer.linear.weight dim1 (= patch*patch*latent_channels) 10 x_embed_in from x_embedder.weight dim0 license_tier: ORIGINAL

dependencies 3 imports · 7 importers

nx_syscalls.nx nx_strconv.nx nx_genweights.nx nx_genarch.nx nx_gen_archprobe.nx nx_gen_modelid.nx nx_gen_pipecheck.nx nx_gen_zoo.nx nx_genblock.nx nx_genpipe.nx nx_genrole.nx

imports: nx_syscalls.nxnx_strconv.nxnx_genweights.nx

imported by: nx_gen_archprobe.nxnx_gen_modelid.nxnx_gen_pipecheck.nxnx_gen_zoo.nxnx_genblock.nxnx_genpipe.nxnx_genrole.nx

structs

none

consts

33const NX_ARCH_SLOTS: i64 = 16
34const NX_ARCH_D: i64 = 0
35const NX_ARCH_HEAD_DIM: i64 = 1
36const NX_ARCH_N_HEADS: i64 = 2
37const NX_ARCH_QKV_W: i64 = 3
38const NX_ARCH_FFN_DIM: i64 = 4
39const NX_ARCH_N_LAYERS: i64 = 5
40const NX_ARCH_N_REFINE: i64 = 6
41const NX_ARCH_ADALN_EMB:i64 = 7
42const NX_ARCH_N_CHUNKS: i64 = 8
43const NX_ARCH_OUT_DIM: i64 = 9
44const NX_ARCH_XEMB_IN: i64 = 10

functions

46func _ar_strlen(s: *u8) -> i64
called by 2: _ar_count_ar_dim
53func _ar_name(out: *u8, stack: *u8, n: i64, suffix: *u8) -> *u8
75func _ar_count(gw: *i64, stack: *u8) -> i64
87func _ar_dim(gw: *i64, name: *u8, which: i64) -> i64
97func nx_arch_probe(gw: *i64, arch: *i64) -> i64