Repository navigation
Add torch upsample_bicubic2d lowering (incl. antialias variant) - #2818
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')
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.
|
@TobyRoseman Thanks for triggering the CI pipeline! I diagnosed the failure in Pushed commit |
|
Thanks for addressing that. |
|
@TobyRoseman pipeline 2769937121 is fully green (12/12) on head |
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).