nx_gguf_type_census_gate.nx source
↩ module page · 67 lines · 3039 B
1// nx_gguf_type_census_gate.nx -- FACTS FIRST for the dequant-debt rung (2026-07-15): enumerate every
2// tensor's ggml_type across the fleet's ggufs so coverage is driven by what models ACTUALLY ship, not
3// assumption. Prints a type histogram per file + the union; exits 0 if all files parsed.
4// expect_exit: 0 license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_tier.nx"
7import "nx_le.nx"
8import "nx_tensor.nx"
9import "nx_gguf.nx"
10
11func tc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func tc_n(v: i64) -> i64 {
13 var m: i64 = v
14 if m < 0 { tc_w("-" as *u8); m = 0 - m }
15 let t: *u8 = sys_mmap(24)
16 var k: i64 = 0
17 if m == 0 { t[0] = 48 as u8; k = 1 }
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let o: *u8 = sys_mmap(24)
20 var i: i64 = 0
21 while i < k { o[i] = t[k - 1 - i]; i = i + 1 }
22 sys_write(1, o, k)
23 return 0
24}
25
26func tc_file(path: *u8, union_hist: *i64) -> i64 {
27 let len_out: *i64 = sys_mmap(8) as *i64
28 len_out[0] = 0
29 let buf: *u8 = sys_read_file(path, len_out)
30 if (buf as i64) == 0 { tc_w(" ABSENT: " as *u8); tc_w(path); tc_w("\n" as *u8); return 0 }
31 let hdr: *NxGgufHeader = sys_mmap(NX_GGUF_HDR_BYTES) as *NxGgufHeader
32 if nx_gguf_parse(buf, len_out[0], hdr) != NX_GGUF_OK { tc_w(" PARSE FAIL: " as *u8); tc_w(path); tc_w("\n" as *u8); return 0 - 1 }
33 let hloc: *NxGgufHeader = hdr
34 let hist: *i64 = sys_mmap(64 * 8) as *i64
35 var i: i64 = 0
36 while i < hloc.tensor_count {
37 let ti: *NxGgufTensorInfo = nx_gguf_tensor_at(hloc, i)
38 let ty: i64 = ti.ggml_type
39 if ty >= 0 { if ty < 64 { hist[ty] = hist[ty] + 1; union_hist[ty] = union_hist[ty] + 1 } }
40 i = i + 1
41 }
42 tc_w(" " as *u8); tc_w(path); tc_w(": tensors=" as *u8); tc_n(hloc.tensor_count); tc_w(" types:" as *u8)
43 var ty2: i64 = 0
44 while ty2 < 64 {
45 if hist[ty2] > 0 { tc_w(" ty" as *u8); tc_n(ty2); tc_w("x" as *u8); tc_n(hist[ty2]) }
46 ty2 = ty2 + 1
47 }
48 tc_w("\n" as *u8)
49 return 1
50}
51
52func main() -> i64 {
53 tc_w("=== NX-GGUF-TYPE-CENSUS -- ggml types actually shipped in the fleet's models ===\n" as *u8)
54 let uh: *i64 = sys_mmap(64 * 8) as *i64
55 var okc: i64 = 0
56 if tc_file("/home/elderwesto/nx_stage/nx_real_model.gguf" as *u8, uh) == 1 { okc = okc + 1 }
57 if tc_file("/home/elderwesto/nx_stage/nx_15b_model.gguf" as *u8, uh) == 1 { okc = okc + 1 }
58 if tc_file("/home/elderwesto/nx_stage/nx_moe_model.gguf" as *u8, uh) == 1 { okc = okc + 1 }
59 tc_w(" UNION:" as *u8)
60 var ty: i64 = 0
61 while ty < 64 { if uh[ty] > 0 { tc_w(" ty" as *u8); tc_n(ty); tc_w("x" as *u8); tc_n(uh[ty]) } ty = ty + 1 }
62 tc_w("\n (key: 0=F32 1=F16 2=Q4_0 3=Q4_1 6=Q5_0 7=Q5_1 8=Q8_0 10=Q2_K 11=Q3_K 12=Q4_K 13=Q5_K 14=Q6_K 30=BF16)\n" as *u8)
63 tc_w("NX-GGUF-TYPE-CENSUS files=" as *u8); tc_n(okc)
64 if okc >= 3 { tc_w(" verdict=GREEN\n" as *u8); return 0 }
65 tc_w(" verdict=PARTIAL (some files absent)\n" as *u8)
66 return 0
67}