Merge branch 'f-ling32-prefill6' into f-ling32-int

This commit is contained in:
Niko1221 committed 2026-12-02 22:07:14 +01:00
commit 3b2a88a5bb
2 files changed
+20 -5

No files matched your search

+8 -3
View File
@@ -470,8 +470,8 @@ struct Ling32Engine::StageCtx {
if (o.mla_hipx && (o.latent == LatentFmt::F32 || o.latent == LatentFmt::F16X2) && gpu::mla_exph_ok(c.nope, c.rope, c.vhead, c.kv_lora)) {
hx_ws_bytes = gpu::mla_exph_workspace_bytes(static_cast<int>(N), c.H, o.mla_hipx_slab);
if (!cu(cudaMalloc(&hx_ws, hx_ws_bytes), "cudaMalloc (expanded MLA workspace)", err)) return false;
hx_wk.assign(c.n_layers, nullptr);
hx_wv.assign(c.n_layers, nullptr);
hx_wk.assign(c.n_layers + 1, nullptr); // + the MTP layer (index n_layers): its prefill chunks take the expanded form too (the NVIDIA build_mla_expanded does the same)
hx_wv.assign(c.n_layers + 1, nullptr);
const size_t nw = static_cast<size_t>(c.H) * c.nope * c.kv_lora, nv = static_cast<size_t>(c.H) * c.vhead * c.kv_lora;
for (int il = layer_first; il < layer_last; ++il) {
if (!c.is_mla(il)) continue;
@@ -479,6 +479,11 @@ struct Ling32Engine::StageCtx {
gpu::mla_exph_convert_weights(m.layers[il].mla.wk_b, nw, hx_wk[il], st);
gpu::mla_exph_convert_weights(m.layers[il].mla.wv_b, nv, hx_wv[il], st);
}
if (m.mtp.loaded && layer_last == c.n_layers) {
if (!cu(cudaMalloc(reinterpret_cast<void**>(&hx_wk[c.n_layers]), nw * 2), "cudaMalloc (wk16, MTP)", err) || !cu(cudaMalloc(reinterpret_cast<void**>(&hx_wv[c.n_layers]), nv * 2), "cudaMalloc (wv16, MTP)", err)) return false;
gpu::mla_exph_convert_weights(m.mtp.layer.mla.wk_b, nw, hx_wk[c.n_layers], st);
gpu::mla_exph_convert_weights(m.mtp.layer.mla.wv_b, nv, hx_wv[c.n_layers], st);
}
cudaStreamSynchronize(st);
}
#else
@@ -728,7 +733,7 @@ struct Ling32Engine::StageCtx {
if (E.opt.age_recent > 0)
gpu::mla_prep_old(ckv, W, M.kva_ln, cache2[il], d_pos, N, c.nope, c.rope, c.kv_lora, c.rope_theta, c.eps, E.opt.max_ctx, E.opt.emul_lat, E.opt.emul_pe, E.opt.rope_fp32, st, mm_mpos_on ? d_mpos : nullptr, d_rdelta);
#if defined(STRATA_USE_HIP)
if (hx_ws && N > E.opt.kda_seq_max_n && il < c.n_layers && hx_wk[il] && (E.opt.latent == LatentFmt::F32 || E.opt.latent == LatentFmt::F16X2) && E.opt.age_recent == 0 && !mm_mpos_on) { // expanded-form WMMA kernel: replaces qabs, the attention kernel and mla_out
if (hx_ws && N > E.opt.kda_seq_max_n && il <= c.n_layers && hx_wk[il] && (E.opt.latent == LatentFmt::F32 || E.opt.latent == LatentFmt::F16X2) && E.opt.age_recent == 0 && !mm_mpos_on) { // expanded-form WMMA kernel: replaces qabs, the attention kernel and mla_out
gpu::mla_exph_prefill(q, cache[il], E.opt.latent == LatentFmt::F16X2 ? 2 * W : W, E.opt.latent == LatentFmt::F16X2 ? 3 : 0, hx_wk[il], hx_wv[il], gate, av, N, H, pos0, 1.0f / std::sqrt(static_cast<float>(c.nope + c.rope)), hx_ws, hx_ws_bytes, E.opt.mla_hipx_slab, st);
mark(L_MLA_ATT);
Act o = make_act(av, N, H * c.vhead, false, 0);
+12 -2
View File
@@ -253,7 +253,12 @@ int default_prefill_chunk(int device) {
cudaGetLastError();
int chunk = gib >= 70.0 ? 4096 : gib >= 30.0 ? 2048 : 1024; // measured on the PRO 6000: 4096 prefills ~5 % faster than 2048 (the expert weights are streamed once per chunk) at twice the activation memory
#if defined(STRATA_USE_HIP)
chunk = std::min(chunk, 1024); // AMD: 1024 (the gfx12 2048 default is its own commit, pending the decode A/B)
// gfx12 (R9700): 2048 (the wide expert tiles of the WMMA kernels fill from about 32 pairs per expert, i.e. from 2048 tokens: 4K prefill 918 -> 1,084 tok/s, 16K 918 -> 1,095, bit-identical; the
// planner takes the 1.8 GiB of activations from the expert pool: decode -4 % in a short measurement, --chunk 1024 gives it back). Other AMD cards (gfx11 iGPUs) stay at 1024: not measured.
{
const bool g12 = std::strncmp(dp.gcnArchName, "gfx12", 5) == 0;
chunk = std::min(chunk, g12 ? 2048 : 1024);
}
#endif
return chunk;
}
@@ -1711,7 +1716,12 @@ int main(int argc, char** argv) {
else if (a == "--stop") { if (o.stop.size() == 2 && o.stop[0] == 156895) o.stop.clear(); o.stop.push_back(std::atoi(nx().c_str())); }
else { std::fprintf(stderr, "strata-ling32: unknown option %s\n", a.c_str()); return 2; }
}
if (o.chunk == 0) o.chunk = default_prefill_chunk(o.device);
if (o.chunk == 0) {
o.chunk = default_prefill_chunk(o.device);
// a card budget below 30 GiB (--vram-budget-gib) is a small card for the planner: the 2048 chunk would take its activations out of an already small pool (R9700 capped to 10 GiB, tier C: 4K prefill
// 121 -> 84 tok/s with chunk 2048), so the chunk follows the budget as it follows the memory of a real small card
if (o.vram_budget_gib > 0 && o.vram_budget_gib < 30.0 && o.chunk > 1024) o.chunk = 1024;
}
if (o.mla_prefill_kernel < 0) o.mla_prefill_kernel = default_mla_prefill_kernel(o.device);
if (!o.mla_prefill_set && o.mla_prefill_kernel == 2 && !o.mla_expanded) { // NVIDIA sm_80+ (the tensor-core MLA is the default there): the expanded-form MLA for prefill chunks of 1024+ tokens (3.4x fewer flop; not bit-identical to the absorbed form, inside the golden bands)
const char* ev = std::getenv("STRATA_L32_MLA_EXPANDED"); // =0: back to the absorbed form without a rebuild