Repository navigation
Add flash attention MMA / Tiles to support MiMo-V2.5 - #22812
Conversation
|
I ran a quick test, and this PR seems to work! Before:
After:
On a DGX Spark. |
|
I don't know if it is a quirk of the model, the IQ3_S quant, or a bug in the inference engine itself... but I did just see a strange behavior. chat history {
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "Let's try to assess how deab41ec68d81324117017a5dd10452920c5c915 would impact the model in the real world. How would this bug manifest? Here is the PR Description: \nOverview\n\nWhen adding test cases for chunked GDN, I noticed the existing test_gated_delta_net uses default Uniform[-1,1] for all inputs, and it fails at n_seq_tokens=256, CPU side produces nan and GPU side produces inf.\n\nThis PR makes two changes:\n\n Adds long sequences and tail cases.\n Updates the inputs to match the real model:\n L2-normalize q/k to match qwen35/kimi-linear.\n Initialize g from Uniform[-20, -1e-4].\n Initialize v from Uniform[-0.3, 5.0].\n Initialize β from Uniform[0, 1].\n\nAdditional information\n\n To reproduce the failure, checkout the first commit (a13c2ae) of this PR, build and run:\n\n./build/bin/test-backend-ops -o GATED_DELTA_NET\n\nExpected output:\n\n[GATED_DELTA_NET] NaN at index 51953 (CUDA0=inf CPU=-nan) GATED_DELTA_NET(type=f32,head_count=4,head_size=64,n_seq_tokens=256,n_seqs=1,v_repeat=1,permuted=0,kda=0): FAIL\n\n The ranges above are mesured on Qwen3.5-35B-A3B: g ∈ [ − 316 , 0 ) , v ∈ [ − 0.278 , 24.78 ] , β ∈ ( 0 , 1 )"
}
]
},
{
"type": "reasoning",
"summary": [],
"content": [
{
"type": "reasoning_text",
"text": "The user wants me to analyze a specific git commit (`ab41ec68d81324117017a5dd10452920c5c915`) and understand how a bug would manifest in the real world. They've provided a PR description that describes the issue. Let me look at the commit to understand the actual code changes."
}
],
"encrypted_content": ""
},
{
"type": "function_call",
"name": "exec_command",
"arguments": "{\"cmd\":\"cd /mnt/truenas/composer/workspace/llama.cpp && git log --oneline -1 ab41ec68d81324117017a5dd10452920c5c915\"}",
"call_id": "fc_r4jcDsrDQgZAV9oI1gltHnWwBr31qwJv"
},
{
"type": "function_call_output",
"call_id": "fc_r4jcDsrDQgZAV9oI1gltHnWwBr31qwJv",
"output": "Chunk ID: ebd011\nWall time: 0.0000 seconds\nProcess exited with code 128\nOriginal token count: 55\nOutput:\nfatal: ambiguous argument 'ab41ec68d81324117017a5dd10452920c5c915': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
},
{
"type": "reasoning",
"summary": [],
"content": [
{
"type": "reasoning_text",
"text": "The commit hash doesn't exist locally. Let me search for it in the git history or look for related commits about gated delta net."
}
],
"encrypted_content": ""
},
{
"type": "function_call",
"name": "exec_command",
"arguments": "{\"cmd\":\"cd /mnt/truenas/composer/workspace/llama.cpp && git log --oneline -30 --all | head -30\"}",
"call_id": "fc_LlekBI2KWg2Jfacm7QAsFS6DuOV3Ktug"
},The model did successfully provide a coherent explanation of the changes, at least the time before this run, but why did it cut off the first hex byte of the commit hash in both its reasoning and tool call? I tried this again while paying close attention, and it immediately tried to find a commit named I've never seen a model behave this way before... so it makes me suspicious. But, maybe it is nothing. |
JohannesGaessler
left a comment
There was a problem hiding this comment.
Unless you are validating that they work on all affected hardware, base the (192, 128) configs on the (256, 256) configs. Also, make the kernels immediately return with NO_DEVICE_CODE for all unused ncols2 values and adjust the host code to reflect this.
|
I only tested this on my RTX 6000 Pros, so I'll update it to follow the (256, 256) configs and make the other changes you suggest. |
|
Recompiled after the above commits, speeds are still sane: |
JohannesGaessler
left a comment
There was a problem hiding this comment.
fattn-tile.cuh still needs to have launch_fattn_tile_switch_ncols2 adjusted with an if constexpr to avoid compiling the unused ncols2 values.
|
Regarding the retrieval issue I mentioned earlier, where the model fails to copy a short string reliably, I set up a harness to reproduce the issue, then I reproduced this with both FA off and with cache off, to exclude both an FA bug and a KV cache bug from being at fault here. After that, I decided to test against the OpenRouter endpoint that Xiaomi hosts, and the issue reproduced there. So, this could be a fundamental issue with the model. About half of the time with the specific prompt and harness that I've set up, the model drops part of the beginning of the commit hash when trying to call a tool. When the model is simply asked to copy the hash, it always succeeds, but it fails when copying that hash is a natural step towards calling a tool. No idea what's going on. Either way, seems like the issue has nothing to do with this PR, but it is concerning nonetheless. |
fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
|
@JohannesGaessler feedback should be addressed now. I found a couple other spots with the 320/576 splits and matched with the 192 there, and made sure it's getting covered in the backend test ops now. |
JohannesGaessler
left a comment
There was a problem hiding this comment.
Assuming the CI passes this should be good to merge based on static code analysis.
|
@am17an can I poke you for a review here? |
|
Since this was an issue recently I also checked that Pascal compilation isn't broken. |
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered (cherry picked from commit 046e284)
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
* mimo-v2.5: add flash attention mma/tiles for for d_kq=192 d_v=128 * mimo-v2.5: follow (256, 256) fattn templates * mimo-v2.5: cleanup comments * mimo-v2.5: further comment cleanup * mimo-v2.5: address PR feedback fix GQA handling check for other dangling 320/576 carveouts and mirror them for 192 Add to backend ops test so new paths are covered
… kernel MiMo-V2.5 (K/Q head 192, V head 128, GQA 8 or 16) and Mistral Small 4 (320/256, GQA 32) had no SYCL flash attention and ran it on the CPU. Port of the tile part of CUDA ggml-org#22286 and ggml-org#22812: config rows, the tile instances, and the dispatch, which needs the GQA path (a mask, no ALiBi, n_kv a multiple of 256) and a GQA ratio that is a multiple of 8 / 32. A 32-head tile holds one query row, so launch_fattn_tile_switch_ncols1 no longer asks for a 64-column config there. The vector kernel has no instance with different K and V head sizes and is not chosen for them. FLASH_ATTN_EXT on an Arc Pro B70: 4236/4236 (4185 before), the 51 new cases are 192/128 with nr 8 and 16 (34) and 320/256 with nr 32 (17); every other case has the same result as before. Assisted-by: Claude Opus 5.5 (1M context) <[email protected]>
… kernel MiMo-V2.5 (K/Q head 192, V head 128, GQA 8 or 16) and Mistral Small 4 (320/256, GQA 32) had no SYCL flash attention and ran it on the CPU. Port of the tile part of CUDA ggml-org#22286 and ggml-org#22812: config rows, the tile instances, and the dispatch, which needs the GQA path (a mask, no ALiBi, n_kv a multiple of 256) and a GQA ratio that is a multiple of 8 / 32. A 32-head tile holds one query row, so launch_fattn_tile_switch_ncols1 no longer asks for a 64-column config there. The vector kernel has no instance with different K and V head sizes and is not chosen for them. FLASH_ATTN_EXT on an Arc Pro B70: 4236/4236 (4185 before), the 51 new cases are 192/128 with nr 8 and 16 (34) and 320/256 with nr 32 (17); every other case has the same result as before. Assisted-by: Claude Opus 5.5 (1M context) <[email protected]>
… kernel MiMo-V2.5 (K/Q head 192, V head 128, GQA 8 or 16) and Mistral Small 4 (320/256, GQA 32) had no SYCL flash attention and ran it on the CPU. Port of the tile part of CUDA ggml-org#22286 and ggml-org#22812: config rows, the tile instances, and the dispatch, which needs the GQA path (a mask, no ALiBi, n_kv a multiple of 256) and a GQA ratio that is a multiple of 8 / 32. A 32-head tile holds one query row, so launch_fattn_tile_switch_ncols1 no longer asks for a 64-column config there. The vector kernel has no instance with different K and V head sizes and is not chosen for them. FLASH_ATTN_EXT on an Arc Pro B70: 4236/4236 (4185 before), the 51 new cases are 192/128 with nr 8 and 16 (34) and 320/256 with nr 32 (17); every other case has the same result as before. Assisted-by: Claude Opus 5.5 (1M context) <[email protected]>
… kernel MiMo-V2.5 (K/Q head 192, V head 128, GQA 8 or 16) and Mistral Small 4 (320/256, GQA 32) had no SYCL flash attention and ran it on the CPU. Port of the tile part of CUDA ggml-org#22286 and ggml-org#22812: config rows, the tile instances, and the dispatch, which needs the GQA path (a mask, no ALiBi, n_kv a multiple of 256) and a GQA ratio that is a multiple of 8 / 32. A 32-head tile holds one query row, so launch_fattn_tile_switch_ncols1 no longer asks for a 64-column config there. The vector kernel has no instance with different K and V head sizes and is not chosen for them. FLASH_ATTN_EXT on an Arc Pro B70: 4236/4236 (4185 before), the 51 new cases are 192/128 with nr 8 and 16 (34) and 320/256 with nr 32 (17); every other case has the same result as before. Assisted-by: Claude Opus 5.5 (1M context) <[email protected]>
Overview
MiMo-V2.5 has asymmetric head sizes for K=192, v=128 which causes a fallback to CPU when using CUDA with flash attention enabled. This PR adds the required MMA / Tiles entries to support compilation for those sizes.
Additional information
llama-sweep-benchspeeds,master:After, on this PR:
Requirements