[ExecuTorch][WebGPU] Add optimized gelu op#20843
Open
JCNTH wants to merge 3 commits into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20843
Note: Links to docs will display an error until the docs builds have been completed. ❌ 57 New Failures, 2 Unrelated Failures, 7 Unclassified FailuresAs of commit 85c5a81 with merge base c2b273e ( 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:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
This was referenced Jul 10, 2026
[ExecuTorch][WebGPU] Add relu op (shared unary handler; sigmoid adopts make_compute_pipeline)
#20863
Open
This was referenced Jul 10, 2026
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Adds the
geluactivation to the WebGPU backend. GELU is the feed-forward (MLP) activation in the vision and VLM transformer blocks this backend targets — the Florence-2 DaViT encoder, BART, and the Whisper/Voxtral stacks — so it is on the critical path for delegating those models without graph breaks.Problem — The WebGPU backend had no
aten.gelu.defaultkernel, so any model whose FFN uses GELU could not be fully delegated. PyTorch's default is the exact (erf) formulation, and the target encoders use it; the tanh approximation must also be supported.Solution
aten.gelu.defaultwas unsupported — no kernel, forcing a partition break around every GELU.gelu.wgslcomputes GELU on the GPU. The exact (erf) vs tanh choice is resolved by compiling the matching entry point (main_erf/main_tanh) into the pipeline, so each dispatch runs only its own formula — no per-invocationselect()and no double-eval of both branches.Implementation
select()-guarded scalar reads, computes GELU as onevec4<f32>op, and scatters back only the in-bounds lanes — so arbitrary FFN widths that are not a multiple of 4 are handled without a separate remainder pass.0.5*x*(1+tanh(...))form.approximatearg (args[1]: "none" selects erf, anything else selects tanh) picks the entry point at build time through the sharedutils::make_compute_pipeline; workgroup size comes fromutils::clamp_workgroup_size, the dispatch count fromutils::compute_1d_workgroup_count, and the uniform fromutils::make_uniform.backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp(itsgeluhandler; args[1] is theapproximatestring). Note the WebGPU kernel additionally implements the exact/erf path, which the Vulkan handler does not currently support.Constraints — fp32 only (both operands must be 4-byte aligned, enforced in the handler); input and output must have identical byte size; 1D dispatch only (throws if the workgroup count would exceed the 65535 cap). Element count need not be a multiple of 4 (scalar tail); static shape (no resize hook).
Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D110836674
Differential Revision: D110836674