[ExecuTorch][WebGPU] Dynamic resize hook for SDPA (live seq-len S)#20580
Open
JulianCloudNTH wants to merge 1 commit into
Open
[ExecuTorch][WebGPU] Dynamic resize hook for SDPA (live seq-len S)#20580JulianCloudNTH wants to merge 1 commit into
JulianCloudNTH wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20580
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit d2a1ecc with merge base 55a71e6 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Jun 28, 2026
This PR needs a
|
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):
Make
sdpa_with_kv_cacheserve any live seq-len S from one graph (batched prefill S=K and decode S=1).Problem: the existing dynamic path only reacted to a live
input_pos(decode), with S captured at build time. It rewrote the QK dispatch (which depends oncontext_len) but leftupdate_cache, softmax, and AV sized for the build-time S. Under a dynamic seq-len S (one graph serving prefill and decode),kv_numel, the QK/AV tile grids, and the softmax row count all depend on S and were stale.Solution: a single recompute hook driven by either a live S (q tensor resize) or a live
input_pos(SymInt), recomputing every per-step quantity from the live shape.input_pos; recomputes ctx + QK count; S fixed.input_pos(when SymInt); reads live S fromcur_dims(q)and live pos, recomputes all five dispatches' counts + UBOs (update_cacheK/V, QK, softmax, AV), and sets the outputcur_dimsto q's.Implementation:
update_cache/softmax/AV dispatch indices (previously only QK) so their workgroup counts can be rewritten per step.Hq*ceil(S/TM)*ceil(ctx-or-D/TN)); softmax is one workgroup perHq*Srow.DynamicDispatchNode(recompute workgroups per execute); scratch is sized at build (S=max, ctx=Cmax) so buffers never move and bind groups stay valid.Constraints: fp32-only, batch=1, GQA,
is_causal=true,D%4==0invariants unchanged; the static / decode-only paths are unaffected (the q hook never fires without a resize).Co-authored-with: Claude Code.
Differential Revision: D109906097