Copy-pasted from ggml.c
| 166 | |
| 167 | // Copy-pasted from ggml.c |
| 168 | static void quantize_row_q8_0_reference(const float *x, block_q8_0 *y, int k) { |
| 169 | assert(k % QK8_0 == 0); |
| 170 | const int nb = k / QK8_0; |
| 171 | |
| 172 | for (int i = 0; i < nb; i++) { |
| 173 | float amax = 0.0f; // absolute max |
| 174 | |
| 175 | for (int l = 0; l < QK8_0; l++) { |
| 176 | const float v = x[i*QK8_0 + l]; |
| 177 | amax = std::max(amax, fabsf(v)); |
| 178 | } |
| 179 | |
| 180 | const float d = amax / ((1 << 7) - 1); |
| 181 | const float id = d ? 1.0f/d : 0.0f; |
| 182 | |
| 183 | y[i].d = d; |
| 184 | |
| 185 | for (int l = 0; l < QK8_0; ++l) { |
| 186 | const float v = x[i*QK8_0 + l]*id; |
| 187 | y[i].qs[l] = roundf(v); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // Copy-pasted from ggml.c |
| 193 | static void dot_q4_q8(const int n, float* s, const void* vx, const void* vy) { |