Repository navigation
vulkan: indexed-bias flash attention on every FA KV type, and on the coopmat1 path - #26
Open
Oxsilaris06 wants to merge 2 commits into
Conversation
…q8_0, q4_1, q5_x, iq4_nl, bf16, f32), test covers them
The indexed-bias kernel was limited to the scalar shader, which caps at about 6 TFLOPS on RDNA4 and makes prefill fall off with context depth. The bias is now added while the mask tile is loaded in flash_attn_cm1.comp, matching the scalar kernel's f16 rounding, and a KV_ROWS variant of the coopmat1 shader reads K/V through the row list. Inactive list entries keep the mask so they stay masked. BF16 K with row lists and f16 accumulation keep the scalar path.
Oxsilaris06
force-pushed
the
inkling-indexed-bias-coopmat
branch
from
November 21, 2026 23:25
b680664 to
d38e73d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to ggml-org#32740 (compact/indexed bias for
FLASH_ATTN_EXT), targeting its branch. Two commits on top of ff91e4f.The measurements below were taken with ggml-org#32740 merged on top of master together with ggml-org#32735 (SCALE on non-contiguous src) and ggml-org#32669 (
.scaletensors). The two commits rebased on ff91e4f alone pass the same indexed-bias test (224 cases). Measured on an RX 9070 XT (RDNA4, RADV, KHR_coopmat),model
IsValorum/Inkling-2-Mini-Abliterated-APEX-I-MiniPlus-V2.1-GGUF(
inkling2_loop, 24 heads, 8 KV heads, head 128, SWA 1024, 48 layer visits).Problem
Inkling 2 adds a relative position bias to every attention score. Without ggml-org#32740 the
bias is materialized as a dense f32 tensor of
n_kv × n_ubatch × n_head, copied twice(get_rows + cont). At 131k context and ubatch 64 that is about 1.6 GB, so ubatch 512
does not fit in 16 GB and prefill is capped at about 230 tok/s.
ggml-org#32740 fixes the memory side, but on Vulkan it had two limits:
supports_opaccepted the indexed bias only with F16 K/V. With a quantized KV cache(
-ctk q4_0 -ctv q4_0, the common case on 16 GB cards) the graph fell back to thedense mask, so ubatch 512 at 131k still needed a 12.7 GB pinned host buffer and
decode dropped to 21 tok/s.
about 6 TFLOPS on this GPU, so prefill falls off quickly with context depth
(1553 tok/s at depth 0, 384 tok/s at depth 98k).
Patch 1: accept every FA KV type
The scalar FA shader already dequantizes K/V generically (
dequantize4), includingthe
_rowsvariant, so the F16-only check insupports_opwas not needed. It isremoved. The test
tests/test-flash-attn-indexed-bias.cppnow takes the KV type andloops over Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, IQ4_NL, BF16 and F32. The expected result is
computed from the quantize → dequantize round trip, so the test checks the kernel and
not the quantization error. On Vulkan the test requires support (it fails if the op
falls back).
Patch 2: coopmat1 path
flash_attn_cm1.compadds the bias while the mask tile is loaded, with the same f16rounding as the scalar kernel (
packHalf2x16(mask + bias)), so the existingall-masked block skip and mask add keep working.
KV_ROWSvariant of the coopmat1 shader (flash_attn_f32_f16_rows_cm1, f32 acc)reads K/V through the row list. With a row list, K/V are always staged through shared
memory (no direct
coopMatLoadfrom the buffer), like the sparse path.-1) skipped the maskload too, so their score was 0 instead of masked. The mask is now indexed by list
position, as in the scalar kernel.
get_fa_tuning_paramswith GQA packing andflip disabled. It falls back to scalar when the result is not coopmat1, with f16
accumulation, or with BF16 K and a row list (the BF16 coopmat1 shader has no
KV_ROWSvariant).Tests
test-flash-attn-indexed-bias(224 cases: 8 KV types × 1/7/65 queries × rows on/off × widths 64/128, Vulkan0 and Vulkan1)test-backend-ops -o FLASH_ATTN_EXT -b Vulkan0test-backend-opsSCALE, MUL_MAT_ID (after patch 1)Measurements (RX 9070 XT, KV q4_0, -b 2048 -ub 512)
llama-bench,
pp512 @ depth:GGML_VK_PERF_LOGGER, global-attentionFLASH_ATTN_EXTat depth 98k: 102.8 ms percall at 6.0 TFLOPS before, about 18 TFLOPS after.
llama-server, 184 320 context, one prompt,
cache_prompt: false:Whole-model comparison against the dense-bias build at 131k, ubatch 64:
prefill 227 → 1112 tok/s at 12.8k tokens, decode unchanged (46.6 → 47.2 tok/s),
compute buffer 1.6 GB → 578 MB, VRAM 15.0 → 14.0 GB. At 184k: VRAM 14.6 GB,
566 MB GTT, KV 1.62 GB, compute buffer 734 MB.
Long-context recall (retrieve line 7 of a 70k / 141k / 179k token list): exact at all
three lengths. Short quality checks (reasoning, Rust code compiled and tested,
French prose, 3-bullet instruction) pass, decode 47.5 tok/s.
Not covered
f16accpath keep the scalar indexed-bias kernel.double_block_rowsand AMD proprietary driverq_in_regsbranches are not exercised by these runs.Host staging buffer (finding, not changed here)
The ~398 MiB
Vulkan_Hostcompute buffer at 131k (566 MiB at 184k, which is also the GTT usage seen) is the CPU-filled inputs:attn_inp_rel_pos(I32, n_kv × n_ubatch, 268 MB at 131k) plus the f16 mask (134 MB). The bias table has 1025 bins, so I16 indices would halve the first tensor, and deriving the bin from query/key positions on the GPU would remove it.