Skip to content

Commit 18280e0

Browse files
Fix upsample half pixel mode for size one (#2918)
Fixes the ATen upsampling lowering for `align_corners=False` to use ONNX `half_pixel` mode instead of `pytorch_half_pixel`. `pytorch_half_pixel` special-cases output size 1 differently from PyTorch eager behavior, causing mismatches for cases like `upsample_bilinear2d(..., output_size=(1, 1), align_corners=False)`. This change makes the exported `Resize` node match PyTorch results for that edge case. Adds regression samples for 2D upsampling with output size 1, covering both `upsample_bilinear2d` and `upsample_bilinear2d.vec`.
1 parent 33d1445 commit 18280e0

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

onnxscript/function_libs/torch_lib/ops/nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ def aten_unflatten_dense_tensors(
23202320

23212321

23222322
def _get_upsample_align_corners_mode(align_corners: bool) -> str:
2323-
return "align_corners" if align_corners else "pytorch_half_pixel"
2323+
return "align_corners" if align_corners else "half_pixel"
23242324

23252325

23262326
def _aten_upsample_output_size(

tests/function_libs/torch_lib/extra_opinfo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,9 @@ def shape(size, rank, with_batch_channel=True):
18871887
yield opinfo_core.SampleInput(make_arg(shape(D, rank)), shape(SS, rank, False), True)
18881888

18891889
for align_corners in align_corners_options:
1890+
yield opinfo_core.SampleInput(
1891+
make_arg(shape(D, rank)), shape(1, rank, False), align_corners
1892+
)
18901893
yield opinfo_core.SampleInput(
18911894
make_arg(shape(D, rank)), shape(S, rank, False), align_corners
18921895
)
@@ -1934,6 +1937,9 @@ def shape(size, rank, with_batch_channel=True):
19341937
yield opinfo_core.SampleInput(make_arg(shape(D, rank)), shape(SS, rank, False), True, None)
19351938

19361939
for align_corners in align_corners_options:
1940+
yield opinfo_core.SampleInput(
1941+
make_arg(shape(D, rank)), shape(1, rank, False), align_corners, None
1942+
)
19371943
yield opinfo_core.SampleInput(
19381944
make_arg(shape(D, rank)), shape(S, rank, False), align_corners, None
19391945
)

0 commit comments

Comments
 (0)