Skip to content

[ExecuTorch][WebGPU] Coalesce SDPA AV V-cache reads along contiguous head-dim#20508

Open
pytorchbot wants to merge 1 commit into
gh/JulianCloudNTH/49/origfrom
gh/JulianCloudNTH/54/orig
Open

[ExecuTorch][WebGPU] Coalesce SDPA AV V-cache reads along contiguous head-dim#20508
pytorchbot wants to merge 1 commit into
gh/JulianCloudNTH/49/origfrom
gh/JulianCloudNTH/54/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #20459 by @JulianCloudNTH
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/54/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/54/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/49/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/54/orig

@diff-train-skip-merge

…head-dim

Pull Request resolved: #20459

**~19% faster SDPA attention-output (AV) stage** — 393→317 µs on llama3 prefill (Chrome Canary / M4 Pro).

**Problem**: V-cache reads load 4 strided context rows × 1 head-dim lane, missing coalescing.

**Solution**: Flip access pattern to read 4 contiguous head-dim lanes per context row:
- **Before**: `load_v_vec4(d, kvh, c4)` → 4 strided rows, `dot()` along D
- **After**: `load_v_d4(c, kvh, d0)` → 4 contiguous D-lanes (16-byte texel), scalar broadcast

**Implementation**:
- Reindex `load_v` helper to read contiguous head-dim
- Replace `dot(A, V)` with `acc += A[c] * V_vec4(d0:d0+3)`
- Mirrors Vulkan `load_v_cache_d4` coalescing pattern

**Constraints**:
- No KV-cache layout change (still `[C, Hkv, D]`)
- Output numerically identical (FP-reassociated, max abs diff 1.43e-6 vs torch)
ghstack-source-id: 396792504
@exported-using-ghexport

Differential Revision: [D109339276](https://our.internmc.facebook.com/intern/diff/D109339276/)
@pytorch-bot

pytorch-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20508

Note: Links to docs will display an error until the docs builds have been completed.

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

❌ 3 New Failures, 1 Unrelated Failure

As of commit eb9073c with merge base e03f777 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants