Repository navigation
[WebGPU] Unroll bounded NVIDIA FlashAttention reductions in WGSL - #33395
Open
Yang Gu (gyagp) wants to merge 1 commit into
Open
Yang Gu (gyagp) wants to merge 1 commit into
Yang Gu (gyagp) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Yang Gu (gyagp)
force-pushed
the
codex/webgpu-nvidia-flash-unroll-20261015
branch
from
October 16, 2026 03:36
fe63446 to
2648fb0
Compare
Yang Gu (gyagp)
marked this pull request as ready for review
October 16, 2026 03:36
Contributor
Author
|
/run bots |
Contributor
|
The request was received. Approve workflow runs. Thanks. |
Unroll the inner QK/PV reductions for NVIDIA shared-memory prefill with head sizes up to 128, preserving FP32 score accumulation and cache keys. Add a 65-token regression covering head sizes 64/128/256 and partial tiles. Phi-4-mini-instruct, RTX 5080 / NVIDIA 617.42. Prefill tokens/s, median of three process averages; two warmups and three repetitions per process, batch 1, 32 generated tokens, ORT graph capture and generator reuse. Matched PR A/B, Agility SDK 1.721.3-preview / SM 6.10, DP4A: Prompt | ORT WebGPU D3D12 before -> after | Gain | ORT WebGPU Vulkan before -> after 512 | 4745.36 -> 5260.95 | +10.87% | 4587.78 -> 4581.26 1024 | 4753.84 -> 5436.72 | +14.36% | 4816.16 -> 4811.42 2048 | 4101.01 -> 5254.00 | +28.11% | 4788.19 -> 4776.38 4096 | 3218.81 -> 4723.09 | +46.73% | 5289.50 -> 5233.24 Cross-runtime baseline context, without this change (SGM = subgroup matrix; llama.cpp b11669 Vulkan, full prompts with prompt caching off): Prompt | ORT D3D12 DP4A | ORT Vulkan DP4A | ORT D3D12 SGM | ORT Vulkan SGM | llama.cpp Vulkan 512 | 4747.16 | 4586.13 | 8243.76 | 7728.76 | 10780.16 1024 | 4760.50 | 4801.05 | 8765.53 | 9785.29 | 10828.61 2048 | 4109.71 | 4792.29 | 6684.01 | 8926.87 | 11859.29 4096 | 3221.59 | 5238.37 | 4626.31 | 9087.97 | 11402.90 ONNX uses Q4/block-32 weights and a Q8 output head; GGUF uses Q4_K_M. Cross-runtime rates include quantization, kernel, and runtime differences. Shader-target recheck at 2048/4096 tokens: SM 6.9 improves prefill by 27.78%/46.84%; SM 6.8 regresses by 1.54%/2.17% (attention time +6.35% at 2048). The SM 6.8 tradeoff is accepted; no shader-model gate is added. Validation: 89 template tests pass; three native regression cases pass on SM 6.8/6.9/6.10. Sampled A/B/A logits and tokens match within each backend at 512/1024/2048/4096 tokens.
Yang Gu (gyagp)
force-pushed
the
codex/webgpu-nvidia-flash-unroll-20261015
branch
from
October 16, 2026 05:02
2648fb0 to
f041c21
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Unroll the inner QK/PV reductions for NVIDIA's dense shared-memory FlashAttention prefill path with head sizes up to 128. Preserve FP32 score accumulation, normalized-score conversion, accumulation order, and cache specialization. Larger heads, other vendors, paged attention, and decode retain their existing paths.
Add a high-magnitude FP16 regression with 65 query tokens and head sizes 64/128/256, covering partial tiles, expanded reductions, and the rolled fallback.
Performance
Phi-4-mini-instruct on RTX 5080 / NVIDIA 617.42. Prefill tokens/s, median of three process averages; two warmups and three repetitions per process, batch 1, 32 generated tokens. ORT uses graph capture and generator reuse. Profiling and shader logging are disabled during timing.
Matched PR A/B: Agility SDK 1.721.3-preview / D3D12 SM 6.10, subgroup matrices disabled, DP4A verified in both variants.
Cross-runtime baseline context, without this change. SGM means subgroup matrix; llama.cpp uses the b11669 Vulkan release, evaluates full prompts, and disables prompt-cache reuse.
ONNX uses Q4/block-32 linear weights plus a Q8 output head; GGUF uses mixed Q4_K_M weights. Cross-runtime comparisons include quantization, kernels, and runtime overhead. Only the matched ORT A/B isolates this patch's effect.
Accepted SM 6.8 tradeoff: the shader-target recheck measured -1.54% / -2.17% full-model prefill at 2,048 / 4,096 tokens and +6.35% attention-kernel time at 2,048. SM 6.9 improved prefill 27.78% / 46.84% at those lengths. The current NVIDIA/head-size gate is retained; this PR does not add a shader-model gate. Broader NVIDIA architecture coverage remains limited.
Validation
WebGPU_FP16_HighMagnitude*tests pass without skips on SM 6.8, 6.9, and 6.10. Captured shaders verify expanded head64/128, rolled head256, and FP32 accumulation.