Verify window: 2-4 token dense projections read an interleaved copy of the q8_1 activations (fork F4)
A one-int-a-column interleaved copy of the window's q8_1 blocks lets a warp decode each weight block once and apply it to every token with the single-column dot's own expression (the same *_q8_dot_impl calls), walking the chunks of the exact multi-column layout and adding the four virtual warps' sums in warp order, so every output is bitwise the multi-column kernel's. IQ4_XS, Q4_K, Q5_K and Q6_K projections (and the head) of 2-4 tokens use it; the copy is made from xq_ by one small kernel, so the fused HC-read producer works too. STRATA_MMVQ_IL=0 keeps native_mmvq's kernels. CUDA only (HIP keeps its kernels). mmvq_il_parity checks every case bitwise for rows 1/2/4 and the table; --bench times it. Ported by hand from Eddoursul's fork (738e166, b67a291), with the IQ3_S and Q8_0 parts and the 5-8 column widths left out. Co-authored-by: Eddoursul <git@eddoursul.win>
This commit is contained in:
1 parent
5adacbc4e1
commit
ffac97f74f
7 files changed
+632
-8
No files matched your search
+30
-8
@@ -64,6 +64,9 @@ inline bool g_lfuse_gate() { static const bool on = [] { const char* v = std::ge
|
||||
inline bool g_lfuse_pair() { static const bool on = [] { const char* v = std::getenv("STRATA_LFUSE_PAIR"); return v == nullptr || v[0] != '0'; }(); return on; }
|
||||
inline bool g_qdedup() { static const bool on = [] { const char* v = std::getenv("STRATA_VERIFY_QDEDUP"); return v != nullptr && std::atoi(v) != 0; }(); return on; }
|
||||
// S26 STRATA_QFUSE=1: activation q8_1 images written by their producers (the GDN output norm) - the same bytes
|
||||
// fork F4 (Eddoursul): 2-4 token dense projections read an interleaved copy of the q8_1 activations (bitwise the same
|
||||
// outputs); STRATA_MMVQ_IL=0 keeps native_mmvq's multi-column kernels
|
||||
inline bool g_mmvq_il() { static const bool on = [] { const char* v = std::getenv("STRATA_MMVQ_IL"); return v == nullptr || v[0] != '0'; }(); return on; }
|
||||
inline bool g_qfuse() { static const bool on = [] { const char* v = std::getenv("STRATA_QFUSE"); return v != nullptr && std::atoi(v) != 0; }(); return on; }
|
||||
#define VDBG(...) do { if (g_dbg) { std::fprintf(stderr, "verify dbg: " __VA_ARGS__); std::fflush(stderr); } } while (0)
|
||||
|
||||
@@ -476,6 +479,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState&
|
||||
lo_ = b.take<float>(T * (uint64_t) g.hc_lr); rs_ = b.take<float>(T * HC); xn_ = b.take<float>(T * HC * N);
|
||||
xq_ = b.take<uint8_t>(strata::kernels::native_q8_1_bytes(max_in, (int) T));
|
||||
sh_xq_ = b.take<uint8_t>(strata::kernels::native_q8_1_bytes(max_in, (int) T));
|
||||
xil_ = b.take<uint8_t>(strata::kernels::native_q8_1_il_bytes(max_in, 4));
|
||||
qkv_L_ = b.take<float>(nG * T * C); h_L_ = b.take<float>(nG * T * C);
|
||||
gate_L_ = b.take<float>(nG * T * HV); beta_L_ = b.take<float>(nG * T * HV);
|
||||
z_ = b.take<float>(T * ZV); y_ = b.take<float>(T * ZV); y_dummy_ = b.take<float>(T * ZV);
|
||||
@@ -825,6 +829,18 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
const bool q8_attn = gr_read_group(0, pending, inj2_, inj_); // true: xq_ holds mixed's q8_1 (STRATA_QFUSE)
|
||||
stamp(l, 1, grp);
|
||||
float* xm = mixed_ + tb * N;
|
||||
bool il_ready = false; // xil_ holds xq_'s interleaved copy (reset whenever xq_ is rewritten)
|
||||
auto mm = [&](const WeightRef* w, float* out, int n_in, int n_out) {
|
||||
if (g_mmvq_il() && strata::kernels::native_mmvq_il_supported(w->native_type, n, n_out)) {
|
||||
if (!il_ready) {
|
||||
strata::kernels::native_q8_1_interleave(xq_, xil_, n_in, n, cs);
|
||||
il_ready = true;
|
||||
}
|
||||
strata::kernels::native_mmvq_il(w->native_type, w->native_data, xq_, xil_, out, n_in, n_out, n, cs);
|
||||
} else {
|
||||
native_mmvq(w->native_type, w->native_data, xq_, out, n_in, n_out, n, cs);
|
||||
}
|
||||
};
|
||||
try {
|
||||
if (!is_qsa_layer(g, l)) {
|
||||
// ======================= GDN =======================
|
||||
@@ -845,7 +861,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
float* gate = gate_L_ + (size_t) gi * MT * HV;
|
||||
float* beta = beta_L_ + (size_t) gi * MT * HV;
|
||||
if (!q8_attn) native_quantize_q8_1(xm, xq_, (int) N, n, cs);
|
||||
native_mmvq(wqkv->native_type, wqkv->native_data, xq_, qkv + (size_t) tb * C, (int) N, (int) C, n, cs);
|
||||
mm(wqkv, qkv + (size_t) tb * C, (int) N, (int) C);
|
||||
stamp(l, 2, grp);
|
||||
if (batch_rec_) { // contiguous rows may be proposals for the same slot
|
||||
for (int t = tb; t < te;) {
|
||||
@@ -866,7 +882,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
(const float*) wsa->data, gate + (size_t) tb * HV, beta + (size_t) tb * HV, (int) N, (int) HV,
|
||||
n, cs);
|
||||
stamp(l, 4, grp);
|
||||
native_mmvq(wg->native_type, wg->native_data, xq_, z_ + (size_t) tb * ZV, (int) N, (int) ZV, n, cs);
|
||||
mm(wg, z_ + (size_t) tb * ZV, (int) N, (int) ZV);
|
||||
stamp(l, 5, grp);
|
||||
// the recurrence from the untouched state over tokens [0, te); outputs only for this group's
|
||||
if (batch_rec_) { // each slot's recurrence over its own proposed-token group
|
||||
@@ -887,7 +903,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
// STRATA_QFUSE: done above by gdn_step_norm_multi - but a batch's per-slot recurrence passes it no q8_1
|
||||
// destination (#1139: the out-projection read stale bytes), so that case quantizes here as without it
|
||||
if (!g_qfuse() || batch_rec_) native_quantize_q8_1(y_ + (size_t) tb * ZV, xq_, (int) ZV, n, cs);
|
||||
native_mmvq(wout->native_type, wout->native_data, xq_, bo_ + tb * N, (int) ZV, (int) N, n, cs);
|
||||
il_ready = false;
|
||||
mm(wout, bo_ + tb * N, (int) ZV, (int) N);
|
||||
} else {
|
||||
// ======================= QSA =======================
|
||||
const int64_t qi = qsa_idx[(size_t) l];
|
||||
@@ -924,8 +941,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
else for (int t = tb; t < te; ++t)
|
||||
bf16_gemv_fp32_mmvf(mixed_ + t * N, (const uint16_t*) wik->data, idx_raw + t * ID, (int) N, (int) ID, cs);
|
||||
stamp(l, 7, grp);
|
||||
native_mmvq(wk->native_type, wk->native_data, xq_, kcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD), n, cs);
|
||||
native_mmvq(wv->native_type, wv->native_data, xq_, vcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD), n, cs);
|
||||
mm(wk, kcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD));
|
||||
mm(wv, vcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD));
|
||||
if (qb) norm_rope(kcur_ + tb * NKV * HD, wkn, (int) (n * NKV), (int) HD, pos_k + tb * NKV);
|
||||
else for (int t = tb; t < te; ++t) norm_rope(kcur_ + t * NKV * HD, wkn, (int) NKV, (int) HD, pos_ + t * NH);
|
||||
if (st.kv_rot) { // K and V rotated before they are stored (kv_q4.hpp)
|
||||
@@ -1004,8 +1021,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
}
|
||||
}
|
||||
stamp(l, 9, grp);
|
||||
native_mmvq(wq->native_type, wq->native_data, xq_, qfull_ + tb * NH * 2 * HD, (int) N, (int) (NH * 2 * HD),
|
||||
n, cs);
|
||||
mm(wq, qfull_ + tb * NH * 2 * HD, (int) N, (int) (NH * 2 * HD));
|
||||
if (qb) {
|
||||
if (fuse_nr) { // the q/gate split reads q straight out of the q|gate rows (stride 2 * HD)
|
||||
native_qsa_rms_norm_rope(qfull_ + tb * NH * 2 * HD, (int) (2 * HD), (const float*) wqn->data,
|
||||
@@ -1086,7 +1102,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
}
|
||||
stamp(l, 14, grp);
|
||||
native_quantize_q8_1(attn32_ + tb * NH * HD, xq_, (int) (NH * HD), n, cs);
|
||||
native_mmvq(wo->native_type, wo->native_data, xq_, bo_ + tb * N, (int) (NH * HD), (int) N, n, cs);
|
||||
il_ready = false;
|
||||
mm(wo, bo_ + tb * N, (int) (NH * HD), (int) N);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
err = "verify layer " + std::to_string(l) + ": " + e.what();
|
||||
@@ -1416,6 +1433,11 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
if (head_ != nullptr && head_->loaded()) {
|
||||
try {
|
||||
native_quantize_q8_1(head_mixed_, xq_, (int) N, T, cs);
|
||||
if (g_mmvq_il() && strata::kernels::native_mmvq_il_supported(head_->type(), (int) T, (int) n_vocab_)) {
|
||||
strata::kernels::native_q8_1_interleave(xq_, xil_, (int) N, (int) T, cs);
|
||||
strata::kernels::native_mmvq_il(head_->type(), head_->weights(), xq_, xil_, head_logits_, (int) N,
|
||||
(int) n_vocab_, (int) T, cs);
|
||||
} else
|
||||
native_mmvq(head_->type(), head_->weights(), xq_, head_logits_, (int) N, (int) n_vocab_, T, cs);
|
||||
} catch (const std::exception& e) {
|
||||
err = std::string("verify head: ") + e.what();
|
||||
|
||||
Reference in new issue
Block a user