vulkan: large top-k support via argsort - #28005
Conversation
Extend the existing pipeline to use optimized top-k when possible, and fallback to descending argsort if requested k is not supported. This preserves the optimized path when possible, but unblocks larger currently-unsupported sizes. Add test coverage for large-k, motivated by qwen3.8-flash-next architecture. Assisted-by: Codex
|
Hi @antoinezambelli, 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. |
Can you share more details on the real-world workload? |
At its core, I ran a forge scenario - a pretty basic 3 step agentic workflow. It has since progressed to more complex scenarios. Happy to pull more data if you're looking for something specific!
|
|
I'm not sure what you're trying to say there. The question was what happens in the model that is not yet supported, and the answer is it has TOP_K operations with k 2048, we currently only support up to 1024. |
Oops, I misunderstood workload to mean end-to-end application. Sorry about that - PR overview updated as well. You got it right though. The model-side gap is Qwen3.8-Flash-Next’s attention indexer requesting TOP_K with a nominal k=2048, beyond the existing Vulkan path. The current qwen4exp graph also includes the compression-block tail, producing k=2051. The Forge/RPC details were only the end-to-end correctness check. |
|
What are the input dimensions? |
|
With this change I'm getting a devicelost in |
Overview
Extend Vulkan
TOP_Ksupport to largerkvalues by falling back to the existing descendingARGSORTimplementation when no optimized Top-K pipeline is available.The existing optimized path remains unchanged and is still used whenever it supports the requested
k. For larger values, each input row is sorted in descending order and the firstkindices are copied into the output tensor.Qwen3.8-Flash-Next configures its attention indexer with
top_k=2048. The currentqwen4expgraph also includes the compression-block tail, producingk=2051, which exceeds the existing Vulkan implementation’s supported range.This enables that workload without adding a model-specific path, changing the model graph, or introducing another shader.
Additional information
Implementation
Factor the existing argsort configuration, capability check, and dispatch logic into reusable helpers.
Continue using the specialized Top-K pipelines whenever available.
Otherwise:
kindices from each sorted row into the output tensor.Preserve the existing contiguity and Vulkan argsort capability requirements.
Add coverage for large
kand multi-row inputs.Validation
Focused Vulkan cases
The parent revision reported all four cases as unsupported:
With this change:
Full backend suite
Vulkan validation layers
The focused large-Top-K cases completed without validation errors.
The only emitted validation warning was the existing SPIR-V
WorkgroupSizebest-practice warning, which was also reproduced on the unchanged optimized small-Top-K path.Existing-path regression checks
The existing optimized case remained unchanged within measurement noise:
Qwen3.6-27B prompt processing and generation throughput were also unchanged within normal run-to-run variation. A matched Wikitext-2 check produced identical results:
Application-level check
Qwen3.8-Flash-Next has a separate large PLE tensor loading issue on Vulkan iGPU systems. For this end-to-end check, both the parent and candidate builds were layered on the same selective lazy-loading implementation proposed in #27837.
That loader work was needed only to fit this model on the test system. It is independent of Vulkan Top-K and is not included in this PR. The binary difference between the two validation builds was verified to be identical to this PR's Top-K diff.
Qwen3.8-Flash-Next
UD-Q4_K_XLwas then exercised over two Vulkan RPC workers at 262,144 context with Q8 K/V caches. A five-run stateful tool-calling smoke test completed successfully with 5/5 validated results.Requirements