mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
New files (replacements, same interfaces):
engine/src/quant/x86/dot_avx2_clean.cpp table + six _opt kernels + three x4 kernels, bit-identical to the plain kernels of the TU
engine/src/quant/x86/act_avx512_clean.cpp AVX-512 Q8_0 / Q8_1 / Q8_K quantisers, byte-identical to the Avx2 contract
engine/src/kernels/cpu/kq_dots_avx2.{hpp,cpp} Q4_K / Q5_1 / Q8_0 multi-token dots, bit-identical per token to the single-token Avx2 dots
Float orders were found by black-box probing of the current kernels (tests/clean_p2/probe_*.cpp, model_*.cpp), then
confirmed on random rows. Tests: dot_avx2_verify, act_avx512_verify (needs AVX-512), kq_dots_avx2_test, plus the probes,
a manual build script for the quant layer and Windows (MSVC) drivers.
49 lines
2.4 KiB
C++
49 lines
2.4 KiB
C++
// probe_mins: layout of the integer min terms of the Avx2 Q4_K / Q5_K dots. Item j (0..7) = the min m_j of sub-block j with bsums[2j] = v and every
|
|
// product zero: the contribution is -dmin*da*m_j*v. Two items in one integer lane give -fl(Dm*float(M1+M2)), different lanes -(fl(Dm*M1)+fl(Dm*M2)).
|
|
#include "probe_core.hpp"
|
|
|
|
int main(int argc, char** argv) {
|
|
const std::string name = argc > 1 ? argv[1] : "q4_K";
|
|
const int trials = argc > 2 ? atoi(argv[2]) : 200;
|
|
ProbeType* t = find_probe_type(name);
|
|
const DotKernel* k = dot_kernel(t->type, Arith::Avx2, Isa::Avx2);
|
|
std::mt19937_64 rng(3);
|
|
auto setitem = [&](ProbeRow& r, int j, int& M) {
|
|
int m = 1 + (int)(rng() % 63);
|
|
r.set_sc6(r.wb(0) + 4, j, m, true);
|
|
int v = (int)(rng() % 4001) - 2000;
|
|
if (v == 0) v = 9;
|
|
const int16_t s = (int16_t)v;
|
|
std::memcpy(r.ab(0) + 260 + 2 * (2 * j), &s, 2);
|
|
M = m * v;
|
|
};
|
|
int same[8][8] = {}, diff[8][8] = {}, none[8][8] = {};
|
|
for (int a = 0; a < 8; ++a)
|
|
for (int b = a + 1; b < 8; ++b)
|
|
for (int tr = 0; tr < trials; ++tr) {
|
|
ProbeRow r(*t, 1);
|
|
put_half(r.wb(0), rand_half(rng));
|
|
put_half(r.wb(0) + 2, rand_half(rng));
|
|
const float da = std::ldexp(0.5f + (float)(rng() % 1000) / 1000.0f, (int)(rng() % 7) - 9);
|
|
std::memcpy(r.ab(0), &da, 4);
|
|
int M1, M2;
|
|
setitem(r, a, M1);
|
|
setitem(r, b, M2);
|
|
float o = 0;
|
|
k->fn(256, &o, r.w.data(), r.a.data());
|
|
const float Dm = fp16_to_fp32(get_half(r.wb(0) + 2)) * da;
|
|
const float hs = -(Dm * (float)(M1 + M2)), hd = -(Dm * (float)M1) + -(Dm * (float)M2);
|
|
const bool es = std::memcmp(&o, &hs, 4) == 0, ed = std::memcmp(&o, &hd, 4) == 0;
|
|
if (es && !ed) ++same[a][b]; else if (ed && !es) ++diff[a][b]; else if (!es && !ed) ++none[a][b];
|
|
}
|
|
printf("%s: pairs of min items (j1,j2): S = same lane, D = different lane, ? = matched neither at least once\n", name.c_str());
|
|
for (int a = 0; a < 8; ++a) {
|
|
for (int b = 0; b < 8; ++b) {
|
|
if (b <= a) { printf(" ."); continue; }
|
|
printf(" %c", none[a][b] ? '?' : (same[a][b] && !diff[a][b]) ? 'S' : (diff[a][b] && !same[a][b]) ? 'D' : '-');
|
|
}
|
|
printf("\n");
|
|
}
|
|
return 0;
|
|
}
|