[ExecuTorch][WebGPU] Add embedding op#20853
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/20853
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 2bf50ae 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):
fp32
aten.embedding.defaultnow runs on the WebGPU backend as a row-gather, so the BART token and positional embedding lookups in Florence-2 execute on-device. This was the remaining attention-stack op that AOT-delegated but had no WebGPU runtime kernel.Problem — The WebGPU backend had no
aten.embedding.defaultkernel. The op partitions into the delegate at export, but with no registered handler the graph failed at runtime load, blocking the BART embedding lookup.Solution — Before:
aten.embedding.defaulthad no runtime kernel (load-time failure). After: the handler binds the fp32weight, the int32indices, and the output, then dispatches a plain gather computingout[row, col] = weight[indices[row], col]. Forward embedding is exactly this row gather; thepadding_idx/scale_grad_by_freq/sparseargs only affect the backward pass and are ignored.Implementation —
embedding.wgslruns one thread per output element: from the linearglobal_invocation_id,row = idx / embed_dimandcol = idx % embed_dim, thentoken = u32(t_indices[row])andt_out[idx] = t_weight[token*embed_dim + col], with an earlyidx >= num_elementsguard. Dispatch is 1D: the workgroup size is clamped to the device limit viautils::clamp_workgroup_sizeand the count computed by the sharedutils::compute_1d_workgroup_count(which throws if the count exceeds the device's per-dimension limit), passed to the shader through awg_sizeoverride constant. Uses the sharedutils::make_compute_pipelineandutils::make_uniform(16-byteEmbeddingParams {embed_dim, num_elements}). Because the backend carries no runtime dtype, per-type byte guards enforce int32indicesand fp32weight/out. Mirrors Vulkanbackends/vulkan/runtime/graph/ops/impl/Embedding.cpp(add_embedding_node: a plain buffer row-gather registered foraten.embedding.default).Constraints — fp32
weight/out, int32indices(the backend's index convention, matchingindex.wgsl/embedding_q4gsw), enforced by byte-size guards;weightmust be at least 2D with its last dim equal to the outputembed_dim; 1D dispatch capped at the device's per-dimension workgroup limit.Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D110836667
Differential Revision: D110836667