[ExecuTorch][WebGPU] et_vk.sdpa: shape-route QK to a per-entry kernel for channel attention (15-30x faster)#20871
Open
JCNTH wants to merge 3 commits into
Open
[ExecuTorch][WebGPU] et_vk.sdpa: shape-route QK to a per-entry kernel for channel attention (15-30x faster)#20871JCNTH wants to merge 3 commits into
JCNTH wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20871
Note: Links to docs will display an error until the docs builds have been completed. ❌ 57 New Failures, 2 Unrelated Failures, 7 Unclassified FailuresAs of commit cf75400 with merge base c2b273e ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Jul 10, 2026
This PR needs a
|
This was referenced Jul 10, 2026
[ExecuTorch][WebGPU] Add relu op (shared unary handler; sigmoid adopts make_compute_pipeline)
#20863
Open
This was referenced Jul 10, 2026
This was referenced Jul 16, 2026
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.
Stack from ghstack (oldest at bottom):
Problem: the fused
et_vk.sdpaQK kernel runs one thread per (b,h,s) row with vec4 loads — ideal for standard attention, but on channel attention (DaViT/Florence, whereS_q = head_dim ~= 32)num_rows = B*H*S_qis tiny, so only a handful of workgroups run serially over a hugeS_kv*D, starving the GPU (the (2,1,1)@103ms dispatch).Solution: add a per-entry QK kernel (one thread per (b,h,s,c) attention entry, 2D-folded) and host-route to it when
num_rowsis below an occupancy floor (4096); standard attention keeps the per-row + vec4 path unchanged.Before:
et_vk_sdpa_qk(per-row, vec4) — the only QK kernel; channel-attn shapes are occupancy-starved.After: router picks
et_vk_sdpa_qk_entry(per-entry, scalar, 2D-folded) for smallnum_rows, else the unchanged per-row kernel.Implementation:
et_vk_sdpa_qk_entry.wgsl(+ generated header) — same bindings andParamsas the per-row kernel, so it is a drop-in underlayout:"auto"; writes a layout-identicalattn[B,H,S_q,S_kv](attn[idx]), so softmax/AV are unchanged and either branch is numerically correct — the floor is a pure perf knob.EtVkSdpa.cppselects the shader and a 2D dispatch (compute_2d_workgroup_count, mirroring the softmax grid) when routed, else the existing 1D per-row dispatch; the grid + dispatch-limit check is computed up front (throw before any buffer alloc -> no leak).LinearFp32.cppK%4vec4 selection,Sdpa.cppvariant selection).Constraints: per-entry drops vec4, so it only wins when the per-row path is occupancy-starved (small
num_rows); the 4096 floor is Canary-tuned.Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D110994975
Differential Revision: D110994975