code wiki / (root) / nx_f32_llm_live_dims_test.nx

nx_f32_llm_live_dims_test.nx source

↩ module page · 62 lines · 2421 B

1// nx_f32_llm_live_dims_test.nx -- LIVE FIRE on the real Qwen2.5-0.5B-Instruct. 2// 3// Reads /tmp/nx_real_model.gguf (~491 MB, Apache 2.0) and verifies 4// nx_f32_llm_read_dims_from_gguf correctly derives Qwen2.5-0.5B-Instruct 5// dimensions from the real GGUF metadata. 6// 7// Expected dims (from Qwen2.5-0.5B-Instruct config.json, public): 8// n_layers = 24 9// hidden_dim = 896 10// n_heads = 14 11// n_kv_heads = 2 (GQA: 7x grouping) 12// head_dim = 64 (hidden_dim / n_heads = 896 / 14 = 64) 13// ffn_dim = 4864 14// vocab_size = 151936 15 16import "nx_syscalls.nx" 17import "nx_tier.nx" 18import "nx_gguf.nx" 19import "nx_gguf_load.nx" 20import "nx_gguf_meta.nx" 21import "nx_f32_llm.nx" 22import "nx_f32_llm_read_dims.nx" 23 24func main() -> i64 { 25 // Path: /tmp/nx_real_model.gguf 26 let path: *u8 = sys_mmap(64) 27 path[0]=0x2F as u8; path[1]=0x74 as u8; path[2]=0x6D as u8; path[3]=0x70 as u8 28 path[4]=0x2F as u8; path[5]=0x6E as u8; path[6]=0x78 as u8; path[7]=0x5F as u8 29 path[8]=0x72 as u8; path[9]=0x65 as u8; path[10]=0x61 as u8; path[11]=0x6C as u8 30 path[12]=0x5F as u8; path[13]=0x6D as u8; path[14]=0x6F as u8; path[15]=0x64 as u8 31 path[16]=0x65 as u8; path[17]=0x6C as u8; path[18]=0x2E as u8 32 path[19]=0x67 as u8; path[20]=0x67 as u8; path[21]=0x75 as u8; path[22]=0x66 as u8 33 path[23]=0 as u8 34 35 // Read the file. 36 let len_out: *i64 = sys_mmap(8) as *i64 37 let buf: *u8 = sys_read_file(path, len_out) 38 if buf == (0 as *u8) { return 10 } 39 if len_out[0] < 1000 { return 11 } 40 41 // Parse header. 42 let hdr: *NxGgufHeader = sys_mmap(NX_GGUF_HDR_BYTES) as *NxGgufHeader 43 let v_p: nx_int = nx_gguf_parse(buf, len_out[0], hdr) 44 if v_p != NX_GGUF_OK { return 20 + v_p } 45 46 // Read dims from metadata + embed shape. 47 let model: *NxF32LlamaModel = nx_f32_llama_model_alloc() 48 let out_err: *i64 = sys_mmap(8) as *i64 49 let v: nx_int = nx_f32_llm_read_dims_from_gguf(buf, len_out[0], hdr, model, out_err) 50 if v != NX_FLD_OK { return 30 + v } 51 52 // Verify against Qwen2.5-0.5B-Instruct public spec. 53 if model.n_layers != 24 { return 50 } 54 if model.hidden_dim != 896 { return 51 } 55 if model.n_heads != 14 { return 52 } 56 if model.n_kv_heads != 2 { return 53 } 57 if model.head_dim != 64 { return 54 } 58 if model.ffn_dim != 4864 { return 55 } 59 if model.vocab_size != 151936 { return 56 } 60 61 return 0 62}