code wiki / (root) / nx_gguf_fixture_tiny_test.nx

nx_gguf_fixture_tiny_test.nx source

↩ module page · 71 lines · 2496 B

1// nx_gguf_fixture_tiny_test.nx -- smoke for the fixture builder. 2 3import "nx_syscalls.nx" 4import "nx_tier.nx" 5import "nx_gguf.nx" 6import "nx_model_spec.nx" 7import "nx_llm_run_v2.nx" 8import "nx_gguf_fixture_tiny.nx" 9 10func main() -> i64 { 11 // 1: verdict enum validity 12 if nx_gft_v_is_valid(NX_GFT_OK) != 1 { return 1 } 13 if nx_gft_v_is_valid(NX_GFT_ERR_PARSE) != 1 { return 2 } 14 if nx_gft_v_is_valid(NX_GFT_ERR_NULL) != 1 { return 3 } 15 if nx_gft_v_is_valid(-1) != 0 { return 4 } 16 if nx_gft_v_is_valid(NX_GFT_N) != 0 { return 5 } 17 18 // 2: build with deterministic seed 19 let b: *NxGgufFixtureBundle = nx_gft_build_tiny_llama(0xcafebabe) 20 if (b as i64) == 0 { return 6 } 21 if nx_gft_verdict(b) != NX_GFT_OK { return 7 } 22 if nx_gft_is_built(b) != 1 { return 8 } 23 24 // 3: shape fields 25 if b.vocab_size != 4 { return 9 } 26 if b.hidden_dim != 2 { return 10 } 27 if b.head_dim != 2 { return 11 } 28 if b.n_layers != 1 { return 12 } 29 if b.ffn_dim != 4 { return 13 } 30 if b.n_heads != 1 { return 14 } 31 if b.max_seq_len != 8 { return 15 } 32 33 // 4: parsed header is real (12 tensors) 34 if b.hdr.n_tensors != 12 { return 16 } 35 36 // 5: spec validates 37 if nx_model_spec_validate(b.spec) != NX_MS_OK { return 17 } 38 39 // 6: vocab-byte map roundtrip 40 if nx_gft_vocab_byte(b, 0) != 0x61 { return 18 } 41 if nx_gft_vocab_byte(b, 1) != 0x62 { return 19 } 42 if nx_gft_vocab_byte(b, 2) != 0x63 { return 20 } 43 if nx_gft_vocab_byte(b, 3) != 0x64 { return 21 } 44 if nx_gft_vocab_byte(b, 4) != -1 { return 22 } 45 if nx_gft_vocab_byte(b, -1) != -1 { return 23 } 46 47 // 7: drive a REAL transformer forward through the fixture 48 let prompt: *u8 = sys_mmap(1) 49 prompt[0] = 0x61 50 let tok: nx_int = nx_llm_generate_one_v2( 51 b.spec, b.gguf_buf, b.hdr, b.bpe, 52 prompt, 1, 53 1024, 4, 54 b.prng_state, 55 10000, 724) 56 if tok < 0 { return 24 } 57 if tok >= b.vocab_size { return 25 } 58 59 // 8: two independent builds with the same seed produce identical headers 60 let b2: *NxGgufFixtureBundle = nx_gft_build_tiny_llama(0xcafebabe) 61 if b2.hdr.n_tensors != 12 { return 26 } 62 if b2.spec.vocab_size != b.spec.vocab_size { return 27 } 63 64 // 9: null guards 65 let null_b: *NxGgufFixtureBundle = (0 as i64) as *NxGgufFixtureBundle 66 if nx_gft_verdict(null_b) != NX_GFT_ERR_NULL { return 28 } 67 if nx_gft_vocab_byte(null_b, 0) != -1 { return 29 } 68 if nx_gft_is_built(null_b) != 0 { return 30 } 69 70 return 0 71}