MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / main

Function main

subprojects/llama.cpp/tests/test-quantize-fns.cpp:101–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101int main(int argc, char * argv[]) {
102 bool verbose = false;
103 const size_t test_size = 32 * 128;
104
105 std::string arg;
106 for (int i = 1; i < argc; i++) {
107 arg = argv[i];
108
109 if (arg == "-v") {
110 verbose = true;
111 } else {
112 fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
113 return 1;
114 }
115 }
116
117 std::vector<float> test_data(test_size);
118 std::vector<float> test_data2(test_size);
119
120 generate_data(0.0, test_data.size(), test_data.data());
121 generate_data(1.0, test_data2.size(), test_data2.data());
122
123 ggml_cpu_init();
124
125 int num_failed = 0;
126 bool failed = false;
127
128 for (int i = 0; i < GGML_TYPE_COUNT; i++) {
129 ggml_type type = (ggml_type) i;
130 const auto * qfns = ggml_get_type_traits(type);
131 const auto * qfns_cpu = ggml_get_type_traits_cpu(type);
132
133 // deprecated - skip
134 if (qfns->blck_size == 0) {
135 continue;
136 }
137
138 const ggml_type ei = (ggml_type)i;
139
140 printf("Testing %s\n", ggml_type_name((ggml_type) i));
141 ggml_quantize_init(ei);
142
143 if (qfns_cpu->from_float && qfns->to_float) {
144 const float total_error = total_quantization_error(qfns, qfns_cpu, test_size, test_data.data());
145 const float max_quantization_error =
146 type == GGML_TYPE_TQ1_0 ? MAX_QUANTIZATION_TOTAL_ERROR_TERNARY :
147 type == GGML_TYPE_TQ2_0 ? MAX_QUANTIZATION_TOTAL_ERROR_TERNARY :
148 type == GGML_TYPE_Q2_K ? MAX_QUANTIZATION_TOTAL_ERROR_2BITS :
149 type == GGML_TYPE_IQ2_S ? MAX_QUANTIZATION_TOTAL_ERROR_2BITS :
150 type == GGML_TYPE_Q3_K ? MAX_QUANTIZATION_TOTAL_ERROR_3BITS :
151 type == GGML_TYPE_IQ3_S ? MAX_QUANTIZATION_TOTAL_ERROR_3BITS :
152 type == GGML_TYPE_IQ3_XXS ? MAX_QUANTIZATION_TOTAL_ERROR_3BITS_XXS : MAX_QUANTIZATION_TOTAL_ERROR;
153 failed = !(total_error < max_quantization_error);
154 num_failed += failed;
155 if (failed || verbose) {
156 printf("%5s absolute quantization error: %s (%f)\n", ggml_type_name(type), RESULT_STR[failed], total_error);
157 }
158

Callers

nothing calls this directly

Calls 11

ggml_cpu_initFunction · 0.85
ggml_get_type_traitsFunction · 0.85
ggml_get_type_traits_cpuFunction · 0.85
ggml_type_nameFunction · 0.85
ggml_quantize_initFunction · 0.85
total_quantization_errorFunction · 0.85
dot_product_errorFunction · 0.85
generate_dataFunction · 0.70
sizeMethod · 0.65
dataMethod · 0.45

Tested by

no test coverage detected