Skip to content

[ExecuTorch][WebGPU] Add batch_norm op#20993

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

[ExecuTorch][WebGPU] Add batch_norm op#20993
JCNTH wants to merge 2 commits into
gh/JCNTH/97/basefrom
gh/JCNTH/97/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Add aten._native_batch_norm_legit_no_training.default to the WebGPU backend — inference batch norm on MODNet's decoder and CNN backbones.

Problem: The WebGPU delegate had no batch-norm handler, so MODNet (background removal) and other CNN models could not fully delegate to the GPU.

Solution: A 4D NCHW fp32 kernel applying the per-channel inference affine y = (x - running_mean) / sqrt(running_var + eps) * weight + bias. weight/bias are optional (affine=False → unit scale / zero shift), bound via utils::make_optional_binding with a dummy buffer when absent.

Implementation:

  • runtime/ops/batch_norm/{BatchNorm.cpp,batch_norm.wgsl,batch_norm_wgsl.h} registering aten._native_batch_norm_legit_no_training.default; uses utils::make_compute_pipeline + utils::make_optional_binding.
  • Multi-output op: reads the out entry of the output ValueList (save_mean/save_invstd unused in inference).
  • Mirrors the Vulkan _native_batch_norm_legit_no_training delegate.
  • CMake WEBGPU_SRCS entry.

Constraints: fp32-only, 4D in/out — throws on rank/shape/dtype mismatch (fail-loud); no change to existing ops.

Differential Revision: D112417288

[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/20993

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

❌ 57 New Failures, 4 Pending, 2 Unrelated Failures, 7 Unclassified Failures

As of commit 9608ba1 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:

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?

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 16, 2026
@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
[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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant