nx_genarch.nx
buildroot/runtime/nx_genarch.nx
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
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
| 33 | const NX_ARCH_SLOTS: i64 = 16 |
| 34 | const NX_ARCH_D: i64 = 0 |
| 35 | const NX_ARCH_HEAD_DIM: i64 = 1 |
| 36 | const NX_ARCH_N_HEADS: i64 = 2 |
| 37 | const NX_ARCH_QKV_W: i64 = 3 |
| 38 | const NX_ARCH_FFN_DIM: i64 = 4 |
| 39 | const NX_ARCH_N_LAYERS: i64 = 5 |
| 40 | const NX_ARCH_N_REFINE: i64 = 6 |
| 41 | const NX_ARCH_ADALN_EMB:i64 = 7 |
| 42 | const NX_ARCH_N_CHUNKS: i64 = 8 |
| 43 | const NX_ARCH_OUT_DIM: i64 = 9 |
| 44 | const NX_ARCH_XEMB_IN: i64 = 10 |
functions
| 46 | func _ar_strlen(s: *u8) -> i64 |
| 53 | func _ar_name(out: *u8, stack: *u8, n: i64, suffix: *u8) -> *u8 |
| 75 | func _ar_count(gw: *i64, stack: *u8) -> i64 |
| 87 | func _ar_dim(gw: *i64, name: *u8, which: i64) -> i64 |
| 97 | func nx_arch_probe(gw: *i64, arch: *i64) -> i64 |