diff --git a/bench/models/check_qwen.cpp b/bench/models/check_qwen.cpp index 86b534c..30afc31 100644 --- a/bench/models/check_qwen.cpp +++ b/bench/models/check_qwen.cpp @@ -478,6 +478,15 @@ static bool check_imperative(const qm::gg::model& m, const Oracle& O, bool held) long_ok = l5 < batched_bound; std::printf("\n%lld-token prompt, batched vs imperative: top-5 logits maxrel %.2e %s\n", (long long)longp.size(), l5, long_ok ? "OK" : "FAIL"); + // Again with its last chunk one token (as a 513-token prompt's is), which runs + // on the decode's GEMVs. + qm::reset_cache(B); + qm::prefill_batched(B, longp, (int64_t)longp.size() - 1); + const double o5 = qm::top5_maxrel(logits_of(B).data(), imp_long.data(), B.c.VOCAB); + const bool one_ok = o5 < batched_bound; + long_ok &= one_ok; + std::printf("the same in chunks of %lld and 1: top-5 logits maxrel %.2e %s\n", + (long long)longp.size() - 1, o5, one_ok ? "OK" : "FAIL"); } const bool f16_ok = !qm::can_prefill_batched(B, (int64_t)longp.size()) || check_f16_sums(B, longp, imp_long); diff --git a/bench/models/qwen.h b/bench/models/qwen.h index a0245df..26c15fc 100644 --- a/bench/models/qwen.h +++ b/bench/models/qwen.h @@ -1180,13 +1180,23 @@ inline int64_t prefill_chunk_(Model& M, int64_t T, bool exact = false, bool last // same source rather than taking it as a parameter that could disagree. int64_t pos0 = seq_cache(M).pos; // The f16-sum GEMMs read their activation as f16 where prefill_a16 says; `a16s` - // is that copy of `a`. - const bool a16 = prefill_a16(M, exact), mmq = prefill_mmq(M, exact); + // is that copy of `a`. One row (a one-token chunk, or the last row past the + // KV-sharing line) is a decode step's product: the decode's GEMVs, which read the + // weights once at their bandwidth where a tile GEMM wastes all its rows but one + // (E2B's 20 shared layers took a quarter of a Metal pp512), and read f32. + bool a16 = false, mmq = false; + auto set_forms = [&] { + a16 = T > 1 && prefill_a16(M, exact); + mmq = T > 1 && prefill_mmq(M, exact); + }; + set_forms(); // A GEMM a run of one format, each into its columns of y. The bf16 GEMMs // write y densely, so a bf16 run is the whole projection, as every bf16 build // loads it (load_wmat). auto gemm = [&](gpu::span a, gpu::span a16s, const wmat& W, gpu::span y, int64_t n, int64_t k) { + if (T == 1) + return gemv_m(W, a, y, exact ? gpu::act_form::f32 : M.gemv_form, sp(M.scratch.act)); for (const auto& p : W.parts) { const gpu::span w = W.at(p); if (p.type != bf16_type) { @@ -1244,6 +1254,7 @@ inline int64_t prefill_chunk_(Model& M, int64_t T, bool exact = false, bool last } pos0 += T - 1; T = 1; + set_forms(); norm(x, sp(L.an), sp(P.h), sp(P.h16), false); } }