MCPcopy Create free account
hub / github.com/Niko1221/Strata / q8_K_ref

Function q8_K_ref

engine/src/quant/act_ref.cpp:81–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void q8_K_ref(const float* STRATA_RESTRICT x, block_q8_K* STRATA_RESTRICT y, int64_t k) {
82 assert(k % QK_K == 0);
83 const int64_t nb = k / QK_K;
84
85 for (int i = 0; i < nb; i++) {
86
87 float max = 0;
88 float amax = 0;
89 for (int j = 0; j < QK_K; ++j) {
90 float ax = fabsf(x[j]);
91 if (ax > amax) {
92 amax = ax; max = x[j];
93 }
94 }
95 if (!amax) {
96 y[i].d = 0;
97 memset(y[i].qs, 0, QK_K);
98 x += QK_K;
99 continue;
100 }
101 //const float iscale = -128.f/max;
102 // We need this change for IQ2_XXS, else the AVX implementation becomes very awkward
103 const float iscale = -127.f/max;
104 for (int j = 0; j < QK_K; ++j) {
105 int v = nearest_int(iscale*x[j]);
106 y[i].qs[j] = MIN(127, v);
107 }
108 for (int j = 0; j < QK_K/16; ++j) {
109 int sum = 0;
110 for (int ii = 0; ii < 16; ++ii) {
111 sum += y[i].qs[j*16 + ii];
112 }
113 y[i].bsums[j] = sum;
114 }
115 y[i].d = 1/iscale;
116 x += QK_K;
117 }
118}
119
120void q4_0_ref(const float* STRATA_RESTRICT x, block_q4_0* STRATA_RESTRICT y, int64_t k) {
121 static const int qk = QK4_0;

Callers 1

quantize_q8_K_refFunction · 0.85

Calls 1

nearest_intFunction · 0.85

Tested by

no test coverage detected