mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
qwen35: give MMQ's row-id table the margin llama.cpp's kernels read past its end
The prompt path's MMQ call takes `ident`, the identity row-id table, allocated with exactly ne = chunk * 8 ints (2048 * 8 * 4 = 64 KB at the default chunk). llama.cpp's mul_mat_q (third_party/strata-ggml/ggml/src/ggml-cuda/mmq.cuh) copies ids_dst[col_low + jt * J + j] for a whole J-column tile before it compares the tile with the expert's rows, and mul_mat_q_stream_k_fixup does the same for every tile up to roundup(max_rows, J) from an expert's first row, which can be the table's last; J goes up to 128. The Flash-Next prompt path already sizes its tables for this (mmq_ids_margin.hpp: roundup(max_rows, 128) + 128 entries, prefill.cpp mmq_ids_rows, PR #5108, where an exact table ending a 2 MiB page faulted on a long prompt). The Qwen3.6 engine did not: the table now takes mmq_ids_table_rows(ne, T) entries (an expert takes at most one row per token, so max_rows <= T = the chunk) and the identity is written over all of them, as there. compute-sanitizer on a table of the same exact size in the one-layer test of the Qwen3.6 fused kernels (z440, RTX A4000, CUDA 12.9, z440-20261111-2224-d478): 311 invalid __global__ reads of size 4 in mul_mat_q<Q8_0, 96, false>, 29 to 57+ bytes after a 65,536-byte allocation, an illegal memory access in the test when that table ended a cudaMalloc chunk. The engine's MMQ path never faulted in the runs so far (the bytes after the table belonged to another allocation); this removes the possibility. No other change. The same change asd7f7d9677on f-q36-identpad-main (a branch from main5f0ae5b55); applied by hand here because the surrounding lines differ on this branch.
This commit is contained in:
1 parent
afaaa77378
commit
a041fd038c
1 file changed
+11
-2
@@ -26,6 +26,7 @@
|
||||
#include "strata/prefill/gemm.hpp"
|
||||
#include "strata/prefill/moe_fused.hpp"
|
||||
#include "strata/prefill/moe_fused_q36.hpp"
|
||||
#include "strata/prefill/mmq_ids_margin.hpp"
|
||||
#include "strata/prefill/moe_mmq.hpp"
|
||||
#include "strata/qwen35/engine.hpp"
|
||||
#include "strata/qwen35/sampling.hpp"
|
||||
@@ -1435,9 +1436,17 @@ struct Engine {
|
||||
if (use_mmq) {
|
||||
const int64_t ne = (int64_t) T * Kp;
|
||||
mctx = std::make_unique<MMQ::Context>();
|
||||
ident = dalloc_t<int32_t>((size_t) ne);
|
||||
// The row table (ids) is read past its end by llama.cpp's MMQ: mul_mat_q copies ids_dst[col_low + jt*J + j] for a whole J-column tile before it
|
||||
// compares the tile with the expert's rows, and its stream-k fixup does the same for every tile up to roundup(max_rows, J) from an expert's first row,
|
||||
// which can be the table's last (mmq.cuh; J goes to 128). mmq_ids_table_rows adds roundup(max_rows, 128) + 128 entries, max_rows <= T (an expert takes at
|
||||
// most one row per token): the margin the Flash-Next prompt path already uses (prefill.cpp mmq_ids_rows, PR #5108). An exact table of ne ints (64 KB at the
|
||||
// default chunk) was read past its end: compute-sanitizer on the same size in the Qwen3.6 one-layer test (z440-20261111-2224-d478), 311 invalid reads of size 4
|
||||
// in mul_mat_q<Q8_0, 96>, 29 to 57+ bytes after a 65,536-byte allocation. The identity is written over the whole table, as there.
|
||||
const int64_t ids_rows = (int64_t) MMQ::mmq_ids_table_rows((uint64_t) ne, (uint64_t) T);
|
||||
if (ids_rows <= 0) { std::fprintf(stderr, "strata-q36: the MMQ row table does not fit\n"); std::exit(1); }
|
||||
ident = dalloc_t<int32_t>((size_t) ids_rows);
|
||||
CK(cudaDeviceSynchronize()); // ident's cudaMemset (legacy stream) before the iota on the non-blocking stream
|
||||
MMQ::iota(ident, ne, st);
|
||||
MMQ::iota(ident, ids_rows, st);
|
||||
CK(cudaMalloc(&mq_x, MMQ::q8_bytes(ne, g.n_embd)));
|
||||
CK(cudaMalloc(&mq_hq, MMQ::q8_bytes(ne, g.n_ff)));
|
||||
mq_gu = dalloc((size_t) ne * 2 * FF);
|
||||
|
||||
Reference in new issue
Block a user