Repository navigation
sycl: accelerate GLM MLA prefill with MKL flash attention - #29171
Conversation
|
Hi @anantshri, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
arthw
left a comment
There was a problem hiding this comment.
It's good job!
GLM-4.7-Flash-Q4_K_M.gguf on B60:
| Test | fa | Base t/s | Primary t/s | Increase Rate (Primary vs Base) |
|---|---|---|---|---|
| pp8192 | 0 | 681.32 | 671.02 | -1.51% |
| pp8192 | 1 | 218.31 | 619.75 | 183.89% |
| tg128 | 0 | 40.77 | 41.00 | 0.56% |
| tg128 | 1 | 40.00 | 40.07 | 0.18% |
Thank you!
| // GLM-4.7 Flash: exact MLA shape that dispatches to MKL FA for prompt batches. | ||
| test_cases.emplace_back(new test_flash_attn_ext(576, 512, 1, {20, 1}, 1024, 32, true, false, 0, 0, | ||
| GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, true)); |
There was a problem hiding this comment.
Prefer not to add this shape because it is very slow on some Vulkan jobs: #28842
There was a problem hiding this comment.
Thanks for the headsup. I will try to see what i can do about this.
I was experimenting on GLM only and i think i might have found more performance improvement point will circle back on this one in next 24 hours or so.
3942532 to
265f974
Compare
Measured on an Intel Arc Pro B70 with the dispatch from the previous pp8192 1583.9 -> 1657.1 tok/s (+4.6%) @arthw @ggerganov for your review and consideration. |
GLM-4.7 Flash uses an MLA shape with 576-wide Q/K heads, a 512-wide V head, GQA 20, and F16 KV. The SYCL dispatcher rejects this shape because the normal MKL flash-attention gate requires matching K/V widths and caps the head dimension at 512, so prompt processing falls back to the substantially slower TILE kernel. Admit only the validated 576/576/512, GQA-20 F16 shape to the existing MKL pipeline. Keep all other mismatched K/V shapes on their current fallback paths. Handle GLM's V cache as a narrower strided view of K rows. Select the strided F16 descriptor when row stride is padded, and alias K/V dequantization buffers only when their logical widths match. Restrict the stride exception to a real V view sharing K's row stride. Add the exact 576/512, GQA-20 prompt-path backend test. On an Intel Arc Pro B70 at master e613ef2, pp8192 improves from 432.80 to 1292.29 tok/s (2.99x, +198.6%). tg256 remains unchanged within noise at 45.67 versus 45.65 tok/s. The exact MLA test passes and debug output confirms MKL dispatch.
Keep the QK GEMM output in F16 instead of F32. The online softmax still converts each score to F32 for its max, exponent, and sum, so the per-element math is unchanged apart from score rounding, and the F32 matrix was being written only to be consumed as F16 probabilities. The F32 score matrix is the largest flash-attention intermediate on this path; storing it as F16 halves its size and traffic. This builds on the coalesced softmax loads from 1aa2954, which read each score row cooperatively, so the smaller dtype pays off. Measured on an Intel Arc Pro B70 with the dispatch from the previous commit, -ngl 999 -b 4096 -ub 1024 -ctk f16 -ctv f16 -fa on: pp8192 1583.9 -> 1657.1 tok/s (+4.6%) pp64000 610.0 -> 684.5 tok/s (+12.2%) pp131072 ~354 -> 402.1 tok/s (+13.5%) tg256 at 8k context is unchanged (32.64), and the FLASH_ATTN_EXT suite shows no new failures. The exact GLM MLA backend cases pass against CPU. Adjust the ~354 baseline figure if you prefer citing only measured pairs (the 131k dispatch-only point came from the equivalent maintained build). Optionally add Assisted-by: <tool name> per the contribution guidelines since AI contributed to the change.
This reverts commit 265f974.
265f974 to
88e6449
Compare
|
|
On Arc770, I didn't see the perf increase. Could you confirm it? Here is my test result:
Thank you! |
|
@arthw you will only see perf gain for GLM 4.7
your initial test was for GLM 4.7 #29171 (review) as prefil size increases the benefit is amplified. |
|
On B60, I tested with the latest code. Could you double check?
|
|
@arthw can you try for larger sizes the performance increment is at the larger context as i showed here #29171 i am running a comparision but mainline is pathetically slow on 64k or more pp so its taking time will post the values once i get them edit more entries i will add here As you can see the gains become visible the movement you start going bigger on pp size. Edit with final updates
Would request to please check at higher sizes. you will find the improvements. sorry for the delay in posting all the details but wanted to run everything and show exact improvements. at top end of the size spectrum you can see massive gains. |
…cl-b70-combined-20261001
arthw
left a comment
There was a problem hiding this comment.
It's good job!
On B60:
| GGUF | Test | fa | Base t/s | Primary t/s | Increase Rate (Primary vs Base) |
|---|---|---|---|---|---|
| GLM-4.7-Flash-Q4_K_M.gguf | pp8192 | 0 | 602.81 | 595.73 | -1.17% |
| GLM-4.7-Flash-Q4_K_M.gguf | pp8192 | 1 | 204.50 | 602.64 | 194.69% |
| GLM-4.7-Flash-Q4_K_M.gguf | tg128 | 0 | 40.79 | 40.97 | 0.44% |
| GLM-4.7-Flash-Q4_K_M.gguf | tg128 | 1 | 39.95 | 40.09 | 0.35% |
Thank you!
…9171) * sycl: accelerate GLM MLA prefill with MKL flash attention GLM-4.7 Flash uses an MLA shape with 576-wide Q/K heads, a 512-wide V head, GQA 20, and F16 KV. The SYCL dispatcher rejects this shape because the normal MKL flash-attention gate requires matching K/V widths and caps the head dimension at 512, so prompt processing falls back to the substantially slower TILE kernel. Admit only the validated 576/576/512, GQA-20 F16 shape to the existing MKL pipeline. Keep all other mismatched K/V shapes on their current fallback paths. Handle GLM's V cache as a narrower strided view of K rows. Select the strided F16 descriptor when row stride is padded, and alias K/V dequantization buffers only when their logical widths match. Restrict the stride exception to a real V view sharing K's row stride. Add the exact 576/512, GQA-20 prompt-path backend test. On an Intel Arc Pro B70 at master e613ef2, pp8192 improves from 432.80 to 1292.29 tok/s (2.99x, +198.6%). tg256 remains unchanged within noise at 45.67 versus 45.65 tok/s. The exact MLA test passes and debug output confirms MKL dispatch. * sycl: store MKL flash attention scores in F16 Keep the QK GEMM output in F16 instead of F32. The online softmax still converts each score to F32 for its max, exponent, and sum, so the per-element math is unchanged apart from score rounding, and the F32 matrix was being written only to be consumed as F16 probabilities. The F32 score matrix is the largest flash-attention intermediate on this path; storing it as F16 halves its size and traffic. This builds on the coalesced softmax loads from 1aa2954, which read each score row cooperatively, so the smaller dtype pays off. Measured on an Intel Arc Pro B70 with the dispatch from the previous commit, -ngl 999 -b 4096 -ub 1024 -ctk f16 -ctv f16 -fa on: pp8192 1583.9 -> 1657.1 tok/s (+4.6%) pp64000 610.0 -> 684.5 tok/s (+12.2%) pp131072 ~354 -> 402.1 tok/s (+13.5%) tg256 at 8k context is unchanged (32.64), and the FLASH_ATTN_EXT suite shows no new failures. The exact GLM MLA backend cases pass against CPU. Adjust the ~354 baseline figure if you prefer citing only measured pairs (the 131k dispatch-only point came from the equivalent maintained build). Optionally add Assisted-by: <tool name> per the contribution guidelines since AI contributed to the change. * Revert "sycl: store MKL flash attention scores in F16" This reverts commit 265f974. (cherry picked from commit d2a79e6)
…9171) * sycl: accelerate GLM MLA prefill with MKL flash attention GLM-4.7 Flash uses an MLA shape with 576-wide Q/K heads, a 512-wide V head, GQA 20, and F16 KV. The SYCL dispatcher rejects this shape because the normal MKL flash-attention gate requires matching K/V widths and caps the head dimension at 512, so prompt processing falls back to the substantially slower TILE kernel. Admit only the validated 576/576/512, GQA-20 F16 shape to the existing MKL pipeline. Keep all other mismatched K/V shapes on their current fallback paths. Handle GLM's V cache as a narrower strided view of K rows. Select the strided F16 descriptor when row stride is padded, and alias K/V dequantization buffers only when their logical widths match. Restrict the stride exception to a real V view sharing K's row stride. Add the exact 576/512, GQA-20 prompt-path backend test. On an Intel Arc Pro B70 at master e613ef2, pp8192 improves from 432.80 to 1292.29 tok/s (2.99x, +198.6%). tg256 remains unchanged within noise at 45.67 versus 45.65 tok/s. The exact MLA test passes and debug output confirms MKL dispatch. * sycl: store MKL flash attention scores in F16 Keep the QK GEMM output in F16 instead of F32. The online softmax still converts each score to F32 for its max, exponent, and sum, so the per-element math is unchanged apart from score rounding, and the F32 matrix was being written only to be consumed as F16 probabilities. The F32 score matrix is the largest flash-attention intermediate on this path; storing it as F16 halves its size and traffic. This builds on the coalesced softmax loads from 1aa2954, which read each score row cooperatively, so the smaller dtype pays off. Measured on an Intel Arc Pro B70 with the dispatch from the previous commit, -ngl 999 -b 4096 -ub 1024 -ctk f16 -ctv f16 -fa on: pp8192 1583.9 -> 1657.1 tok/s (+4.6%) pp64000 610.0 -> 684.5 tok/s (+12.2%) pp131072 ~354 -> 402.1 tok/s (+13.5%) tg256 at 8k context is unchanged (32.64), and the FLASH_ATTN_EXT suite shows no new failures. The exact GLM MLA backend cases pass against CPU. Adjust the ~354 baseline figure if you prefer citing only measured pairs (the 131k dispatch-only point came from the equivalent maintained build). Optionally add Assisted-by: <tool name> per the contribution guidelines since AI contributed to the change. * Revert "sycl: store MKL flash attention scores in F16" This reverts commit 265f974.

Overview
DKQ=576,DV=512, GQA-20 F16 MLA prompt shape through the existing SYCL MKL flash-attention pipelineAdditional information
Problem
The normal SYCL MKL flash-attention gate requires matching K and V head dimensions and limits the head dimension to 512.
GLM-4.7 Flash uses:
Because
DKQ != DVandDKQ > 512, GLM prefill falls back to the generic TILE kernel. That fallback scales poorly with context length and causes severe long-context prefill degradation.The existing MKL pipeline already parameterizes the KQ and VKQ operations with separate dimensions, so it can support this shape once dispatch and V-cache layout handling are corrected.
Implementation
The new dispatch exception is deliberately narrow. It admits only:
Q = 576K = 576V = 512All existing prompt, mask, bias, softcap, batch, graph, and cache restrictions remain in force. Other unequal K/V shapes continue to use their existing fallback paths.
GLM stores V as a 512-element sub-view of a 576-element K-cache row. Its logical row is 1,024 bytes, while its physical row stride remains 1,152 bytes.
The implementation therefore:
An exact backend test covers the 576/512, GQA-20, strided-V configuration.
Performance
Intel Arc Pro B70, IntelLLVM 2026.1, oneDNN enabled, F16 KV,
-ngl 999 -b 4096 -ub 1024 -fa on, three repetitions.This table compares clean master with this standalone patch only.
Prompt processing
The improvement grows with context length because the patch removes GLM's quadratic TILE fallback and routes the supported MLA shape through MKL flash attention.
Context-loaded generation
Generation of 256 tokens after preloading the stated KV-cache depth:
Generation remains effectively unchanged, as expected for a prompt-processing dispatch change.
Validation
b23efaa2D=576,DV=512, 20 Q heads, and one KV headFLASH_ATTN_EXTsuite: 4,044/4,045 passedgit diff --checkpassesScope
This is a standalone three-file change:
ggml/src/ggml-sycl/fattn.cppggml/src/ggml-sycl/fattn-mkl.cpptests/test-backend-ops.cppIt does not depend on the IQ3 optimization, the MMVQ decode fusions, PR #28918, PR #28931, or any other B70 campaign patch.
Requirements
This specific PR and associated fixes are created using GPT 5.6 Sol