Feature/vulkan fa large buffer#181
Open
Yvi71 wants to merge 12 commits into
Open
Conversation
The legacy memory pool (ggml_cuda_pool_leg) retains peak-sized allocations permanently. For quantized KV flash attention, the f16 dequant temp buffers (K_f16, V_f16) stay allocated in the pool after use, consuming more VRAM than the KV compression saves. This causes quantized KV (q8_0, q4_0) to OOM before f16 at equivalent context lengths on HIP/ROCm where VMM is unavailable. Root cause: ggml_cuda_pool_leg::free() stores buffers in buffer_pool[] for reuse and never calls cudaFree. On CUDA with VMM the OS can reclaim unused virtual memory. On HIP without VMM (all consumer RDNA 3/4 GPUs), the pool permanently consumes peak VRAM. Fix: on HIP, allocate f16 temp buffers with cudaMalloc and free with cudaFree (via RAII wrapper) instead of the pool. Memory is released after the FA kernel completes via cudaStreamSynchronize. Trade-off: one cudaStreamSynchronize per FA call (~5% overhead at 32K). Impact: CUDA/Metal unaffected (#ifdef GGML_USE_HIP only). Confirmed: gfx1100 (RX 7900 XT), gfx1201 (RX 9070 XT) Fixes: ggml-org#22107
hip: bypass memory pool for FA f16 temp buffers
…o feature/vulkan-turboquant-kv-cache
* vulkan: fast path for walsh-hadamard transform * disable for intel due to segfault
…o feature/vulkan-turboquant-kv-cache
…o feature/vulkan-turboquant-kv-cache
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
This PR fixes a crash/abort in the Vulkan backend when utilizing large context sequence lengths (or high parallel slot counts) where the required intermediate
split_kbuffer or model inputs exceed the GPU'smaxStorageBufferRange(capped at 4GB on AMD discrete GPUs like the RX 6800).Although the scheduler's
supports_opalready correctly allows tensors larger thanmaxStorageBufferRangewhenshader_64b_indexingis enabled, the Flash Attention implementation (ggml_vk_flash_attn) was still hard-aborting on preallocation size limits and did not select the 64-bit indexing pipeline variants at runtime.This change:
max_buffer_sizeinstead ofmaxStorageBufferRangeif the device supportsshader_64b_indexing.pipeline_flash_attn_split_k_reduce).Additional information
maxStorageBufferRangelimit by leveraging the existing 64-bit indexing pipeline variants already compiled in the Vulkan backend.Requirements