metal : fix MiniCPM3 crash with automatic flash attention - #28599
Open
wyanzhao wants to merge 2 commits into
Open
metal : fix MiniCPM3 crash with automatic flash attention#28599wyanzhao wants to merge 2 commits into
wyanzhao wants to merge 2 commits into
Conversation
wyanzhao
marked this pull request as ready for review
September 8, 2026 10:09
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
MiniCPM3-4B uses head dimensions
(dk, dv) = (96, 64). Metal'ssupports_oponly checksdk, so-fa autoselects the missingkernel_flash_attn_ext_vec_f16_dk96_dv64kernel and crashes.Fixes #28602.
Check the full head-size pair so automatic FA selection falls back to ordinary attention. Both vec dispatch paths use the same helper to check their supported pairs.
The regression tests query
supports_opwithout executing the graph: a normal(96, 64)test would dispatch a missing kernel on the baseline and crash the test process. The positive cases also check that supported pairs remain available.Tested on M5 Max: baseline
64e9bceb2c3a856efed96feda784a50947049febcrashes with SIGSEGV; the patch generates normally. With a 32-token budget and the prompt below, patched FA auto and both FA off controls produce identical text. All 4832 FA numerical tests, 5 admission checks and the default CPUci/run.shpassed. The new(96, 64)admission test fails with the baseline library.Reproduce with MiniCPM3-4B
Use
minicpm3-4b-q4_k_m.gguffrom openbmb/MiniCPM3-4B-GGUF:./build/bin/llama-cli -m minicpm3-4b-q4_k_m.gguf \ -ngl 99 -fa auto -ctk f16 -ctv f16 -c 512 -b 128 -ub 128 \ -n 32 --seed 1234 --temp 0 -st -p '请用一句话介绍北京。' --offlineRepeat with
-fa offfor the control.Run the FA tests with:
cmake --build build --target test-backend-ops -j 8 ./build/bin/test-backend-ops test -b MTL0 -o FLASH_ATTN_EXTRequirements