Vulkan: support zeros padding and align_corners=false in grid_sampler_2d - #22803
Open
msluszniak wants to merge 1 commit into
Open
msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
The shader implemented one configuration, the one RIFE's WarpModule uses: bilinear, border padding, align_corners=true. Every other configuration was rejected by the partitioner and fell back to CPU, including torch's own default of zeros padding with align_corners=false, which is what the deformable attention in DETR-derived detectors emits. Make padding_mode and align_corners specialization constants so the four supported combinations share one shader variant and each pipeline still compiles with the branches folded away. border clamps the sample coordinate, which pins the interpolation weights at the edge. zeros must not clamp: the weights stay as computed and an out-of-range corner contributes a zero value instead, so the two paths differ for any grid that leaves [-1, 1]. On an RF-DETR keypoint model this takes all 8 grid_sampler_2d calls off the host and the graph from 7 delegate blobs to 2.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22803
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
msluszniak
added a commit
to software-mansion-labs/executorch
that referenced
this pull request
Sep 15, 2026
Backport of pytorch/executorch#22803. grid_sampler_2d was gated to RIFE's config (bilinear/border/align_corners=true). RF-DETR needs zeros/false, and relaxing the gate takes its detector to 3 delegates / 3 host calls.
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.
Summary
grid_sampler_2dwas gated to a single configuration, the one RIFE'sWarpModuleuses: bilinear,borderpadding,align_corners=True. Everything else was rejected bycheck_grid_sampler_2d_nodeand fell back to CPU, including torch's own defaults (padding_mode="zeros",align_corners=False), which is what the deformable attention in DETR-derived detectors emits.Changes
padding_modeandalign_cornersbecome specialization constants, so the four supported combinations share one shader variant and each pipeline still compiles with the branches folded away. Reflection padding and nearest/bicubic interpolation remain unsupported and still fall back.The two padding paths are not interchangeable:
borderclamps the sample coordinate, which also pins the interpolation weights at the edge, whilezerosmust not clamp, because the weights stay as computed and each out-of-range corner contributes a zero value instead.Test
test_vulkan_backend_grid_sampler_2dcovers all four combinations with a grid deliberately overshooting to +/-1.6, so the zeros and border paths actually diverge; an in-range grid passes even with the padding branch broken.Also checked end to end on a Mali-G76 against eager PyTorch, max abs error 5.96e-08 (float32 eps) for each of the four configurations.
On an RF-DETR keypoint model this moves all 8
grid_sampler_2dcalls off the host, taking the graph from 7 delegate blobs and 11 host calls to 2 and 3.cc @SS-JIA @manuelcandales @digantdesai @cbilgin