Skip to content

vulkan : check combined K+V f16 scratch size in FA dequant path - #30487

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
nisbenz:vulkan-fa-dequant-kv-buffer-limit
Nov 5, 2026
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
nisbenz:vulkan-fa-dequant-kv-buffer-limit

Conversation

@nisbenz

@nisbenz nisbenz commented Oct 14, 2026

Copy link
Copy Markdown

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 against maxStorageBufferRange. 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_kv conditions, checked against both max_buffer_size and max_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 maxStorageBufferRange for 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

  • Before: crash with the same ErrorOutOfDeviceMemory as the issue.
  • After: passes (falls back to the quantized path).
  • Tested on AMD Radeon RX 6750 XT (RADV, Mesa 26.2.4), limits forced down with the env vars above. The bug is not vendor-specific: it triggers on any device once f16 K+V exceeds max_buffer_size / max_memory_allocation_size.

Requirements

@nisbenz
nisbenz requested a review from a team as a code owner October 14, 2026 01:41
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Oct 14, 2026
@0cc4m

0cc4m commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

This is valid, but should not be needed anymore after #30665

@0cc4m

0cc4m commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Can you rebase this? #30665 will take longer to merge, so this can be merged in the meantime.

@nisbenz
nisbenz force-pushed the vulkan-fa-dequant-kv-buffer-limit branch from 9bb6388 to c4b3e91 Compare November 2, 2026 15:30
@nisbenz

nisbenz commented Nov 2, 2026

Copy link
Copy Markdown
Author

Rebased onto current master.

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 5, 2026
@ggerganov
ggerganov merged commit 3b83d12 into ggml-org:master Nov 5, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vulkan: FA quantized-KV dequant scratch can exceed maxBufferSize at long context

3 participants