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

Function quantize_row_q8_0_reference

ggml-quants.c:607–630  ·  view source on GitHub ↗

reference implementation for deterministic creation of model files

Source from the content-addressed store, hash-verified

605
606// reference implementation for deterministic creation of model files
607void 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
632void quantize_row_q8_0(const float * restrict x, void * restrict vy, int k) {
633 assert(QK8_0 == 32);

Callers 2

ggml_quantize_q8_0Function · 0.70
quantize_row_q8_0Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected