Skip to content

[ExecuTorch][WebGPU] Add aten.sub.Tensor with TensorMeta broadcast#20985

Open
JCNTH wants to merge 2 commits into
gh/JCNTH/89/basefrom
gh/JCNTH/89/head
Open

[ExecuTorch][WebGPU] Add aten.sub.Tensor with TensorMeta broadcast#20985
JCNTH wants to merge 2 commits into
gh/JCNTH/89/basefrom
gh/JCNTH/89/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Add aten.sub.Tensor with TensorMeta broadcast

Problem: The WebGPU backend had no sub op. A flat modulo-tiled broadcast (the old rig add form) is wrong for a middle/spatial broadcast [N,C,1,1] — e.g. InstanceNorm's x - mean, where mean is [N,C,1,1] broadcast across H,W. A flat tiling cannot express that middle/spatial broadcast, so the result is numerically wrong.

Solution: Add aten.sub.Tensor mirroring mul's 3x TensorMeta UBO broadcast — the same-shape elementwise fast path plus an out-index relinearize on shape mismatch — with an alpha_ pipeline override constant so the kernel computes in1 - alpha_ * in2.

Implementation: runtime/ops/sub/binary_sub.wgsl + BinaryOp.cpp register aten.sub.Tensor. The handler fills three broadcast TensorMeta uniforms (out/in1/in2) and rebuilds them plus the dispatch on dynamic resize; alpha is read from the scalar arg and baked into the pipeline as the alpha_ override (fixed for the op's lifetime, so resize never rewrites it). Mirrors Vulkan aten.sub.Tensor / the mul op.

Constraints: fp32-only (every operand nbytes == numel * 4), rank <= 4 (NCHW).

Co-authored-with: Claude Code.

Differential Revision: D112378933

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 128 New Failures, 3 Unrelated Failures, 2 Unclassified Failures

As of commit 92ff4d3 with merge base c2b273e (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

  • Build documentation / build (buck2) / Build doc (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
  • Labeler / label (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 0C40:1722F:5849D96:59C3598:6A5960F7 and timestamp 2026-07-16 22:53:44 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service)

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

  • pull / unittest / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?
  • pull / unittest-editable / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?

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 Jul 16, 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.

This was referenced Jul 16, 2026
[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.

1 participant