Skip to content

Add torch upsample_bicubic2d lowering (incl. antialias variant) - #2818

Open
SakshamKapoor2911 wants to merge 2 commits into
apple:mainfrom
SakshamKapoor2911:feat/pr1747-bicubic-upsample
Open

Add torch upsample_bicubic2d lowering (incl. antialias variant)#2818
SakshamKapoor2911 wants to merge 2 commits into
apple:mainfrom
SakshamKapoor2911:feat/pr1747-bicubic-upsample

Conversation

@SakshamKapoor2911

@SakshamKapoor2911 SakshamKapoor2911 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Torch frontend lowering for upsample_bicubic2d / upsample_bicubic2d.vec (Keys cubic, a=-0.75).
  • Implement the antialias variants _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 torchvision Resize(..., InterpolationMode.BICUBIC) emits by default.
  • Decompose the separable cubic convolution into existing MIL ops (gather + stack + broadcast mul + reduce_sum), one pass per spatial axis, with tap indices and weights precomputed as constants for static input shapes.
  • Support align_corners, output_size, and scale_factor / recompute_scale_factor argument forms across TorchScript and TorchExport frontends.
  • Add TestUpsample tests for all four op variants.

Fixes #1747.
Also closes #2340 (BICUBIC resizing).

Testing

Local Linux neuralnetwork conversion/structure tests:

PYMIL_TEST_TARGETS=neuralnetwork INCLUDE_MIL_FP32_UNIT_TESTS=1 python -m pytest coremltools/converters/mil/frontend/torch/test/test_torch_ops.py::TestUpsample -q

Result: full TestUpsample class 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).

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')
@TobyRoseman

Copy link
Copy Markdown
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.
@SakshamKapoor2911

SakshamKapoor2911 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@TobyRoseman Thanks for triggering the CI pipeline!

I diagnosed the failure in test_py310_pytorch_executorch: torch.export emits aten._upsample_bicubic2d_aa.default for antialiased bicubic, which is not in the Core ATen opset and has no core ATen decomposition in PyTorch. During ExecuTorch export (executorch.exir.to_edge()), EXIRATenDialectVerifier strictly verifies ops against Core ATen, raising SpecViolationError.

Pushed commit b2b0e3b3 adding the standard pytest.skip guard for TorchFrontend.EXECUTORCH on the two antialiased test functions, matching the repository's established convention for non-canonical ATen ops in test_torch_ops.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support BICUBIC interpolation for image resizing Implement PyTorch op upsample_bicubic2d

2 participants