Skip to content

[Test][TFLite] Add unit tests for RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR ops#19365

Merged
tlopex merged 3 commits intoapache:mainfrom
OmarAzizi:test/tflite-resize-ops
Apr 7, 2026
Merged

[Test][TFLite] Add unit tests for RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR ops#19365
tlopex merged 3 commits intoapache:mainfrom
OmarAzizi:test/tflite-resize-ops

Conversation

@OmarAzizi
Copy link
Copy Markdown
Contributor

@OmarAzizi OmarAzizi commented Apr 6, 2026

Partially closes #18971.

Add parametrized unit tests for RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR following the existing verify() + tf.Module pattern in the file.

Tests added (13 total)

RESIZE_BILINEAR (7 cases via test_resize_bilinear)

Case Input shape Output size coordinate_transformation_mode
upsample, default (1, 4, 4, 1) 8×8 half_pixel
downsample, default (1, 8, 8, 3) 4×4 half_pixel
align_corners (1, 4, 4, 1) 7×7 align_corners
half_pixel_centers (1, 4, 4, 2) 8×8 half_pixel
multichannel / batch > 1 (2, 6, 6, 16) 12×12 half_pixel
identity (1, 5, 5, 3) 5×5 half_pixel
non-square (1, 4, 8, 1) 8×16 half_pixel

RESIZE_NEAREST_NEIGHBOR (6 cases via test_resize_nearest_neighbor)

Case Input shape Output size coordinate_transformation_mode rounding_method
upsample, default (1, 2, 2, 1) 4×4 half_pixel round_prefer_ceil
downsample, default (1, 8, 8, 3) 4×4 half_pixel round_prefer_ceil
align_corners (1, 4, 4, 1) 7×7 align_corners ""
multichannel / batch > 1 (4, 3, 3, 8) 6×6 half_pixel round_prefer_ceil
non-square (1, 4, 8, 1) 8×16 half_pixel round_prefer_ceil
identity (1, 3, 3, 2) 3×3 half_pixel round_prefer_ceil

Implementation notes

  • Expected modules are built programmatically via relax.BlockBuilder rather than TVMScript — the TVMScript parser does not accept runtime variables in type annotations, which would be required inside a parametrized test.
  • All 13 new tests pass.
  • test_fill, test_batch_matmul, and test_batch_matmul_adj were already failing on unmodified main before this PR. No regressions introduced.
  • Tested with Python 3.10.20, TensorFlow 2.9.0, NumPy 1.26.4.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds comprehensive unit tests for TFLite resize operations (bilinear and nearest neighbor) in the Relax frontend. It introduces a helper function, _make_resize_expected, to programmatically generate expected IRModules for verification. The review feedback highlights an unused import (tirx as T) and an unused variable (out_shape) in the helper function that should be removed to improve code quality.

from tvm.relax.frontend.tflite import from_tflite
from tvm.script.parser import ir as I
from tvm.script.parser import relax as R
from tvm.script.parser import tirx as T
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The import of tirx as T is added but appears to be unused in the current file. To maintain code cleanliness and avoid unnecessary dependencies in the test module, it should be removed if not required for future planned changes in this PR.


def _make_resize_expected(input_shape, output_size, method, coordinate_transformation_mode, rounding_method):
"""Build an Expected IRModule programmatically to avoid TVMScript variable scope limitations."""
out_shape = (input_shape[0], output_size[0], output_size[1], input_shape[3])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable out_shape is calculated but never used within the _make_resize_expected function. Removing unused variables improves code readability and maintainability.

Copy link
Copy Markdown
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlopex tlopex merged commit 072c849 into apache:main Apr 7, 2026
9 checks passed
@tlopex
Copy link
Copy Markdown
Member

tlopex commented Apr 7, 2026

Hi @OmarAzizi , Just a small note: please avoid using phrases like Partially closes #18971 in the PR description, because GitHub may still treat that as a closing keyword and auto-close the tracking issue.
Safer alternatives are things like Part of #18971, Related to #18971, or Addresses part of #18971. In this way I don't need to open it again:)

@OmarAzizi
Copy link
Copy Markdown
Contributor Author

@tlopex Noted, thank you for letting me know

@OmarAzizi OmarAzizi deleted the test/tflite-resize-ops branch April 8, 2026 11:11
Aharrypotter pushed a commit to Aharrypotter/tvm that referenced this pull request Apr 10, 2026
…NEIGHBOR ops (apache#19365)

Partially closes apache#18971.

Add parametrized unit tests for `RESIZE_BILINEAR` and
`RESIZE_NEAREST_NEIGHBOR` following the existing `verify()` +
`tf.Module` pattern in the file.

## Tests added (13 total)

### `RESIZE_BILINEAR` (7 cases via `test_resize_bilinear`)
| Case | Input shape | Output size | `coordinate_transformation_mode` |
|------|-------------|-------------|----------------------------------|
| upsample, default | `(1, 4, 4, 1)` | `8×8` | `half_pixel` |
| downsample, default | `(1, 8, 8, 3)` | `4×4` | `half_pixel` |
| align_corners | `(1, 4, 4, 1)` | `7×7` | `align_corners` |
| half_pixel_centers | `(1, 4, 4, 2)` | `8×8` | `half_pixel` |
| multichannel / batch > 1 | `(2, 6, 6, 16)` | `12×12` | `half_pixel` |
| identity | `(1, 5, 5, 3)` | `5×5` | `half_pixel` |
| non-square | `(1, 4, 8, 1)` | `8×16` | `half_pixel` |

### `RESIZE_NEAREST_NEIGHBOR` (6 cases via
`test_resize_nearest_neighbor`)
| Case | Input shape | Output size | `coordinate_transformation_mode` |
`rounding_method` |

|------|-------------|-------------|----------------------------------|-------------------|
| upsample, default | `(1, 2, 2, 1)` | `4×4` | `half_pixel` |
`round_prefer_ceil` |
| downsample, default | `(1, 8, 8, 3)` | `4×4` | `half_pixel` |
`round_prefer_ceil` |
| align_corners | `(1, 4, 4, 1)` | `7×7` | `align_corners` | `""` |
| multichannel / batch > 1 | `(4, 3, 3, 8)` | `6×6` | `half_pixel` |
`round_prefer_ceil` |
| non-square | `(1, 4, 8, 1)` | `8×16` | `half_pixel` |
`round_prefer_ceil` |
| identity | `(1, 3, 3, 2)` | `3×3` | `half_pixel` | `round_prefer_ceil`
|

## Implementation notes

- `Expected` modules are built programmatically via `relax.BlockBuilder`
rather than TVMScript — the TVMScript parser does not accept runtime
variables in type annotations, which would be required inside a
parametrized test.
- All 13 new tests pass.
- `test_fill`, `test_batch_matmul`, and `test_batch_matmul_adj` were
already failing on unmodified `main` before this PR. No regressions
introduced.
- Tested with Python 3.10.20, TensorFlow 2.9.0, NumPy 1.26.4.
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.

[Tracking Issue][TFLite] Expand unit test coverage for supported non-quantized operators

2 participants