iq_kernels: decode each IQ weight part once for every column and entry
iq_mmvq, native_gu_kernel and native_down_kernel called the format's dot once per column (or group entry), re-reading the weight words and redoing the grid lookups and sign unpacking each time. Each dot is now split into load (weight side) and apply (activation side, same integer chain and float expression), as native_mmvq.cu's multi-column traits are: the dense kernel takes 1, 2, 4 or 8 columns per pass (8 at a time past 8), the grouped ones 4 entries per pass (~48 registers; the default verify window, --spec 4 with the split off, fits in one pass). Every column keeps the same calls, lane stride, summation order and warp_sum, so results are bitwise equal to the old kernels, which STRATA_OLD_IQ_MMVQ=1 (or iq_set_old_kernels) keeps for A/B timing. Tests: iq_multi_parity (ctest, GPU, synthetic, no model) checks old vs new bitwise for every format, ncols 1..8 and 11, groups of 0..11 entries; --bench times both. iq_parity (real rows from tools/iq_fixture.py) now runs the dot for 1 to 8 columns and requires every column of a multi-column call to equal a one-column call on it bitwise (exact layout, the default). native_expert_parity runs the GPU expert with both the decode-once and the per-entry kernels on real blobs and requires the same bits.
This commit is contained in:
1 parent
abde6fc8c9
commit
45f93fc5ee
6 files changed
+854
-36
No files matched your search
@@ -4,7 +4,8 @@
|
||||
//
|
||||
// (a) float reference: ggml's own dequantizer (`to_float`) and a float SwiGLU expert, (b) the CPU path
|
||||
// (ggml-cpu vec_dot with its quantized activations), (c) the GPU path (`native_expert_grouped`, q8_1
|
||||
// activations). (b) and (c) each differ from (a) by their activation rounding only (a few 1e-3 relative).
|
||||
// activations). (b) and (c) each differ from (a) by their activation rounding only (a few 1e-3 relative). (c) runs
|
||||
// twice, with the kernels that decode a weight part once for all entries and with the per-entry ones: bitwise equal.
|
||||
#include "strata/artifact/gguf_reader.hpp"
|
||||
#include "strata/kernels/cpu/native_expert.hpp"
|
||||
#include "strata/kernels/cpu/expert.hpp"
|
||||
@@ -276,6 +277,18 @@ int main(int argc, char** argv) {
|
||||
strata::kernels::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, 1, NT, dxq, dscr, dout, s);
|
||||
cudaStreamSynchronize(s);
|
||||
cudaMemcpy(got_g.data(), dout, got_g.size() * 4, cudaMemcpyDeviceToHost);
|
||||
{ // the kernels that decode a weight part once for the NT entries, bitwise vs the per-entry ones
|
||||
std::vector<float> old_g(got_g.size());
|
||||
const bool was = strata::kernels::iq_old_kernels();
|
||||
strata::kernels::iq_set_old_kernels(!was);
|
||||
strata::kernels::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, 1, NT, dxq, dscr, dout, s);
|
||||
strata::kernels::iq_set_old_kernels(was);
|
||||
cudaStreamSynchronize(s);
|
||||
cudaMemcpy(old_g.data(), dout, old_g.size() * 4, cudaMemcpyDeviceToHost);
|
||||
const bool same = std::memcmp(old_g.data(), got_g.data(), got_g.size() * 4) == 0;
|
||||
std::printf(" gpu decode-once vs per-entry kernels: %s\n", same ? "bitwise equal" : "MISMATCH");
|
||||
if (!same) ++failures;
|
||||
}
|
||||
cudaFree(dblob); cudaFree(dx); cudaFree(dxq); cudaFree(dscr); cudaFree(dout); cudaFree(dptr);
|
||||
cudaFree(dstart); cudaFree(dn); cudaFree(ddst); cudaFree(dtok);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user