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).
This commit is contained in:
Niko1221 committed 2026-10-26 16:16:28 +01:00
1 parent 0f66c316ee
commit fd81df6972
1 file changed
+6 -4
+6 -4
View File
@@ -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;
}