mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Merge main 697b6d67a into f-p4-int (the three row-id margin commits d7f7d9677, 14dd746f6, 697b6d67a)
main'sd7f7d9677(q36_engine.cu) is the same change as f-p4-q36a041fd038/afaaa7737, which this branch already carries (merge 10,1ddbb4ced): the MMQ row-id table of the Qwen3.6 engine takes mmq_ids_table_rows(ne, T) entries and the identity is written over all of them. The text on both sides is byte-equal. Two conflict hunks in src/qwen35/q36_engine.cu, both resolved to this branch's side: - the include list: this branch's (moe_fused.hpp, moe_fused_q36.hpp, and mmq_ids_margin.hpp once, in the place it already has); - the ident allocation: main's block (comment, ids_rows, ident, the identity over ids_rows) is the block this branch already has a few lines below; kept once, not twice. src/qwen35/q36_engine.cu of the merge is therefore byte-identical to this branch's before the merge: ONE table-size expression, MMQ::mmq_ids_table_rows. No margin value is chosen or changed here.14dd746f6(src/prefill/gemm.cu, the dense MMQ row-id table) and697b6d67a(src/prefill/prefill.cpp, the MTP draft step's table) come in as main has them; both merged without a conflict.
This commit is contained in:
commit
15dfa33240
2 files changed
+13
-5
No files matched your search
+7
-2
@@ -2,6 +2,7 @@
|
||||
#include "strata/prefill/gemm.hpp"
|
||||
#include "strata/kernels/dequant_bf16.hpp"
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
#include "strata/prefill/mmq_ids_margin.hpp"
|
||||
#include "strata/prefill/moe_mmq.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1294,8 +1295,12 @@ bool Gemm::native_mmq(const uint16_t* X, int type, const void* W, float* Y, int6
|
||||
if (ldy <= 0) ldy = N;
|
||||
|
||||
const auto up = [](size_t v) { return (v + 255) & ~(size_t) 255; };
|
||||
// The row table is read past its end by llama.cpp's MMQ (mul_mat_q: a whole J-column tile from the start of each tile, J up to 128; the stream-k fixup:
|
||||
// up to roundup(max_rows, J) from the expert's first row): kRows + the margin of mmq_ids_margin.hpp (max_rows <= kRows), the identity written over all of it.
|
||||
// Exact, with only the 256 bytes of the bounds after it, a tile of 112 columns on a full chunk read 384 bytes past the table, 128 past the allocation.
|
||||
const size_t ids_rows = (size_t) mmq::mmq_ids_table_rows((uint64_t) kRows, (uint64_t) kRows);
|
||||
const size_t ident_off = up(mmq::q8_bytes(kRows, kMaxK));
|
||||
const size_t bounds_off = ident_off + up((size_t) kRows * 4);
|
||||
const size_t bounds_off = ident_off + up(ids_rows * 4);
|
||||
if (!mmq_buf_) {
|
||||
if (cudaMalloc(&mmq_buf_, bounds_off + 256) != cudaSuccess) {
|
||||
cudaGetLastError();
|
||||
@@ -1303,7 +1308,7 @@ bool Gemm::native_mmq(const uint16_t* X, int type, const void* W, float* Y, int6
|
||||
return false;
|
||||
}
|
||||
mmq_ctx_ = new mmq::Context();
|
||||
mmq::iota((int32_t*) ((uint8_t*) mmq_buf_ + ident_off), kRows, stream_);
|
||||
mmq::iota((int32_t*) ((uint8_t*) mmq_buf_ + ident_off), (int64_t) ids_rows, stream_);
|
||||
std::fprintf(stderr, "prefill gemm: dense MMQ on (STRATA_DENSE_MMQ=1)\n");
|
||||
}
|
||||
void* xq = mmq_buf_;
|
||||
|
||||
@@ -2388,7 +2388,7 @@ bool Prefill::draft_kv(core::MtpDrafter& mtp, const float* R_rows, const int32_t
|
||||
static const bool f16_only = [] { const char* v = std::getenv("STRATA_MTP_BATCH_F16"); return v == nullptr || v[0] != '0'; }();
|
||||
const bool q8 = !f16_only && mmq::built() && mmq::fits(kQ8_0, Nn) && mmq::fits(kQ8_0, KV); // #420
|
||||
const uint64_t per_row = 4 * (2 * Nn + 4 * HCN + LR + HC + Nn + 2 * KV + 1) + 2 * (Nn + 2 * HCN + LR + Nn) + 64 +
|
||||
(q8 ? (uint64_t) mmq::q8_bytes(g.hc, Nn) + 4 * g.hc : 0);
|
||||
(q8 ? (uint64_t) mmq::q8_bytes(g.hc, Nn) + 8 * g.hc : 0); // (8 * hc: the row table twice, see its margin below)
|
||||
int64_t B = std::min<int64_t>(n - r0, (int64_t) (m.region_bytes / per_row) & ~(int64_t) 63);
|
||||
if (st.kv_mode == 2) // a ring: one batch's cells must not share a slot (a batch can straddle one page more)
|
||||
B = std::min<int64_t>(B, ((st.n_slots - 1) * strata::kernels::qsa_real_shapes().page_size) & ~(int64_t) 63);
|
||||
@@ -2413,7 +2413,10 @@ bool Prefill::draft_kv(core::MtpDrafter& mtp, const float* R_rows, const int32_t
|
||||
float* Vc = (float*) carve((size_t) B * KV * 4);
|
||||
int32_t* tok = (int32_t*) carve((size_t) B * 4);
|
||||
void* xq = q8 ? carve(mmq::q8_bytes(B * g.hc, Nn)) : nullptr;
|
||||
int32_t* ident = q8 ? (int32_t*) carve((size_t) B * g.hc * 4) : nullptr;
|
||||
// The row table is read past its end by llama.cpp's MMQ (a whole J-column tile from the start of each tile; the stream-k fixup up to roundup(max_rows, J)
|
||||
// from the expert's first row; J up to 128): rows + the margin of mmq_ids_margin.hpp, max_rows <= B * hc (one expert, p.n = 1), the identity over all of it.
|
||||
const uint64_t ids_rows = q8 ? mmq::mmq_ids_table_rows((uint64_t) (B * g.hc), (uint64_t) (B * g.hc)) : 0;
|
||||
int32_t* ident = q8 ? (int32_t*) carve((size_t) ids_rows * 4) : nullptr;
|
||||
int32_t* bnd = q8 ? (int32_t*) carve(16) : nullptr;
|
||||
if ((uint64_t) (q - m.region) > m.region_bytes) return decline("the batch buffers do not fit the scratch region");
|
||||
static const bool timing = std::getenv("STRATA_DRAFT_TIMING") != nullptr; // debug: where this pass's time goes
|
||||
@@ -2426,7 +2429,7 @@ bool Prefill::draft_kv(core::MtpDrafter& mtp, const float* R_rows, const int32_t
|
||||
std::vector<int32_t> tk((size_t) B);
|
||||
if (q8) {
|
||||
if (!m.mmq_ctx) m.mmq_ctx = std::make_unique<mmq::Context>();
|
||||
mmq::iota(ident, B * g.hc, m.cs);
|
||||
mmq::iota(ident, (int64_t) ids_rows, m.cs);
|
||||
}
|
||||
// y[rows, n_out] = x[rows, k] . w^T for a Q8_0 matrix: MMQ from the FP32 rows (bounds slot 0: rows, 1: rows*hc)
|
||||
auto proj = [&](const float* x, const uint16_t* x16, const void* w, float* y, int64_t rows, int64_t n_out,
|
||||
|
||||
Reference in new issue
Block a user