From fd81df6972b656fbfd480be8cb16c4438384d1ff Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 26 Oct 2026 16:16:28 +0100 Subject: [PATCH] DeepSeek engine (AMD): the matrix-core attention on by default for the chunked prompt fast_attn_enabled() was opt-in (DS4_FAST_ATTN=1); with the prompt chunk at 1024 it is worth far more than when it was gated: measured on 4x R9700, 2.25 bpw, 8K code prompts, three warm prompts a load, the same ids (5705e1164a) -- without it 1159 / 1180 / 1195 ppts (median 1180) with it 1327 / 1354 / 1360 ppts (median 1354, +14.7%) and after this commit the un-enved default reads 1314 / 1357 / 1369 (median 1357), i.e. identical to setting the flag, so a deployment no longer needs any environment at all. The QK/PV sums are the matrix cores' order, which the owner already approved for the prefill; the decode path keeps the scalar kernels. DS4_FAST_ATTN=0 turns it off (it is a no-op on CUDA, whose dispatch is not compiled). --- src/dsv41/ds4_kernels.cu | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu index 7656f33a..a0b7c38a 100644 --- a/src/dsv41/ds4_kernels.cu +++ b/src/dsv41/ds4_kernels.cu @@ -1998,13 +1998,15 @@ bool split_enabled() { }(); return on; } -// DS4_FAST_ATTN=1: the chunked prompt's packed-KV attention on the matrix cores (sparse_attn_wmma_kernel). Opt-in: the -// QK/PV sums are the matrix cores' order, so the outputs differ from the scalar kernel's in the last places (the owner -// approved the trade for the prefill; the decode path stays on the scalar kernels). +// The chunked prompt's packed-KV attention on the matrix cores (sparse_attn_wmma_kernel). ON by default: measured on +// 4x R9700, 2.25 bpw, 8K code prompts, warm medians of three a load -- 1180 ppts without it, 1354 with it (+14.7%), +// the same ids (5705e1164a). The QK/PV sums are the matrix cores' order, so the last places differ from the scalar +// kernel's and the owner approved that trade for the prefill; the decode path stays on the scalar kernels. +// DS4_FAST_ATTN=0 turns it off. bool fast_attn_enabled() { static const bool on = [] { const char* e = std::getenv("DS4_FAST_ATTN"); - return e != nullptr && std::atoi(e) != 0; + return e != nullptr ? std::atoi(e) != 0 : true; }(); return on; }