Metal: Fix flash_attn_ext assertion by applying consistent has_kvpad logic #17294
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.
Description:
This PR resolves an assertion failure in
ggml_metal_op_flash_attn_extthat occurs when thehas_kvpadvariable evaluates tofalse.Root Cause
I observed an inconsistency in how the
has_kvpadvariable is determined withinggml-metal-ops.cpp.In one section of the file (around line 1980), the logic was intentionally hard-coded to
true, likely as a temporary fix:However, later in the file (around line 2156), the original (and now inconsistent) logic was still being used:
Command:
./llama-simple -m ~/Library/Caches/llama.cpp/ggml-org_gemma-3-1b-it-GGUF_gemma-3-1b-it-Q4_K_M.ggufThis inconsistency was causing the following assertion to fail in my case, as the code was hitting the un-patched
elseblock: