Skip to content

vulkan: top_k radix select for k >= 1024 for Qwen 3.8 Flash Next - #28032

Merged
0cc4m merged 4 commits into
masterfrom
0cc4m/vulkan-topk-radix
Aug 31, 2026
Merged

vulkan: top_k radix select for k >= 1024 for Qwen 3.8 Flash Next#28032
0cc4m merged 4 commits into
masterfrom
0cc4m/vulkan-topk-radix

Conversation

@0cc4m

@0cc4m 0cc4m commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Overview

Qwen 3.8 Flash Next requires top-k with k 2048 and higher, which Vulkan's current shader does not support. Add a radix sort for top-k with k 1024 or higher.

I also fused the QSA indexer pattern the Qwen model uses into it, which gives a few percent more performance. Not sure if this is premature and the pattern will change. It adds a few percent performance on top.

Supersedes #28005, with significantly higher performance than using argsort here.

AMD 8060S (Strix Halo)

test Vulkan master Vulkan radix-only Vulkan radix+fusion ROCm
pp512 @ d0 313.3 294.7 292.2 242.2
tg128 @ d0 24.06 23.79 23.70 15.62
pp512 @ d16384 183.3 214.5 219.9 138.1
tg128 @ d16384 15.82 17.95 18.21 10.63
pp512 @ d32768 145.8 175.7 179.5 118.9
tg128 @ d32768 12.84 14.91 15.16 9.30

DGX Spark (GB10)

test Vulkan master Vulkan radix-only Vulkan radix+fusion CUDA
pp512 @ d0 693.8 699.0 691.2 732.9
tg128 @ d0 26.18 26.17 26.19 29.43
pp512 @ d16384 449.0 580.8 585.5 611.0
tg128 @ d16384 13.74 21.97 22.36 24.12
pp512 @ d32768 390.1 512.3 520.8 498.5
tg128 @ d32768 12.02 19.23 19.78 20.68

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, Claude was used to write code, I validated it.

@0cc4m
0cc4m requested review from a team and ggerganov as code owners August 30, 2026 15:55
@github-actions github-actions Bot added testing Everything test related Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Aug 30, 2026
@jeffbolznv

Copy link
Copy Markdown
Contributor

I've also been poking around at a larger top_k today, I hadn't quite finished reviewing but I'll share it in a moment. Mine does a radix/histogram in global memory and tries to spread each row across multiple workgroups.

// Don't pull forward nodes from fusion patterns
// Protect every interior QSA node (not just the start): the mask branch is
// independent, so it gets pulled out and breaks keep_pattern otherwise.
auto const &in_qsa_pattern = [&](int n) -> bool {

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.

I had to have codex explain this to me, but it makes sense now.

@0cc4m 0cc4m changed the title vulkan: top_k radix sort for k >= 1024 for Qwen 3.8 Flash Next vulkan: top_k radix select for k >= 1024 for Qwen 3.8 Flash Next Aug 31, 2026
@0cc4m
0cc4m merged commit daef7b6 into master Aug 31, 2026
24 of 29 checks passed
@0cc4m
0cc4m deleted the 0cc4m/vulkan-topk-radix branch August 31, 2026 05:04
amangupta-tether pushed a commit to amangupta-tether/qvac-fabric-llm.cpp that referenced this pull request Aug 31, 2026
…l-org#28032)

* vulkan: add top-k radix sort shader for k >= 1024

* add Qwen 3.8 Flash Next top-k tests

* add top-k qsa fusion

* clean up code
wdenejko added a commit to wdenejko/llama.cpp that referenced this pull request Aug 31, 2026
54 upstream commits since 1844325. Conflict resolutions keep the fork's
validated mmid stack authoritative and graft upstream additions alongside:
- mul_mat_id pc: union of our padded_N/use_row_lists/fusion_flags/tile_list_base
  and upstream's n_experts/hoist_row_ids (ggml-org#26686); mmq declares tile_list_base
  as layout filler so both shader blocks match the one host struct.
- row-id loading: our row-lists prepass first, upstream's hoisted path second
  (their gate is n_as <= 256, so qwen4exp n_as=512 never hoists), ballot scan
  as the fallback; hoisting yields the prepass buffer to our row lists.
- K-vs-N padding (ggml-org#27925): took upstream's y_staged_row_stride/K-pad scheme;
  padded_N stays as a pc-layout filler (no merged shader reads it).
- Strix mat-vec tuning (ggml-org#27909): took upstream's rm_id/rm_int_n RDNA3 lambdas
  alongside our GGML_VK_MMV_RM_* sweep knobs.
- kept our epilog-fusion ctx fields next to upstream's fused_topk_qsa (ggml-org#28032).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
gagallo7 pushed a commit to gagallo7/qvac-fabric-llm.cpp that referenced this pull request Aug 31, 2026
…l-org#28032)

* vulkan: add top-k radix sort shader for k >= 1024

* add Qwen 3.8 Flash Next top-k tests

* add top-k qsa fusion

* clean up code

(cherry picked from commit 65c7c96)
Nathanw1014 pushed a commit to Nathanw1014/llama.cpp that referenced this pull request Aug 31, 2026
…l-org#28032)

* vulkan: add top-k radix sort shader for k >= 1024

* add Qwen 3.8 Flash Next top-k tests

* add top-k qsa fusion

* clean up code
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 testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants