Repository navigation
ggml/CUDA+HIP: Flash Attention with indexed bias - #33063
Conversation
|
The CI regressions are from the Hy4_flash commit, they're unrelated (unless it's some new one). |
| const bool scan_mask = !use_sparse && mask && mask->ne[2] == 1 && mask->ne[1]/ncols1 >= ntiles_x && | ||
| n_kv_cols % FATTN_KQ_STRIDE == 0 && (Q->ne[1] >= 1024 || Q->ne[3] > 1 || kv_rows); |
There was a problem hiding this comment.
Why is this being changed?
There was a problem hiding this comment.
Should scan_mask ever be set to true for a bias mask? It only provides a speedup if there is padding at the end that can be skipped.
Assisted-by: Codex
|
I worked on a port of the CUDA implementation of this feature onto the current master (my own branch, now closed as a duplicate of this PR) and verified it on an RTX 3060 Ti (cc 8.6). Some findings that may be useful while reviewing this PR — they are about the original implementation and the current kernels, not about this diff, which I have not built: The contract to implement is the CPU reference in The original CUDA code in the first commit of #32740 ( The head of a column in the tile kernel is The tile kernel and K/V row lists: it passes Measurements (RTX 3060 Ti, cc 8.6, Inkling 2 Mini
Happy to test a branch of this PR with EDIT: AI assisted Assisted-by: Hermes-Agent:minimax/MiniMax-M3 |
|
@JohannesGaessler aight, should be addressed now. |
|
Is this supposed to be the only remaining PR required to fix the compute buffer problem? I tried building this locally and ran the Edit: It'll be convenient for users if there were a checklist that tracks the follow-ups needed to fix the compute buffer problem (eg., backend support for FA with indexed bias). I imagine #32910 would be a good place for this. |
…R #33063 Ports pwilkin's indexed-bias FA kernels (ggml-org/llama.cpp#33063, tip a5e173111, OPEN/unmerged) into the fork, adapted for fork divergence: - no kv_rows/KV_rows anywhere: all rows plumbing dropped, mask width is K->ne[1] directly - llama-graph build_attn_mha: replaces the offload_kqv CPU-pin fallback with unconditional ggml_flash_attn_ext_add_indexed_bias; dispatch now follows the backends' supports_op - fattn.cu: removes the indexed-bias reject; selection block added (tile for hs 128, tile/vec for hs 64 without softcap; vec only when softcap==0 && Q->ne[1]==1 && K->ne[1]%FATTN_KQ_STRIDE==0) - tile/vec kernels: indexed_bias template param + bias.add at the mask site; fixup/combine/gate divisions route through fattn_normalize so a fully masked query returns 0 like the CPU backend - mma kernel: signature param only, biased ops never dispatch to it - HIP: narrower tile widths for indexed bias; F8_E4M3 register tuning dropped (fork has no F8 type); vgpr-check mangled names updated - ggml: exported ggml_validate_flash_attn_ext_indexed_bias, used by add_indexed_bias and the RPC server - tests: test_flash_attn_ext_indexed_bias adapted without kv_rows (18 cases, all pass on CPU) Verification: CPU build + 18/18 FLASH_ATTN_EXT indexed-bias backend tests pass. CUDA/HIP graft is REVIEW-ONLY - not compile-checked (no GPU toolchain in this environment).
This doesn't look like it's the KV cache. This looks like the OP offload to GPU with the model fully on CPU (see the host usage). |
I'm mostly concerned about the I'm not actually sure whether this is related to the indexed bias, but the compute buffer problem has been there since the beginning, and #32740 claimed to solve the enormous VRAM usage issue, so I expected the overall VRAM usage to drop. When I run Qwen3.6-35b-a3b on the same rig with the same flags, the compute buffer is under 300MB combined, and I intuitively thought the compute buffer of inkling2-mini should be similar. Or is it just expected to have a huge compute buffer for this model? |
|
@Davidyz please paste the results of the KV cache dumps from the logs, not the final breakdown. |
|
@pwilkin sorry about not including the info. The kv cache is actually reasonably sized (although squeezed to CPU). The Details |
|
After applying this patch from @erdincyasar, the compute buffer size dropped from 12,904 MB to 1,237 MB at |
Assisted-by: Codex
|
@rgerganov @JohannesGaessler the fixes are up. |
|
@Davidyz sure, but it's a separate PR since that's a scheduler issue. |
|
All right, this no longer has any RPC code so I guess I can merge once checks are green. |
…-bias-cuda-master Assisted-by: Codex # Conflicts: # scripts/hip/gcn-cdna-vgpr-check.py
|
Need a reapproval, the CI changes are not related. |
Overview
Implements Flash Attention with indexed bias in CUDA + HIP.
Additional information
CUDA/HIP implementation of the contract in #32740
Requirements