hip: VEC flash-attn for D=512 (Gemma 4) on ROCm with quantized KV#156
Open
cclecle wants to merge 1 commit into
Open
hip: VEC flash-attn for D=512 (Gemma 4) on ROCm with quantized KV#156cclecle wants to merge 1 commit into
cclecle wants to merge 1 commit into
Conversation
Extends the VEC flash-attention path to D=512 heads on HIP/ROCm,
enabling Gemma 4 27B/1B decode with quantized KV caches at long context.
Problem: the TILE path allocates an f16 temp buffer per FA call (~2 GB
at 256K context with D=512) that the legacy pool retains permanently.
With quantized KV this consumes more VRAM than the compression saves,
causing OOM. The VEC path does inline dequant with no temp buffer, so
it avoids the issue entirely.
D=512 was previously excluded from VEC because nthreads_KQ=2 exceeds
the 256-VGPR limit on RDNA4 (wave32). Set nthreads_KQ=4 for D>=512 to
halve Q register use. Decode only (ncols=1); prefill falls back to TILE.
Changes:
- fattn-vec.cuh: add ggml_cuda_flash_attn_ext_vec_case_d512<K,V>
template (ncols=1 fixed), expose DECL_FATTN_VEC_CASE_D512 macro
- fattn.cu: add FATTN_VEC_CASE_D512 dispatch for K=q8_0 + common V
types; extend can_use_vector_kernel to allow D=512 for q8_0 K decode
- fattn-vec-instance-q8_0-{f16,q8_0,bf16,turbo2/3/4_0}.cu: add
DECL_FATTN_VEC_CASE_D512 instantiations in existing per-V-type TUs
Tested: Gemma 4 31B running with q8_0 K + turbo4 V at 200K context on
RDNA4 (Radeon PRO AI 9700 XT).
Co-Authored-By: 15073640+cclecle@users.noreply.github.com
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Overview
Extends the VEC flash-attention path to D=512 heads on HIP/ROCm, enabling Gemma 4 27B decode with quantized KV caches at long context.
Problem: the TILE path allocates an f16 temp buffer per FA call (~2 GB at 256K context with D=512) that the legacy pool retains permanently. With quantized KV this consumes more VRAM than the compression saves, causing OOM. The VEC path does inline dequant with no temp buffer, so it avoids the issue entirely.
D=512 was previously excluded from VEC because nthreads_KQ=2 exceeds the 256-VGPR limit on RDNA4 (wave32). Set nthreads_KQ=4 for D>=512 to halve Q register use. Decode only (ncols=1); prefill falls back to TILE.
Co-Authored-By: 15073640+cclecle@users.noreply.github.com
Additional information
Changes:
template (ncols=1 fixed), expose DECL_FATTN_VEC_CASE_D512 macro
Requirements
Tests:
Environment: