MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

tests/test-quantize-fns.cpp:95–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95int main(int argc, char * argv[]) {
96 bool verbose = false;
97 const size_t test_size = 32 * 128;
98
99 std::string arg;
100 for (int i = 1; i < argc; i++) {
101 arg = argv[i];
102
103 if (arg == "-v") {
104 verbose = true;
105 } else {
106 fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
107 return 1;
108 }
109 }
110
111 std::vector<float> test_data(test_size);
112 std::vector<float> test_data2(test_size);
113
114 generate_data(0.0, test_data.size(), test_data.data());
115 generate_data(1.0, test_data2.size(), test_data2.data());
116
117 // Initialize GGML, ensures float conversion tables are initialized
118 struct ggml_init_params ggml_params = {
119 /* .mem_size = */ 1*1024,
120 /* .mem_buffer = */ NULL,
121 /* .no_alloc = */ true,
122 };
123 struct ggml_context * ctx = ggml_init(ggml_params);
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 ggml_type_traits_t qfns = ggml_internal_get_type_traits(type);
131
132 // deprecated - skip
133 if (qfns.blck_size == 0) {
134 continue;
135 }
136
137 printf("Testing %s\n", ggml_type_name((ggml_type) i));
138
139 if (qfns.from_float && qfns.to_float) {
140 const float total_error = total_quantization_error(qfns, test_size, test_data.data());
141 const float max_quantization_error =
142 type == GGML_TYPE_Q2_K ? MAX_QUANTIZATION_TOTAL_ERROR_2BITS :
143 type == GGML_TYPE_Q3_K ? MAX_QUANTIZATION_TOTAL_ERROR_3BITS : MAX_QUANTIZATION_TOTAL_ERROR;
144 failed = !(total_error < max_quantization_error);
145 num_failed += failed;
146 if (failed || verbose) {
147 printf("%5s absolute quantization error: %s (%f)\n", ggml_type_name(type), RESULT_STR[failed], total_error);
148 }
149
150 const float reference_error = reference_quantization_error(qfns, test_size, test_data.data());
151 failed = !(reference_error < MAX_QUANTIZATION_REFERENCE_ERROR);
152 num_failed += failed;

Callers

nothing calls this directly

Calls 13

fprintfFunction · 0.85
printfFunction · 0.85
generate_dataFunction · 0.70
total_quantization_errorFunction · 0.70
dot_product_errorFunction · 0.70
ggml_initFunction · 0.50
ggml_type_nameFunction · 0.50
ggml_freeFunction · 0.50
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected