nx_qwen_blk0_types.nx source
↩ module page · 85 lines · 3604 B
1// nx_qwen_blk0_types.nx -- dump the ggml_type + dims of every blk.0 weight of the real Q4_K_M Qwen.
2//
3// Grounds the integer-layer plan: Q4_K_M mixes quant types per tensor, and our integer linear
4// (nx_q4k_linear) only handles Q4_K (12). This says which blk.0 weights are integer-able (Q4_K=12) vs
5// need the f32 path (Q6_K=14 / F32=0). Metadata parse only (bounded 96MB prefix; tensor infos are at the
6// file start), so no 1.1GB data read. -> /tmp/qwen_blk0_types.txt
7// license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_tier.nx"
10import "nx_le.nx"
11import "nx_strconv.nx"
12import "nx_tensor.nx"
13import "nx_gguf.nx"
14import "nx_gguf_load.nx"
15import "nx_gguf_meta.nx"
16import "nx_placement.nx"
17import "nx_gguf_load_lazy.nx"
18
19func ty_emit(fd: i64, name: *u8, name_len: i64, ty: i64, d0: i64, d1: i64) -> i64 {
20 let line: *u8 = sys_mmap(128)
21 var lo: i64 = 0
22 var ki: i64 = 0
23 while ki < name_len { line[lo] = name[ki]; lo = lo + 1; ki = ki + 1 }
24 let tag: *u8 = " ty=" as *u8
25 var ti: i64 = 0
26 while tag[ti] != (0 as u8) { line[lo] = tag[ti]; lo = lo + 1; ti = ti + 1 }
27 let dec: *u8 = sys_mmap(32)
28 var nd: i64 = nx_strconv_format_i64(ty, dec)
29 var k: i64 = 0
30 while k < nd { line[lo] = dec[k]; lo = lo + 1; k = k + 1 }
31 let tag2: *u8 = " d0=" as *u8
32 ti = 0
33 while tag2[ti] != (0 as u8) { line[lo] = tag2[ti]; lo = lo + 1; ti = ti + 1 }
34 nd = nx_strconv_format_i64(d0, dec)
35 k = 0
36 while k < nd { line[lo] = dec[k]; lo = lo + 1; k = k + 1 }
37 let tag3: *u8 = " d1=" as *u8
38 ti = 0
39 while tag3[ti] != (0 as u8) { line[lo] = tag3[ti]; lo = lo + 1; ti = ti + 1 }
40 nd = nx_strconv_format_i64(d1, dec)
41 k = 0
42 while k < nd { line[lo] = dec[k]; lo = lo + 1; k = k + 1 }
43 line[lo] = 0x0A; lo = lo + 1
44 return sys_write(fd, line, lo)
45}
46
47func ty_dump(fd: i64, hdr: *NxGgufHeader, name: *u8, name_len: i64) -> i64 {
48 let idx: nx_int = nx_gguf_find_tensor(hdr, name, name_len)
49 if idx < 0 { return ty_emit(fd, name, name_len, 0 - 1, 0 - 1, 0 - 1) }
50 let ti: *NxGgufTensorInfo = nx_gguf_tensor_at(hdr, idx)
51 return ty_emit(fd, name, name_len, ti.ggml_type, ti.dim_0, ti.dim_1)
52}
53
54func main() -> i64 {
55 let path: *u8 = "/home/elderwesto/nx_stage/nx_real_model.gguf" as *u8
56 let fd: i64 = sys_openat_rd(path)
57 if fd < 0 { return 30 }
58 let CAP: i64 = 100663296 // 96 MB (tensor infos are at the file start)
59 let buf: *u8 = sys_mmap(CAP)
60 var total: i64 = 0
61 var go: i64 = 1
62 while go == 1 {
63 let r: i64 = sys_read(fd, ((buf as i64) + total) as *u8, CAP - total)
64 if r <= 0 { go = 0 } else { total = total + r; if total >= CAP { go = 0 } }
65 }
66 sys_close(fd)
67 if total < 1000000 { return 31 }
68 let hdr: *NxGgufHeader = sys_mmap(NX_GGUF_HDR_BYTES) as *NxGgufHeader
69 if nx_gguf_parse(buf, total, hdr) != NX_GGUF_OK { return 40 }
70
71 let ofd: i64 = sys_openat_wr("/tmp/qwen_blk0_types.txt" as *u8, 0x1a4)
72 if ofd < 0 { return 50 }
73 ty_dump(ofd, hdr, "token_embd.weight" as *u8, 17)
74 ty_dump(ofd, hdr, "blk.0.attn_norm.weight" as *u8, 22)
75 ty_dump(ofd, hdr, "blk.0.attn_q.weight" as *u8, 19)
76 ty_dump(ofd, hdr, "blk.0.attn_k.weight" as *u8, 19)
77 ty_dump(ofd, hdr, "blk.0.attn_v.weight" as *u8, 19)
78 ty_dump(ofd, hdr, "blk.0.attn_output.weight" as *u8, 24)
79 ty_dump(ofd, hdr, "blk.0.ffn_norm.weight" as *u8, 21)
80 ty_dump(ofd, hdr, "blk.0.ffn_gate.weight" as *u8, 21)
81 ty_dump(ofd, hdr, "blk.0.ffn_up.weight" as *u8, 19)
82 ty_dump(ofd, hdr, "blk.0.ffn_down.weight" as *u8, 21)
83 sys_close(ofd)
84 return 0
85}