Skip to content

[ExecuTorch][WebGPU] Dynamic resize hooks for rms_norm, embedding, rope#20575

Open
JulianCloudNTH wants to merge 1 commit into
gh/JulianCloudNTH/67/basefrom
gh/JulianCloudNTH/67/head
Open

[ExecuTorch][WebGPU] Dynamic resize hooks for rms_norm, embedding, rope#20575
JulianCloudNTH wants to merge 1 commit into
gh/JulianCloudNTH/67/basefrom
gh/JulianCloudNTH/67/head

Conversation

@JulianCloudNTH

@JulianCloudNTH JulianCloudNTH commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

These ops baked their dispatch count, param UBO, and output dims at build() for the max seq-len. On a dynamic-shape graph at a smaller live S they would over-dispatch and leave the output sized at the max, so the resize engine could not actually shrink them.

This adds tensor resize hooks to rms_norm, embedding_q4gsw, and apply_rotary_emb. When an input is resized, each hook recomputes the live row/token count, rewrites the param UBO, updates the dispatch workgroup_count_x, and sets the output's cur_dims. The hook is inert until a resize happens, so static graphs are byte-identical.

Implementation:

  • rms_norm: recompute num_rows from live cur_dims; out dims follow the input.
  • embedding_q4gsw: recompute num_indices/total_blocks; out dims = indices dims + [embed_dim].
  • apply_rotary_emb: add_rope_dispatch now returns its uniform handle; one hook rewrites both the xq and xk dispatches/UBOs for the live S and sets both outputs.
  • Each keeps its uniform buffer alive via own_uniform_buffer (the hook rewrites it) instead of releasing it at build.

Mirrors Vulkan per-op resize_*_node (recompute sizes + dispatch each execute). No kernel/WGSL/numerics change. Behavior-neutral on static graphs (hook only fires when live dims differ from max). quantized_linear and SDPA resize hooks land in following diffs; prepack needs none (constants are fixed-size).

Differential Revision: D109906096

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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 89bce88 with merge base 55a71e6 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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.

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