Skip to content

[ExecuTorch][WebGPU] Add apply_rotary_emb_interleaved op#21185

Open
JCNTH wants to merge 1 commit into
gh/JCNTH/145/basefrom
gh/JCNTH/145/head
Open

[ExecuTorch][WebGPU] Add apply_rotary_emb_interleaved op#21185
JCNTH wants to merge 1 commit into
gh/JCNTH/145/basefrom
gh/JCNTH/145/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Problem: The WebGPU delegate is missing the pair-interleaved rotary embedding that the Vulkan delegate exposes as et_vk.apply_rotary_emb_interleaved (used by EdgeTAM). Without it these graphs fall back to CPU or fail to delegate.

Solution: Port the Vulkan apply_rotary_emb_interleaved.glsl to WGSL + a C++ handler, mirroring its math exactly. The last dim is [r, i] pairs and freqs is matching [cos, sin] pairs of shape [seq, width]; each output element applies the standard 2x2 rotation from its pair partner. Single dispatch, 2D-folded flat index to lift the 65535 1D-dispatch cap.

Implementation: RotaryEmbeddingInterleaved.cpp registers et_vk.apply_rotary_emb_interleaved.default (args [x, freqs, out]), guards rank-3 [B, N, C] / even width / fp32 / freqs == [seq, width] / numel <= u32 / non-null buffers, and installs a resize hook that recomputes seq/numel + dispatch counts for dynamic shapes. apply_rotary_emb_interleaved.wgsl reads the [cos, sin] pair at the even-aligned column and writes the rotated element.

Differential Revision: D112257634

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

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

❌ 77 New Failures

As of commit ea182f2 with merge base 266e0dc (image):

NEW FAILURES - The following jobs have failed:

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

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

This was referenced Jul 22, 2026
This was referenced Jul 22, 2026
@JCNTH
JCNTH requested a review from psiddh July 23, 2026 02:07

@psiddh psiddh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving full WebGPU stack

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