nx_zimage_gguf_probe.nx source
↩ module page · 59 lines · 2456 B
1// nx_zimage_gguf_probe.nx -- read the REAL Z-Image text-encoder GGUF structure, sovereignly.
2//
3// sd-server -> Nishi migration, the real-weight bridge: proves our sovereign GGUF reader (`nx_gguf_parse`
4// + `nx_gguf_find_tensor` + `nx_gguf_tensor_at`, the same path `nx_real_gguf_test` gates on a 491MB Qwen)
5// reads the ACTUAL Z-Image model weights -- `Z-Image_Qwen_3_4b-Q6_K.gguf` -- so real tensors can flow into
6// our gated f32 organs (-> dequant `nx_q6_k_to_f32` -> the DiT/attention path). Bounded PREFIX read: the
7// GGUF header + tensor-info + KV-metadata live at the FRONT of the file; tensor DATA (the multi-GB bulk) is
8// lazy and not needed to enumerate/locate tensors, so we read only a 192MB prefix instead of the 2.5GB file.
9//
10// Pass: file opens, >=1KB read, GGUF v3, tensor_count sane, and token_embd.weight is found with dim_0>0.
11// license_tier: ORIGINAL
12import "nx_syscalls.nx"
13import "nx_tier.nx"
14import "nx_le.nx"
15import "nx_strconv.nx"
16import "nx_tensor.nx"
17import "nx_gguf.nx"
18import "nx_gguf_load.nx"
19import "nx_gguf_meta.nx"
20import "nx_placement.nx"
21import "nx_gguf_load_lazy.nx"
22
23func main() -> i64 {
24 let path: *u8 = "/mnt/c/Users/elder/elder-ai-platform/models/unified/text_encoder/Z-Image_Qwen_3_4b-Q6_K.gguf" as *u8
25
26 let fd: i64 = sys_openat_rd(path)
27 if fd < 0 { return 30 }
28
29 // bounded prefix read (metadata region at the front; tensor data is lazy)
30 let CAP: i64 = 201326592 // 192 MB
31 let buf: *u8 = sys_mmap(CAP)
32 var total: i64 = 0
33 var go: i64 = 1
34 while go == 1 {
35 let r: i64 = sys_read(fd, ((buf as i64) + total) as *u8, CAP - total)
36 if r <= 0 { go = 0 } else {
37 total = total + r
38 if total >= CAP { go = 0 }
39 }
40 }
41 sys_close(fd)
42 if total < 1000 { return 31 }
43
44 // parse the GGUF header + tensor infos + metadata from the prefix
45 let hdr: *NxGgufHeader = sys_mmap(NX_GGUF_HDR_BYTES) as *NxGgufHeader
46 let vp: nx_int = nx_gguf_parse(buf, total, hdr)
47 if vp != NX_GGUF_OK { return 40 + vp }
48 if hdr.version != 3 { return 50 }
49 if hdr.tensor_count <= 0 { return 51 }
50 if hdr.tensor_count > 4096 { return 52 }
51
52 // locate a universal Qwen/llama tensor by name
53 let idx: nx_int = nx_gguf_find_tensor(hdr, "token_embd.weight" as *u8, 17)
54 if idx < 0 { return 60 }
55 let ti: *NxGgufTensorInfo = nx_gguf_tensor_at(hdr, idx)
56 if ti.dim_0 <= 0 { return 61 }
57
58 return 0
59}