Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

iq_multi_parity: an independent mmvq reference for the grouped expert kernels (the old-vs-new comparison was the same kernels by default)

Niko1221793ca909c134
diff --git a/sycl/src/kernels/iq_multi_parity.cpp b/sycl/src/kernels/iq_multi_parity.cpp
index 0f086958a..1b0e02d2f 100644
--- a/sycl/src/kernels/iq_multi_parity.cpp
+++ b/sycl/src/kernels/iq_multi_parity.cpp
@@ -269,6 +269,7 @@ struct Grouped {
uint8_t *dxq = nullptr, *dscr = nullptr;
float* dout = nullptr;
size_t out_floats = 0;
+ std::vector<int32_t> h_start, h_tok, h_dst; // the host copies, for reference()
Grouped(int gu, int dt, int64_t H, int64_t FF, const std::vector<int>& counts, int tokens, std::mt19937& rng) {
L = k::native_expert_layout(gu, dt, H, FF);
@@ -279,11 +280,14 @@ struct Grouped {
for (int c : counts) start.push_back(start.back() + c);
n_ent = start.back();
cap_ent = n_ent + 3;
+ h_start = start;
std::uniform_int_distribution<int> tk(0, tokens - 1);
for (int e = 0; e < n_ent; ++e) tok.push_back(tk(rng));
dst.resize(n_ent);
std::iota(dst.begin(), dst.end(), 0);
std::shuffle(dst.begin(), dst.end(), rng);
+ h_tok = tok;
+ h_dst = dst;
std::vector<unsigned long long> ptr;
for (int g = 0; g < n_groups; ++g) {
// one blob per group: gate rows | up rows (format gu, H values) | down rows (format dt, FF values)
@@ -385,6 +389,34 @@ struct Grouped {
k::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, cap_groups, cap_ent, dxq, dscr, dout, s);
k::iq_set_old_kernels(false);
}
+ // An independent reference: every entry through iq_mmvq (itself checked against a double-precision CPU reference
+ // above), one column at a time - gate and up rows against the token's q8_1 activations, SwiGLU into q8_1, the down
+ // rows against that. Not bitwise the grouped path (accumulation order), so it is compared with a tolerance.
+ std::vector<float> reference(dpct::queue_ptr s) {
+ const int64_t H = L.n_embd, FF = L.n_ff;
+ float *g = dalloc<float>(FF), *u = dalloc<float>(FF), *y = dalloc<float>(H);
+ uint8_t* hq = dalloc<uint8_t>((size_t) (FF / 32) * 36 + 64);
+ std::vector<float> out(out_floats, 0.0f);
+ std::vector<unsigned long long> ptr(n_groups);
+ ck(DPCT_CHECK_ERROR((dpct::get_current_device().queues_wait_and_throw(), dpct::get_in_order_queue())
+ .memcpy(ptr.data(), dptr, ptr.size() * 8).wait()), "ptr");
+ for (int gi = 0; gi < n_groups; ++gi) {
+ const uint8_t* blob = (const uint8_t*) ptr[gi];
+ for (int e = h_start[gi]; e < h_start[gi + 1]; ++e) {
+ const uint8_t* xq = dxq + (size_t) h_tok[e] * (H / 32) * 36;
+ k::iq_mmvq(L.gu_type, blob, xq, g, (int) H, (int) FF, 1, s);
+ k::iq_mmvq(L.gu_type, blob + L.up_off, xq, u, (int) H, (int) FF, 1, s);
+ k::native_swiglu_quantize_q8_1(g, u, hq, (int) FF, 1, s);
+ k::iq_mmvq(L.d_type, blob + L.down_off, hq, y, (int) FF, (int) H, 1, s);
+ ck(DPCT_CHECK_ERROR(s->wait()), "ref sync");
+ ck(DPCT_CHECK_ERROR((dpct::get_current_device().queues_wait_and_throw(), dpct::get_in_order_queue())
+ .memcpy(out.data() + (size_t) h_dst[e] * H, y, (size_t) H * 4).wait()), "ref out");
+ }
+ }
+ sycl::free(g, dpct::get_in_order_queue()); sycl::free(u, dpct::get_in_order_queue());
+ sycl::free(y, dpct::get_in_order_queue()); sycl::free(hq, dpct::get_in_order_queue());
+ return out;
+ }
std::vector<float> result(bool old, dpct::queue_ptr s) {
ck(DPCT_CHECK_ERROR((dpct::get_current_device().queues_wait_and_throw(), dpct::get_in_order_queue())
.memset(dout, 0xFF, out_floats * 4)
@@ -418,6 +450,22 @@ void check_grouped(int gu, int dt, int64_t H, int64_t FF, dpct::queue_ptr s,
diff += std::memcmp(&a[i], &b[i], 4) != 0;
if (i < (size_t) G.n_ent * H) { ++written; finite = finite && std::isfinite(b[i]); }
}
+ // against the independent reference: the lane kernels (the default) and the other path, rows that are written
+ {
+ const auto r = G.reference(s);
+ auto bad = [&](const std::vector<float>& v) {
+ float mx = 0;
+ for (size_t i = 0; i < (size_t) G.n_ent * H; ++i) mx = std::max(mx, std::fabs(r[i]));
+ size_t n = 0;
+ for (size_t i = 0; i < (size_t) G.n_ent * H; ++i) n += !(std::fabs(v[i] - r[i]) <= 0.05f * mx);
+ return n;
+ };
+ const size_t ba = bad(a), bb = bad(b);
+ std::printf("%-8s/%-7s %5lld x %4lld vs the mmvq reference: lane kernels %zu, other path %zu of %zu rows-values "
+ "outside 5%% of the max%s\n", name_of(gu), name_of(dt), (long long) H, (long long) FF, ba, bb,
+ (size_t) G.n_ent * H, ba || bb ? " <== FAIL" : "");
+ if (ba) ++g_fail;
+ }
const bool ok = diff == 0 && finite;
std::printf("%-8s/%-7s %5lld x %4lld native_expert_grouped, %d groups, %d entries: %s\n", name_of(gu),
name_of(dt), (long long) H, (long long) FF, G.n_groups, G.n_ent,