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

Function q4_0_ref

engine/src/quant/act_ref.cpp:120–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;
122
123 assert(k % qk == 0);
124
125 const int nb = k / qk;
126
127 for (int i = 0; i < nb; i++) {
128 float amax = 0.0f; // absolute max
129 float max = 0.0f;
130
131 for (int j = 0; j < qk; j++) {
132 const float v = x[i*qk + j];
133 if (amax < fabsf(v)) {
134 amax = fabsf(v);
135 max = v;
136 }
137 }
138
139 const float d = max / -8;
140 const float id = d ? 1.0f/d : 0.0f;
141
142 y[i].d = fp32_to_fp16(d);
143
144 for (int j = 0; j < qk/2; ++j) {
145 const float x0 = x[i*qk + 0 + j]*id;
146 const float x1 = x[i*qk + qk/2 + j]*id;
147
148 const uint8_t xi0 = MIN(15, (int8_t)(x0 + 8.5f));
149 const uint8_t xi1 = MIN(15, (int8_t)(x1 + 8.5f));
150
151 y[i].qs[j] = xi0;
152 y[i].qs[j] |= xi1 << 4;
153 }
154 }
155}
156
157} // namespace
158

Callers 1

quantize_q4_0_refFunction · 0.85

Calls 1

fp32_to_fp16Function · 0.85

Tested by

no test coverage detected