reference implementation for deterministic creation of model files
| 605 | |
| 606 | // reference implementation for deterministic creation of model files |
| 607 | void quantize_row_q8_0_reference(const float * restrict x, block_q8_0 * restrict y, int k) { |
| 608 | assert(k % QK8_0 == 0); |
| 609 | const int nb = k / QK8_0; |
| 610 | |
| 611 | for (int i = 0; i < nb; i++) { |
| 612 | float amax = 0.0f; // absolute max |
| 613 | |
| 614 | for (int j = 0; j < QK8_0; j++) { |
| 615 | const float v = x[i*QK8_0 + j]; |
| 616 | amax = MAX(amax, fabsf(v)); |
| 617 | } |
| 618 | |
| 619 | const float d = amax / ((1 << 7) - 1); |
| 620 | const float id = d ? 1.0f/d : 0.0f; |
| 621 | |
| 622 | y[i].d = GGML_FP32_TO_FP16(d); |
| 623 | |
| 624 | for (int j = 0; j < QK8_0; ++j) { |
| 625 | const float x0 = x[i*QK8_0 + j]*id; |
| 626 | |
| 627 | y[i].qs[j] = roundf(x0); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | void quantize_row_q8_0(const float * restrict x, void * restrict vy, int k) { |
| 633 | assert(QK8_0 == 32); |
no outgoing calls
no test coverage detected