Repository navigation
sycl: route BMG D=256 single-query decode to the FA vector kernel - #30606
Conversation
arthw
left a comment
There was a problem hiding this comment.
I test on B60.
There is not perf increasing:
| GGUF | Test | fa | Base t/s | Primary t/s | Increase Rate (Primary vs Base) |
|---|---|---|---|---|---|
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp8192 | 0 | 188.77 | 188.76 | -0.01% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp8192 | 1 | 190.99 | 190.99 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp2048 | 0 | 192.29 | 192.28 | -0.01% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp2048 | 1 | 192.67 | 192.66 | -0.01% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp1024 | 0 | 193.09 | 193.09 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp1024 | 1 | 192.82 | 192.82 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp32 | 0 | 45.66 | 45.68 | 0.04% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp32 | 1 | 44.29 | 44.30 | 0.02% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp16 | 0 | 23.91 | 23.91 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | pp16 | 1 | 23.17 | 23.17 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | tg128 | 0 | 15.90 | 15.90 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | tg128 | 1 | 15.91 | 15.98 | 0.44% |
Could you share the whole test cmd?
Thank you!
|
Hey @arthw : Thanks for testing on B60 — those numbers are exactly what this change predicts, because none of the cells in that matrix hit the case this PR touches. The condition, in plain terms. This PR changes exactly one dispatch decision: generating tokens one at a time (decode, Why each of your cells is flat:
What we measured, model by model (Arc Pro B70, single GPU,
pp cells on B70 were also flat by construction (7603/7326/4859 vs 7603/7323/4853 t/s at the tail-arm pp sizes). All three models have head dim 256 with 4 KV heads (Spark: 16 query heads → GQA4; Qwen3.8: 24 query heads → GQA6 — verified from the GGUF metadata) — the shapes the routing targets. The exact commands behind the table: # Spark BF16 — tg @0 / @8k / @64k
llama-bench -m Spark-X2.5-4B.gguf -t 6 -ngl 999 -fa 1 -b 2048 -ub 2048 -p 0 -n 256 -d 0,8192,64000
# Spark Uncensored Q8_0 — same three depths
llama-bench -m Spark-X2.5-4B-Uncensored-Q8_0.gguf -t 6 -ngl 999 -fa 1 -b 2048 -ub 2048 -p 0 -n 256 -d 0,8192,64000
# Qwen3.8-27B — the tg128 @32k cell
llama-bench -m Qwen3.8-27B-UD-Q4_K_XL.gguf -t 6 -ngl 999 -fa 1 -b 4096 -ub 1024 -p 0 -n 128 -d 32768 -r 3
To reproduce on B60, the single most informative cell is: llama-bench -m Qwen3.8-27B-UD-Q4_K_XL.gguf -ngl 99 -fa 1 -p 0 -n 128 -d 32768base vs this branch. On B70 this went 18.59 → 20.58 tok/s; on B60 I'd expect the same direction, with the magnitude depending on how the two kernels compare on your memory subsystem. Model sources (all public Hugging Face repos, so the exact cells are reproducible):
If you want to watch the routing decide live: |
arthw
left a comment
There was a problem hiding this comment.
It's good job!
On B60, I get perf increasing with "-fa 1 -p 0 -n 128 -d 32768":
| GGUF | Test | fa | Base t/s | Primary t/s | Increase Rate (Primary vs Base) |
|---|---|---|---|---|---|
| Qwen3.8-27B-UD-Q4_K_XL.gguf | tg128 | 0 | 10.44 | 10.44 | 0.00% |
| Qwen3.8-27B-UD-Q4_K_XL.gguf | tg128 | 1 | 11.19 | 12.21 | 9.12% |
Thank you!
1650840 to
c514a38
Compare
|
@anantshri Thank you! |
over to you @arthw @Titaniumtown |
|
@arthw we should wait on @ggerganov to review the test changes |
|
@Titaniumtown |
|
@anantshri can you please rebase? Thank you! |
f61e4a5 to
502685b
Compare
|
@Titaniumtown @arthw Rebased. |
The GQA-optimized tile config has been the dispatcher's preference for masked single-query decode since it landed. On Battlemage (bmg_g21/g31) with head dim 256 the vector kernel is materially faster at that shape: 832 vs 1150 us per call at kv=65536, GQA4 (B70, op-level twins). Route single-query (Q->ne[1] == 1), non-quantized-KV, max_bias == 0 decode to BEST_FATTN_KERNEL_VEC on those parts/head sizes; every other arch, head size, and query count keeps the existing preference. Also drop the now redundant K->ne[1] % FATTN_KQ_STRIDE gate: the GQA-optimized TILE variant iterates its trailing chunk out-of-bounds-checked, so n_kv no longer needs to be a multiple of FATTN_KQ_STRIDE. End-to-end (Arc Pro B70, llama-bench -fa 1, 2 rounds reversed order): | cell | before | after | delta | |---|---:|---:|---:| | Spark-X2.5-4B BF16 tg @0 / @8k / @64k | 52.05 / 47.93 / 33.68 | 52.91 / 49.84 / 37.68 | +1.7 / +4.0 / +11.9% | | Spark-4B-Uncensored Q8_0 tg @0 / @8k / @64k | 98.11 / 84.65 / 48.49 | 101.73 / 90.68 / 57.14 | +3.7 / +7.1 / +17.8% | | Qwen3.8-27B Q4_K_XL tg128 @32k | 18.59 | 20.58 | +10.7% | Prefill unchanged by construction (dispatch edit is Q->ne[1] == 1 only); tail-arm pp cells measured flat (7603/7326/4859 vs 7603/7323/4853). Correctness gates: FA op suite 4073/4085 — the 12 non-green are pre-existing on the production binary (2 failures) plus 10 known >=32k-KV tolerance overages identical across both kernels; perplexity byte-identical between arms (14.7975 +/- 0.37670); greedy parity 4/5 byte-identical, the 5th differs only in whitespace.
Address review feedback on the FA TILE dispatch instrumentation added in this PR: it read the env var through a static-local getenv at the call site. Follow the GGML_SYCL_DEV_DEBUG pattern instead: - g_ggml_sycl_fa_tile_debug is a global (extern in base.hpp, defined in ggml-sycl.cpp), read once in ggml_check_sycl() during backend init, so the per-call cost on the dispatch path is one unlikely branch: no lazy first-call getenv and no per-template-instantiation static guard (fattn-tile.hpp is instantiated once per DKQ/DV combination) - the call site in fattn-tile.hpp uses a GGML_SYCL_FA_TILE_DEBUG() macro shaped like GGML_SYCL_DEV_DEBUG() - documented in docs/backend/SYCL.md (runtime env table) and echoed in the init "Running with Environment Variables" log alongside the other debug vars
502685b to
76450bb
Compare
|
Tests dropped, rebased on master @Titaniumtown over to you. |
Summary
Q->ne[1] == 1, non-quantized-KV,max_bias == 0decode toBEST_FATTN_KERNEL_VECon those parts/head sizes only; every other arch, head size, and query count keeps the existing preferenceK->ne[1] % FATTN_KQ_STRIDEgate fromgqa_opt_applies: the GQA-optimized TILE variant iterates its trailing chunk out-of-bounds-checked, so n_kv no longer needs to be a multiple ofFATTN_KQ_STRIDE— hygiene, not perf (see marker 3)test_flash_attn_extcoverage for D=256 at aligned and unaligned kv (1024/1025/5003/16383/16384/32767/32768/65535/65536, GQA4 and GQA6, batch 1/2/5) so both the gate drop and the decode routing are regression-coveredPerformance
Arc Pro B70, llama-bench
-fa 1, 2 rounds in reversed arm order:Prefill unchanged by construction (the dispatch edit is
Q->ne[1] == 1only); tail-arm pp cells measured flat (7603/7326/4859 vs 7603/7323/4853).How this was found (markers)
max_bias=0vsmax_bias=8athsk=256,nh=4,nr23=[4,1],kv=65536,nb=1on the same binary → 1150 µs (tile) vs 832 µs (vector) — the marker that located the win.use_gqa_opt = falseeverywhere collapses deep decode 3× (Spark BF16 d64k: 33.7 → 11.7 tok/s) — the tile config still wins at its shapes; this change is shape-scoped, not a general preference flip.n_kv % FATTN_KQ_STRIDEalignment gate essentially never blocks in practice — llama.cpp pads FA-visible KV to 256-token granularity (live dispatch instrumentation shows onlyn_kv ∈ {256, 1024, 65536, 65792}). An end-to-end A/B of just the tail/gate change was flat (±0.9%); the gate drop rides along as dead-condition cleanup.Verification
Requirements