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

Function gemv_quantized

engine/src/core/layer.cpp:169–201  ·  view source on GitHub ↗

< threads per row for the row-split GEMVs. MEASURED, NOT ASSUMED, AND 64 IS NOT BETTER.** `dense_pass.exe` drives the same split kernels at threads_per_row 64 and reports 248.5 GB/s, so matching it looked like free performance. It is not: TPR=64 gives 11.75 tok/s against 32's 11.99 with experts, and 20.19 against 20.26 without - identical inside noise and marginally worse on both. That is also

Source from the content-addressed store, hash-verified

167// `x80` and `xq8k` are the two quantized images of the SAME activation; a caller produces both once and this
168/// picks. Producing only the one it thinks it needs is how the assumption gets baked in again.
169bool gemv_quantized(const WeightRef& w, const Planes& p, const strata::kernels::SForm& f, const uint8_t* x80, const uint8_t* xq8k, float* y, int64_t n_in, int64_t n_out, const std::string& name, void* stream, std::string& err, const float* x_f32 = nullptr, bool x_q8_1_ready = false) {
170 using namespace strata::kernels;
171 if (w.native_data) {
172 if (!x_f32 || !w.native_q8_1 || !stream || n_in != w.ne0 || n_out != w.ne1) {
173 err = name + ": native projection requires matching FP32 input and session scratch";
174 return false;
175 }
176 try {
177 // Plan v0.3 P3: a caller whose previous native projection quantized the SAME x into the shared
178 // scratch, with no native projection in between, passes x_q8_1_ready and the quantize is skipped.
179 if (!x_q8_1_ready) native_quantize_q8_1(x_f32, w.native_q8_1, (int) n_in, 1, stream);
180 native_mmvq(w.native_type, w.native_data, w.native_q8_1, y,
181 (int) n_in, (int) n_out, 1, stream);
182 } catch (const std::exception& error) {
183 err = name + ": " + error.what();
184 return false;
185 }
186 return true;
187 }
188 if ((w.code_bits == 2 || !w.wants_q8k()) ? !x80 : !xq8k) {
189 err = name + ": missing canonical quantized activation";
190 return false;
191 }
192 if (w.code_bits == 2) {
193// S2 carries no offset plane and no SForm: its attributes are fixed (2 bits, group 64, bias -1), which
194// is why `s2_gemv_q8` takes neither.
195if (w.has_offset || p.offset != nullptr) { err = name + ": an S2 form must have no offset plane"; return false; } if (w.group_elems != 64 || w.code_bias != -1) { err = name + ": an S2 form must be group 64 with bias -1, this one is group " + std::to_string(w.group_elems) + " with bias " + std::to_string(w.code_bias); return false; } s2_gemv_q8(x80, p.codes, p.scales, y, n_in, n_out, TPR, stream); return true; }
196// **A LEGACY 4/8-BIT FORM WANTS Q8_0, NOT Q8_K, AND `code_bits` CANNOT TELL YOU WHICH.** This used to be
197// `code_bits == 2 ? Q8_0 : Q8_K`, which is CORRECT ONLY BY LUCK: every legacy tensor in this pack apart
198// from `ffn_down_shexp` is Q2_0, whose attributes happen to be S2's. Q5_0 and Q5_K are both 8-bit with
199// bias -16 and differ only in `has_offset`; IQ4_NL and IQ4_XS differ in NOTHING the S-form carries. The
200// kind therefore comes from the manifest's `source_type`, through the index (LEDGER L54/L55).
201if (!w.wants_q8k()) { s_gemv_q8_0_split(x80, p.codes, p.scales, p.offset, y, n_in, n_out, f, stream); return true; } s_gemv_q8k_split(xq8k, p.codes, p.scales, p.offset, y, n_in, n_out, f, stream); return true;}}
202// namespace
203void layer_set_native_bf16(bool enabled) { native_bf16_projections = enabled; }
204void layer_set_native_flash_attn_short(bool enabled) { native_flash_attn_short = enabled; }

Callers 3

gdn_layerFunction · 0.70
qsa_layerFunction · 0.70
lm_headFunction · 0.70

Calls 7

wants_q8kMethod · 0.80
native_quantize_q8_1Function · 0.50
native_mmvqFunction · 0.50
to_stringFunction · 0.50
s2_gemv_q8Function · 0.50
s_gemv_q8_0_splitFunction · 0.50
s_gemv_q8k_splitFunction · 0.50

Tested by

no test coverage detected