Skip to content

Add flash attention MMA / Tiles to support MiMo-V2.5 - #22812

Merged
am17an merged 5 commits into
ggml-org:masterfrom
AesSedai:mimo-v2.5-fattn
May 9, 2026
Merged

am17an merged 5 commits into
ggml-org:masterfrom
AesSedai:mimo-v2.5-fattn

Conversation

@AesSedai

@AesSedai AesSedai commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

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-bench speeds, master:

|    PP |     TG |   N_KV |   T_PP s | S_PP t/s |   T_TG s | S_TG t/s |
|-------|--------|--------|----------|----------|----------|----------|
|   512 |    128 |      0 |    0.539 |   949.33 |    2.400 |    53.34 |
|   512 |    128 |    512 |    0.615 |   832.51 |    3.263 |    39.23 |
|   512 |    128 |   1024 |    0.708 |   723.43 |    3.314 |    38.62 |
|   512 |    128 |   1536 |    0.728 |   703.40 |    3.408 |    37.56 |
|   512 |    128 |   2048 |    0.842 |   608.44 |    3.528 |    36.28 |
|   512 |    128 |   2560 |    0.844 |   606.29 |    3.635 |    35.22 |
|   512 |    128 |   3072 |    0.895 |   572.12 |    3.710 |    34.50 |
|   512 |    128 |   3584 |    0.955 |   535.94 |    3.790 |    33.78 |
|   512 |    128 |   4096 |    1.016 |   503.79 |    3.885 |    32.95 |
|   512 |    128 |   4608 |    1.107 |   462.56 |    4.200 |    30.48 |
|   512 |    128 |   5120 |    1.132 |   452.30 |    4.013 |    31.89 |
|   512 |    128 |   5632 |    1.187 |   431.44 |    4.105 |    31.18 |
|   512 |    128 |   6144 |    1.244 |   411.61 |    4.260 |    30.04 |
|   512 |    128 |   6656 |    1.317 |   388.84 |    4.293 |    29.81 |
|   512 |    128 |   7168 |    1.373 |   372.85 |    4.368 |    29.30 |
|   512 |    128 |   7680 |    1.429 |   358.21 |    4.451 |    28.75 |

After, on this PR:

|    PP |     TG |   N_KV |   T_PP s | S_PP t/s |   T_TG s | S_TG t/s |
|-------|--------|--------|----------|----------|----------|----------|
|   512 |    128 |      0 |    0.321 |  1594.47 |    1.617 |    79.16 |
|   512 |    128 |    512 |    0.321 |  1593.80 |    1.618 |    79.13 |
|   512 |    128 |   1024 |    0.320 |  1602.07 |    1.619 |    79.05 |
|   512 |    128 |   1536 |    0.323 |  1584.53 |    1.620 |    79.03 |
|   512 |    128 |   2048 |    0.320 |  1602.32 |    1.621 |    78.94 |
|   512 |    128 |   2560 |    0.323 |  1587.19 |    1.622 |    78.91 |
|   512 |    128 |   3072 |    0.323 |  1583.45 |    1.626 |    78.73 |
|   512 |    128 |   3584 |    0.324 |  1581.18 |    1.625 |    78.75 |
|   512 |    128 |   4096 |    0.325 |  1573.98 |    1.627 |    78.69 |
|   512 |    128 |   4608 |    0.327 |  1566.03 |    1.627 |    78.67 |
|   512 |    128 |   5120 |    0.323 |  1586.14 |    1.628 |    78.61 |
|   512 |    128 |   5632 |    0.329 |  1555.60 |    1.629 |    78.58 |
|   512 |    128 |   6144 |    0.329 |  1556.26 |    1.632 |    78.43 |
|   512 |    128 |   6656 |    0.331 |  1547.68 |    1.632 |    78.42 |
|   512 |    128 |   7168 |    0.333 |  1539.83 |    1.634 |    78.31 |
|   512 |    128 |   7680 |    0.328 |  1560.61 |    1.635 |    78.31 |

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, to find necessary files and make sure templated kernels were updated correctly

@AesSedai
AesSedai requested a review from a team as a code owner May 7, 2026 17:32
@github-actions github-actions Bot added Nvidia GPU Issues specific to Nvidia GPUs python python script changes ggml changes relating to the ggml tensor library for machine learning labels May 7, 2026
@coder543

coder543 commented May 7, 2026

Copy link
Copy Markdown
Contributor

I ran a quick test, and this PR seems to work!

Before:

size fa test t/s
105.33 GiB 0 pp2048 452.38 ± 0.81
105.33 GiB 0 tg128 21.52 ± 0.01
105.33 GiB 1 pp2048 330.39 ± 0.47
105.33 GiB 1 tg128 6.34 ± 0.04

After:

size fa test t/s
105.33 GiB 1 pp2048 661.24 ± 1.95
105.33 GiB 1 tg128 22.40 ± 0.01

On a DGX Spark.

@coder543

coder543 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

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 dab41ec68d81324117017a5dd10452920c5c915, which is even stranger as it just leaves out the second character.

I've never seen a model behave this way before... so it makes me suspicious. But, maybe it is nothing.

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AesSedai

AesSedai commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

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.

@AesSedai

AesSedai commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Recompiled after the above commits, speeds are still sane:

|    PP |     TG |   N_KV |   T_PP s | S_PP t/s |   T_TG s | S_TG t/s |
|-------|--------|--------|----------|----------|----------|----------|
|   512 |    128 |      0 |    0.321 |  1592.86 |    1.615 |    79.24 |
|   512 |    128 |    512 |    0.321 |  1592.71 |    1.619 |    79.08 |
|   512 |    128 |   1024 |    0.319 |  1602.56 |    1.620 |    79.04 |
|   512 |    128 |   1536 |    0.322 |  1589.59 |    1.621 |    78.94 |
|   512 |    128 |   2048 |    0.321 |  1597.17 |    1.624 |    78.82 |
|   512 |    128 |   2560 |    0.322 |  1589.47 |    1.626 |    78.73 |
|   512 |    128 |   3072 |    0.323 |  1586.59 |    1.630 |    78.55 |
|   512 |    128 |   3584 |    0.323 |  1583.68 |    1.629 |    78.56 |
|   512 |    128 |   4096 |    0.326 |  1571.16 |    1.630 |    78.54 |
|   512 |    128 |   4608 |    0.326 |  1570.88 |    1.631 |    78.49 |
|   512 |    128 |   5120 |    0.322 |  1588.31 |    1.631 |    78.48 |
|   512 |    128 |   5632 |    0.329 |  1556.77 |    1.632 |    78.44 |
|   512 |    128 |   6144 |    0.330 |  1551.56 |    1.636 |    78.25 |
|   512 |    128 |   6656 |    0.331 |  1548.84 |    1.636 |    78.26 |
|   512 |    128 |   7168 |    0.332 |  1543.55 |    1.637 |    78.20 |
|   512 |    128 |   7680 |    0.328 |  1561.56 |    1.638 |    78.15 |

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fattn-tile.cuh still needs to have launch_fattn_tile_switch_ncols2 adjusted with an if constexpr to avoid compiling the unused ncols2 values.

Comment thread ggml/src/ggml-cuda/fattn.cu Resolved
@coder543

coder543 commented May 7, 2026

Copy link
Copy Markdown
Contributor

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
@AesSedai
AesSedai requested a review from ggerganov as a code owner May 7, 2026 22:52
@github-actions github-actions Bot added the testing Everything test related label May 7, 2026
@AesSedai

AesSedai commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@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 JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the CI passes this should be good to merge based on static code analysis.

@AesSedai

AesSedai commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

@am17an can I poke you for a review here?

@JohannesGaessler

Copy link
Copy Markdown
Contributor

Since this was an issue recently I also checked that Pascal compilation isn't broken.

@am17an
am17an merged commit 046e284 into ggml-org:master May 9, 2026
49 checks passed
cetarthoriphros pushed a commit to cetarthoriphros/llama.cpp that referenced this pull request May 9, 2026
* 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
baramofme pushed a commit to baramofme/llama-cpp-turboquant that referenced this pull request May 23, 2026
* 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
baramofme pushed a commit to baramofme/llama-cpp-turboquant that referenced this pull request May 23, 2026
* 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
carlosfundora pushed a commit to carlosfundora/llama.cpp-1-bit-turbo that referenced this pull request May 24, 2026
* 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)
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
* 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
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* 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
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 21, 2026
… 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]>
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 22, 2026
… 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]>
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 29, 2026
… 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]>
iki007 added a commit to iki007/llama.cpp that referenced this pull request Nov 4, 2026
… 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]>
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 Nvidia GPU Issues specific to Nvidia GPUs python python script changes testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants