[ExecuTorch][WebGPU] Add upsample_nearest2d op#20859
Open
JCNTH wants to merge 4 commits into
Open
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20859
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 990f2f3 with merge base c2b273e ( 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 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
aten.upsample_nearest2d.vecto the WebGPU backend, enabling the SAM2/SAM3 pixel-decoder / FPN nearest-neighbour upsample path.Problem — nearest-neighbour 2D upsample (
F.interpolate(..., mode="nearest")) had no WebGPU kernel, blocking the FPN 2x upsample chain in the SAM2/SAM3 pixel decoder.Solution — Before — no handler;
aten.upsample_nearest2d.vecunsupported. After — one thread per output element(n, c, oh, ow)maps back to its nearest source pixel and copies it.Implementation:
ih = floor(oh*IH/OH),iw = floor(ow*IW/OW)(integer division), then copiesinp[((n*C+c)*IH+ih)*IW+iw]— a plain NCHW row-major gather, bit-exact.OH/OWare taken from the output tensor's own dims (not re-derived from thesize/scaleargs), and the handler validates thatN/Cmatch between input and output.utils::compute_dispatch_grid(workgroup size clamped to the device max, up to 256, plus a 2D spill past the 65535 ceiling;stride_xdecode).backends/vulkan/runtime/graph/ops/impl/Upsample.cpp, which computes the source index with the half-pixel-center reciprocal-scale formula. Half-pixel-center is correct for bilinear but wrong for non-exact nearest; the ATennearest_neighbor_compute_source_index(UpSample.h)floor(oh*IH/OH)form is the one that matches PyTorch'smode="nearest". The two agree on exact-integer ratios (e.g. 2x) but diverge on non-integer ratios (e.g. 5->8), which the op-test'snon_2x_ratiocase pins down.Constraints — fp32 only; 4D NCHW input and output;
nearestmode only; non-zero spatial dims; the output element count must fitu32.Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D110836668
Differential Revision: D110836668