Add torch upsample_bicubic2d lowering (incl. antialias variant) - #2818
Open
SakshamKapoor2911 wants to merge 2 commits into
Open
Add torch upsample_bicubic2d lowering (incl. antialias variant)#2818SakshamKapoor2911 wants to merge 2 commits into
SakshamKapoor2911 wants to merge 2 commits into
Conversation
Implement upsample_bicubic2d / upsample_bicubic2d.vec / _upsample_bicubic2d_aa / _upsample_bicubic2d_aa.vec via a separable cubic convolution decomposition into existing MIL ops (gather, stack, mul, reduce_sum), with per-axis tap indices and weights precomputed as constants for static input shapes. The antialias variants (_aa) match the ATen implementation: Keys cubic kernel with a=-0.5, per-position normalized weights and a scale-dependent tap count (max_interp_size = ceil(2*max(scale,1))*2+1). Plain bicubic matches ATen's a=-0.75 kernel with 4 taps. Fixes apple#1747 (torchvision Resize with BICUBIC interpolation fails with 'PyTorch convert function for op _upsample_bicubic2d_aa not implemented')
Collaborator
PyTorch's torch.export on antialiased bicubic emits aten._upsample_bicubic2d_aa.default, which is not in Core ATen and has no core ATen decomposition in PyTorch. When running tests under TorchFrontend.EXECUTORCH, EXIRATenDialectVerifier rejects the op with SpecViolationError. Skip TorchFrontend.EXECUTORCH for the two antialiased bicubic test cases, matching the established convention across other non-canonical ATen ops in test_torch_ops.py.
Contributor
Author
|
@TobyRoseman Thanks for triggering the CI pipeline! I diagnosed the failure in Pushed commit |
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
upsample_bicubic2d/upsample_bicubic2d.vec(Keys cubic,a=-0.75)._upsample_bicubic2d_aa/_upsample_bicubic2d_aa.vec(PIL-compatible Keys cubic,a=-0.5, per-position normalized weights, scale-dependent tap count) — these are what torchvisionResize(..., InterpolationMode.BICUBIC)emits by default.gather+stack+ broadcastmul+reduce_sum), one pass per spatial axis, with tap indices and weights precomputed as constants for static input shapes.align_corners,output_size, andscale_factor/recompute_scale_factorargument forms across TorchScript and TorchExport frontends.TestUpsampletests for all four op variants.Fixes #1747.
Also closes #2340 (BICUBIC resizing).
Testing
Local Linux neuralnetwork conversion/structure tests:
Result: full
TestUpsampleclass passes (28 new bicubic cases; expected pre-existing XFAILs only).macOS native Core ML prediction parity (fork GHA smoke, mlprogram fp16 + fp32, TorchScript + TorchExport on macOS 14 / 15 / latest): 6/6 jobs, 56 tests each, all passing.
Numeric parity against PyTorch (fp32): max abs diff ≤ 3.3e-6 across a grid of plain/antialias × up/down-sampling × align_corners × output_size/scale_factor/torchvision paths, including the issue repro (112x112 → 336x336 torchvision Resize).