Skip to content

[ExecuTorch][WebGPU] Fuse the SwiGLU elementwise chain#21129

Open
JCNTH wants to merge 4 commits into
gh/JCNTH/105/basefrom
gh/JCNTH/105/head
Open

[ExecuTorch][WebGPU] Fuse the SwiGLU elementwise chain#21129
JCNTH wants to merge 4 commits into
gh/JCNTH/105/basefrom
gh/JCNTH/105/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The SwiGLU feed-forward activation lowered to separate gate and up projections
followed by a sigmoid and two elementwise multiplies, launching several
dispatches over the same tensors. This fuses the sigmoid and the two multiplies
into a single dynamically-resized 2D dispatch that computes
(gate * sigmoid(gate)) * up in one pass. Fusion applies only when the pattern
is exact and its scratch is planner-owned; graph outputs, extra consumers, and
separate inputs fall back to the unfused chain, and the landed broad-QKV
behavior is left untouched until its dedicated corrective diff. No Vulkan
analogue: the Vulkan backend has no fused SiLU/SwiGLU shader and composes it
from a sigmoid unary op plus an elementwise multiply at graph level.

Key changes:

  • runtime/ops/mul/silu_mul_fused.wgsl (+ generated header): one-thread-per-
    element SiLU-gated multiply of gate and up into a single output.
  • WebGPUGraph.cpp: detect the exact gate/up/sigmoid/mul pattern, own the gate
    scratch, size the 2D dispatch, and fall back conservatively.
    @exported-using-ghexport

Differential Revision: D113171742

Differential Revision: D113171742

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 Cancelled Job

As of commit de7106f with merge base 86c3470 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

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.

[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.

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.

2 participants