[ExecuTorch][WebGPU] Dynamic resize hook for slice_copy (dynamic start/end) by JulianCloudNTH · Pull Request #20581 · pytorch/executorch · GitHub
Skip to content

[ExecuTorch][WebGPU] Dynamic resize hook for slice_copy (dynamic start/end)#20581

Open
JulianCloudNTH wants to merge 6 commits into
gh/JulianCloudNTH/73/basefrom
gh/JulianCloudNTH/73/head
Open

[ExecuTorch][WebGPU] Dynamic resize hook for slice_copy (dynamic start/end)#20581
JulianCloudNTH wants to merge 6 commits into
gh/JulianCloudNTH/73/basefrom
gh/JulianCloudNTH/73/head

Conversation

@JulianCloudNTH

@JulianCloudNTH JulianCloudNTH commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Make slice_copy support a dynamic gather range so the RoPE-freqs slice [input_pos : input_pos + S] works under one dynamic graph.

Problem: the static slice handler read start via a scalar reader that throws on a SymInt and ignored end (output length baked AOT). The RoPE-freqs slice uses a SymInt input_pos for start and a live S for the range, so the static op could neither build nor resize for it.

Solution: read start/end as possibly-dynamic SymInts and add a resize hook that recomputes the gather offset and live output length each step.

  • Before: start is a static scalar (SymInt throws); end ignored; output length fixed at the serialized max.
  • After: start/end read via a SymInt-aware reader; a hook recomputes out[dim] = (end - start + step - 1) / step, rewrites out_meta/in_meta/params UBOs + the dispatch count, and sets the output cur_dims.

Implementation:

  • Hook registered on the start/end value-ids when they are SymInts and on the input tensor always (inert until resized, so a static slice is byte-identical).
  • Output/input TensorMeta rebuilt from live dims; dim/step stay static.
  • Keep the uniforms alive via own_uniform_buffer so the hook can rewrite them.
  • Mirrors Vulkan resize_slice_copy_node.

Constraints: fp32-only; dim/step static; numerics + layout unchanged; inert on a static graph.

NOTE (stacking): this diff sits on top of the in-review slice_copy op (D108793168); rebase onto it once that op lands on master.

Co-authored-with: Claude Code.
@exported-using-ghexport

Differential Revision: D109906092

Differential Revision: D109906092

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

@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 Jun 28, 2026
@JulianCloudNTH

Copy link
Copy Markdown
Contributor Author

@claude review and check for any areas or opportunities for modularization

@claude

claude Bot commented Jun 29, 2026

Copy link
Copy Markdown

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

@SS-JIA SS-JIA 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.

Review automatically exported from Phabricator review in Meta.

[ghstack-poisoned]
[ghstack-poisoned]
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants