Commit 0582b6b
[torchlib] Implement aten__upsample_bicubic2d_aa and aten__upsample_bilinear2d_aa functions (#2383)
This PR implements the missing anti-aliasing (AA) variants of upsample
functions that were requested in issue #1159:
- `aten__upsample_bicubic2d_aa` - bicubic 2D upsampling with
anti-aliasing
- `aten__upsample_bilinear2d_aa` - bilinear 2D upsampling with
anti-aliasing
## Changes Made
### Core Implementation
- **Modified helper functions** to support anti-aliasing:
- Added `antialias` parameter (default=0) to
`_aten_upsample_output_size()`
- Added `antialias` parameter (default=0) to `_aten_upsample_scales()`
- Maintains backward compatibility with existing code
- **Implemented AA functions** with same signatures as regular variants:
```python
def aten__upsample_bicubic2d_aa(self, output_size, align_corners,
scales_h=None, scales_w=None)
def aten__upsample_bilinear2d_aa(self, output_size, align_corners,
scales_h=None, scales_w=None)
```
Both functions pass `antialias=1` to enable ONNX Resize anti-aliasing.
### Test Configuration
- **Added OpInfo entries** in `extra_opinfo.py` for both AA functions
- **Added TorchLibOpInfo entries** in `ops_test_data.py` with
`compare_shape_only_for_output=(0,)` since ONNX and PyTorch use
different anti-aliasing algorithms
## Technical Details
The AA variants use the same underlying logic as regular upsample
functions but enable anti-aliasing in the ONNX Resize operation. As
noted in the original issue discussion, ONNX and PyTorch implement
different anti-aliasing methods, so tests compare shapes rather than
exact values.
Example usage:
```python
import numpy as np
from onnxscript.function_libs.torch_lib.ops.nn import aten__upsample_bicubic2d_aa
# Create test input
input_tensor = np.array([[[[2,1,1,1], [1,1,1,1], [1,1,1,1], [1,1,1,1]]]]).astype(np.float32)
output_size = np.array([1,1]).astype(np.int64)
# Use AA upsampling
result = aten__upsample_bicubic2d_aa(input_tensor, output_size, align_corners=True)
print(result) # Output: [[[[1.390625]]]]
```
## Testing Results
- ✅ All new AA function tests pass (2 passed, 1 skipped as expected for
trace-only functions)
- ✅ All existing upsample function tests continue to pass - no
regressions
- ✅ Functions produce expected different output when AA is enabled vs
disabled
- ✅ Helper functions work correctly with both `antialias=0` and
`antialias=1`
This implementation matches the approach from the previous PR #1259 and
completes the upsample function suite requested in the issue.
Fixes #1159. Fixes pytorch/pytorch#128818
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: titaiwangms <18010845+titaiwangms@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>1 parent 59340c6 commit 0582b6b
3 files changed
Lines changed: 84 additions & 0 deletions
File tree
- onnxscript/function_libs/torch_lib/ops
- tests/function_libs/torch_lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2317 | 2317 | | |
2318 | 2318 | | |
2319 | 2319 | | |
| 2320 | + | |
2320 | 2321 | | |
2321 | 2322 | | |
2322 | 2323 | | |
| |||
2333 | 2334 | | |
2334 | 2335 | | |
2335 | 2336 | | |
| 2337 | + | |
2336 | 2338 | | |
2337 | 2339 | | |
2338 | 2340 | | |
| |||
2341 | 2343 | | |
2342 | 2344 | | |
2343 | 2345 | | |
| 2346 | + | |
2344 | 2347 | | |
2345 | 2348 | | |
2346 | 2349 | | |
| |||
2352 | 2355 | | |
2353 | 2356 | | |
2354 | 2357 | | |
| 2358 | + | |
2355 | 2359 | | |
2356 | 2360 | | |
2357 | 2361 | | |
| |||
2376 | 2380 | | |
2377 | 2381 | | |
2378 | 2382 | | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
2379 | 2405 | | |
2380 | 2406 | | |
2381 | 2407 | | |
| |||
2438 | 2464 | | |
2439 | 2465 | | |
2440 | 2466 | | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
2441 | 2489 | | |
2442 | 2490 | | |
2443 | 2491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2589 | 2589 | | |
2590 | 2590 | | |
2591 | 2591 | | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
2592 | 2599 | | |
2593 | 2600 | | |
2594 | 2601 | | |
| |||
2603 | 2610 | | |
2604 | 2611 | | |
2605 | 2612 | | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
2606 | 2620 | | |
2607 | 2621 | | |
2608 | 2622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1934 | 1934 | | |
1935 | 1935 | | |
1936 | 1936 | | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
1937 | 1948 | | |
1938 | 1949 | | |
1939 | 1950 | | |
| |||
1946 | 1957 | | |
1947 | 1958 | | |
1948 | 1959 | | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
1949 | 1971 | | |
1950 | 1972 | | |
1951 | 1973 | | |
| |||
0 commit comments