char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
7992aa7c8
char/aliceai-t5-moe
1#include "gguf-model-data.h" 2 3#include <cstdio> 4 5#define TEST_ASSERT (cond ,msg ) \ 6 do { \ 7 if (!(cond)) { \ 8 fprintf(stderr, "FAIL: %s (line %d): %s\n", #cond, __LINE__, msg); \ 9 return 1; \ 10 } \ 11 } while (0) 12 13int main () { 14fprintf (stderr ,"=== test-gguf-model-data ===\n" ); 15 16// Fetch Qwen3-0.6B Q8_0 metadata 17auto result = gguf_fetch_model_meta ("ggml-org/Qwen3-0.6B-GGUF" ,"Q8_0" ); 18 19if (!result .has_value ()) { 20fprintf (stderr ,"SKIP: could not fetch model metadata (no network or HTTP disabled)\n" ); 21return 0 ; 22 } 23 24const auto & model = result .value (); 25 26fprintf (stderr ,"Architecture: %s\n" ,model .architecture .c_str ()); 27fprintf (stderr ,"n_embd: %u\n" ,model .n_embd ); 28fprintf (stderr ,"n_ff: %u\n" ,model .n_ff ); 29fprintf (stderr ,"n_vocab: %u\n" ,model .n_vocab ); 30fprintf (stderr ,"n_layer: %u\n" ,model .n_layer ); 31fprintf (stderr ,"n_head: %u\n" ,model .n_head ); 32fprintf (stderr ,"n_head_kv: %u\n" ,model .n_head_kv ); 33fprintf (stderr ,"n_expert: %u\n" ,model .n_expert ); 34fprintf (stderr ,"n_embd_head_k: %u\n" ,model .n_embd_head_k ); 35fprintf (stderr ,"n_embd_head_v: %u\n" ,model .n_embd_head_v ); 36fprintf (stderr ,"tensors: %zu\n" ,model .tensors .size ()); 37 38// Verify architecture 39TEST_ASSERT (model .architecture == "qwen3" ,"expected architecture 'qwen3'" ); 40 41// Verify key dimensions (Qwen3-0.6B) 42TEST_ASSERT (model .n_layer == 28 ,"expected n_layer == 28" ); 43TEST_ASSERT (model .n_embd == 1024 ,"expected n_embd == 1024" ); 44TEST_ASSERT (model .n_head == 16 ,"expected n_head == 16" ); 45TEST_ASSERT (model .n_head_kv == 8 ,"expected n_head_kv == 8" ); 46TEST_ASSERT (model .n_expert == 0 ,"expected n_expert == 0 (not MoE)" ); 47TEST_ASSERT (model .n_vocab == 151936 ,"expected n_vocab == 151936" ); 48 49// Verify tensor count 50TEST_ASSERT (model .tensors .size ()== 311 ,"expected tensor count == 311" ); 51 52// Verify known tensor names exist 53bool found_attn_q = false; 54bool found_token_embd = false; 55bool found_output_norm = false; 56for (const auto & t :model .tensors ) { 57if (t .name == "blk.0.attn_q.weight" ) { 58found_attn_q = true; 59 } 60if (t .name == "token_embd.weight" ) { 61found_token_embd = true; 62 } 63if (t .name == "output_norm.weight" ) { 64found_output_norm = true; 65 } 66 } 67TEST_ASSERT (found_attn_q ,"expected tensor 'blk.0.attn_q.weight'" ); 68TEST_ASSERT (found_token_embd ,"expected tensor 'token_embd.weight'" ); 69TEST_ASSERT (found_output_norm ,"expected tensor 'output_norm.weight'" ); 70 71// Verify token_embd.weight shape 72for (const auto & t :model .tensors ) { 73if (t .name == "token_embd.weight" ) { 74TEST_ASSERT (t .ne [0 ]== 1024 ,"expected token_embd.weight ne[0] == 1024" ); 75TEST_ASSERT (t .n_dims == 2 ,"expected token_embd.weight to be 2D" ); 76break ; 77 } 78 } 79 80// Test that second call uses cache (just call again, it should work) 81auto result2 = gguf_fetch_model_meta ("ggml-org/Qwen3-0.6B-GGUF" ,"Q8_0" ); 82TEST_ASSERT (result2 .has_value (),"cached fetch should succeed" ); 83TEST_ASSERT (result2 -> tensors .size ()== model .tensors .size (),"cached result should match" ); 84 85// Test a split MoE model without specifying quant (should default to Q8_0) 86auto result3 = gguf_fetch_model_meta ("ggml-org/GLM-4.6V-GGUF" ); 87if (!result3 .has_value ()) { 88fprintf (stderr ,"SKIP: could not fetch GLM-4.6V metadata (no network?)\n" ); 89return 0 ; 90 } 91const auto & model3 = result3 .value (); 92 93fprintf (stderr ,"Architecture: %s\n" ,model3 .architecture .c_str ()); 94fprintf (stderr ,"n_embd: %u\n" ,model3 .n_embd ); 95fprintf (stderr ,"n_ff: %u\n" ,model3 .n_ff ); 96fprintf (stderr ,"n_vocab: %u\n" ,model3 .n_vocab ); 97fprintf (stderr ,"n_layer: %u\n" ,model3 .n_layer ); 98fprintf (stderr ,"n_head: %u\n" ,model3 .n_head ); 99fprintf (stderr ,"n_head_kv: %u\n" ,model3 .n_head_kv ); 100fprintf (stderr ,"n_expert: %u\n" ,model3 .n_expert ); 101fprintf (stderr ,"n_embd_head_k: %u\n" ,model3 .n_embd_head_k ); 102fprintf (stderr ,"n_embd_head_v: %u\n" ,model3 .n_embd_head_v ); 103fprintf (stderr ,"tensors: %zu\n" ,model3 .tensors .size ()); 104 105// Verify architecture 106TEST_ASSERT (model3 .architecture == "glm4moe" ,"expected architecture 'glm4moe'" ); 107 108// Verify key dimensions (GLM-4.6V) 109TEST_ASSERT (model3 .n_layer == 46 ,"expected n_layer == 46" ); 110TEST_ASSERT (model3 .n_embd == 4096 ,"expected n_embd == 4096" ); 111TEST_ASSERT (model3 .n_head == 96 ,"expected n_head == 96" ); 112TEST_ASSERT (model3 .n_head_kv == 8 ,"expected n_head_kv == 8" ); 113TEST_ASSERT (model3 .n_expert == 128 ,"expected n_expert == 128 (MoE)" ); 114TEST_ASSERT (model3 .n_vocab == 151552 ,"expected n_vocab == 151552" ); 115 116// Verify tensor count 117TEST_ASSERT (model3 .tensors .size ()== 780 ,"expected tensor count == 780" ); 118 119// Test a hybrid-attention model with array-valued head counts 120auto result4 = gguf_fetch_model_meta ("ggml-org/Step-3.5-Flash-GGUF" ,"Q4_K" ); 121if (!result4 .has_value ()) { 122fprintf (stderr ,"FAIL: could not fetch Step-3.5-Flash metadata\n" ); 123return 1 ; 124 } 125const auto & model4 = result4 .value (); 126 127fprintf (stderr ,"Architecture: %s\n" ,model4 .architecture .c_str ()); 128fprintf (stderr ,"n_embd: %u\n" ,model4 .n_embd ); 129fprintf (stderr ,"n_ff: %u\n" ,model4 .n_ff ); 130fprintf (stderr ,"n_vocab: %u\n" ,model4 .n_vocab ); 131fprintf (stderr ,"n_layer: %u\n" ,model4 .n_layer ); 132fprintf (stderr ,"n_head: %u\n" ,model4 .n_head ); 133fprintf (stderr ,"n_head_kv: %u\n" ,model4 .n_head_kv ); 134fprintf (stderr ,"n_expert: %u\n" ,model4 .n_expert ); 135fprintf (stderr ,"n_embd_head_k: %u\n" ,model4 .n_embd_head_k ); 136fprintf (stderr ,"n_embd_head_v: %u\n" ,model4 .n_embd_head_v ); 137fprintf (stderr ,"tensors: %zu\n" ,model4 .tensors .size ()); 138 139TEST_ASSERT (model4 .architecture == "step35" ,"expected architecture 'step35'" ); 140 141TEST_ASSERT (model4 .n_layer == 45 ,"expected n_layer == 45" ); 142TEST_ASSERT (model4 .n_embd == 4096 ,"expected n_embd == 4096" ); 143TEST_ASSERT (model4 .n_ff == 11264 ,"expected n_ff == 11264" ); 144TEST_ASSERT (model4 .n_head == 64 ,"expected n_head == 64 (first element of per-layer array)" ); 145TEST_ASSERT (model4 .n_head_kv == 8 ,"expected n_head_kv == 8 (first element of per-layer array)" ); 146TEST_ASSERT (model4 .n_expert == 288 ,"expected n_expert == 288" ); 147TEST_ASSERT (model4 .n_embd_head_k == 128 ,"expected n_embd_head_k == 128" ); 148TEST_ASSERT (model4 .n_embd_head_v == 128 ,"expected n_embd_head_v == 128" ); 149TEST_ASSERT (model4 .n_vocab == 128896 ,"expected n_vocab == 128896" ); 150TEST_ASSERT (model4 .tensors .size ()== 754 ,"expected tensor count == 754" ); 151 152fprintf (stderr ,"=== ALL TESTS PASSED ===\n" ); 153return 0 ; 154}