You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds aten.upsample_nearest2d.vec to 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.vec unsupported. After — one thread per output element (n, c, oh, ow) maps back to its nearest source pixel and copies it.
Implementation:
The kernel computes the source index with ATen's legacy nearest formula ih = floor(oh*IH/OH), iw = floor(ow*IW/OW) (integer division), then copies inp[((n*C+c)*IH+ih)*IW+iw] — a plain NCHW row-major gather, bit-exact.
OH/OW are taken from the output tensor's own dims (not re-derived from the size/scale args), and the handler validates that N/C match between input and output.
Adaptive 1D->2D dispatch via utils::compute_dispatch_grid (workgroup size clamped to the device max, up to 256, plus a 2D spill past the 65535 ceiling; stride_x decode).
Divergence from Vulkan (intentional): this does NOT mirror Vulkan 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 ATen nearest_neighbor_compute_source_index (UpSample.h) floor(oh*IH/OH) form is the one that matches PyTorch's mode="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's non_2x_ratio case pins down.
Constraints — fp32 only; 4D NCHW input and output; nearest mode only; non-zero spatial dims; the output element count must fit u32.
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"
meta-claBot
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 10, 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
CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
2 participants
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.
Differential Revision: D110836668