Repository navigation
vulkan : check combined K+V f16 scratch size in FA dequant path - #30487
Merged
ggerganov merged 1 commit intoNov 5, 2026
Merged
Conversation
Contributor
|
This is valid, but should not be needed anymore after #30665 |
Contributor
|
Can you rebase this? #30665 will take longer to merge, so this can be merged in the meantime. |
Fixes ggml-org#30048 Assisted-by: Claude
nisbenz
force-pushed
the
vulkan-fa-dequant-kv-buffer-limit
branch
from
November 2, 2026 15:30
9bb6388 to
c4b3e91
Compare
Author
|
Rebased onto current master. |
0cc4m
approved these changes
Nov 4, 2026
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
Fixes #30048.
The FA dequant path (
use_dequant_kv, added in #25494) dequantizes K and V to f16 into one scratch buffer (prealloc_x). The existing checks only compare K and V separately againstmaxStorageBufferRange. Nothing checks the combined K+V size against the device's max buffer / allocation size, which is what we actually allocate.With a large context and a quantized KV cache K+V in f16 can go past that limit. In the issue, at 1M context each of K and V is ~1 GiB in f16. One more batch takes K+V to 2049 MiB, over the 2 GiB limit, and allocation fails
This PR adds the combined size to the
use_dequant_kvconditions, checked against bothmax_buffer_sizeandmax_memory_allocation_size. If it does not fit, FA falls back to the existing quantized path. Normal context sizes are unchanged.Additional information
Why not
maxStorageBufferRangefor the sum: that limit is per binding, and K and V are bound separately, so each one alone is still the right check there. The failure here is the allocation of the shared buffer, so the sum has to be checked against the buffer and allocation limits. Both are checked because the scratch is one buffer backed by one allocation.Testing: reproducing the original failure needs ~1M context, so I lowered the limits instead:
GGML_VK_FORCE_MAX_BUFFER_SIZE=327680 GGML_VK_FORCE_MAX_ALLOCATION_SIZE=327680 ./build/bin/test-backend-ops -o FLASH_ATTN_EXT
ErrorOutOfDeviceMemoryas the issue.max_buffer_size/max_memory_allocation_size.Requirements