Skip to content

[ExecuTorch][WebGPU] et_vk.apply_rotary_emb_hf: HuggingFace rotate-half RoPE runtime op (unblocks Qwen3)#20875

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

[ExecuTorch][WebGPU] et_vk.apply_rotary_emb_hf: HuggingFace rotate-half RoPE runtime op (unblocks Qwen3)#20875
JCNTH wants to merge 1 commit into
gh/JCNTH/50/basefrom
gh/JCNTH/50/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 10, 2026

Copy link
Copy Markdown

Stack from ghstack (oldest at bottom):

Problem: the WebGPU runtime registers only et_vk.apply_rotary_emb (the interleaved/Meta RoPE convention). HuggingFace-derived models (Qwen3, etc.) export the rotate-half convention, which fuses under VulkanPartitioner into et_vk.apply_rotary_emb_hf — an op the runtime graph builder has no handler for, so WebGPUGraph::build() throws and the delegate is rejected at load with DelegateInvalidCompatibility (et_load error 48). The whole model then fails to load on WebGPU.

Solution: add the et_vk.apply_rotary_emb_hf runtime kernel + handler as a rotate-half sibling of the interleaved op.

Before: only apply_rotary_emb (interleaved) is registered; HF-RoPE models throw at load.
After: both conventions are handled; HF-RoPE models (Qwen3) load and run.

Implementation:

  • New rotary_embedding_hf.wgsl: one thread per (i, i+half_dim) pair (rotate-half pairing vs the interleaved even/odd), reading a full [max_seq, rotary_dim] freqs table indexed at row start_pos + s. Scalar, wg_size 64 — structural + optimization parity with the interleaved kernel (RoPE is ~1% of runtime; vec4 is neutral for this elementwise-class op on Apple's scalar ALU).
  • RotaryEmbedding.cpp: apply_rotary_emb_hf_impl mirrors the interleaved handler; it parses the extra start_pos arg as a build-time Int (baked) or a runtime SymInt (dynamic KV-cache decode) exactly as Sdpa.cpp handles input_pos, and registers a seq resize hook (xq/xk) plus a start_pos resize hook (dynamic decode). Full rotary only (rotary_dim == head_dim); partial-rotary passthrough throws (documented follow-up; Qwen3 uses full RoPE). Mirrors Vulkan et_vk.apply_rotary_emb_hf (backends/vulkan/runtime/graph/ops/impl/RotaryEmbedding.cpp).
  • Registers et_vk.apply_rotary_emb_hf.default.

Constraints: full rotary only for now; scalar one-thread-per-pair, kept at parity with the interleaved sibling rather than vec4 (neutral for RoPE per the closed vec4 sweep).

Co-authored-with: Claude Code.

Differential Revision: D111009173

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 8874028 with merge base aceeb40 (image):

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.

This was referenced Jul 10, 2026
@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.

@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 Jul 10, 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