Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] Add support for onnx.Resize with nearest_mode "round_prefer_floor" and "round_prefer_ceil" #3420

Closed
flemairen6 opened this issue Jun 5, 2024 · 6 comments

Comments

@flemairen6
Copy link

Currently the torchOnnxToTorch pass seems to only support nearest mode with floor.

@vivekkhandelwal1
Copy link
Collaborator

Assigned to @aldesilv

@ttjost
Copy link
Contributor

ttjost commented Jun 6, 2024

Thanks for working on it. What about ceil mode?

@aldesilv
Copy link
Contributor

aldesilv commented Jun 7, 2024

#3421

@zjgarvey
Copy link
Collaborator

zjgarvey commented Jun 7, 2024

The referenced PR just got merged. Here is a status update, so please let us know if any of the currently unsupported features are needed by your team. @flemairen6

I'm going to do some E2E testing and put up a report today to see if we are running into any numerical issues with the supported configurations below.

Resize Status:

Currently Supported:

  • mode == "nearest":
    &: nearest_mode is one of "floor", "ceil", "round_prefer_floor", "round_prefer_ceil"
    &: coordinate_transformation_mode == "asymmetric"
    &: 1,2, or 3 spatial dims

  • mode == "linear":
    &: coordinate_transformation_mode is one of "align_corners", "asymmetric", "pytorch_half_pixel", "half_pixel"
    &: 2 spatial dims.

Currently Unsupported:

  • coordinate_transformation_mode == "tf_crop_and_resize"
  • coordinate_transformation_mode == "half_pixel_symmetric".
    Note: It looks like we aren't producing a match failure in this case, so we should add support for mode = "linear" and coordTfMode = "half_pixel_symmetric" as soon as possible. @aldesilv Do you want to take a look? Edit: see comment below.
  • mode = "linear" with 1 or 3 spatial dims.
  • mode = "nearest" with coordinate_transformation_mode != "asymmetric".

@zjgarvey
Copy link
Collaborator

zjgarvey commented Jun 8, 2024

A few notes after doing some e2e testing via the iree_tests:

  1. all nearest_modes that are ceil-related have some issues along the back-edge where ceil would result in an index > (input_size - 1). E.G.:
_______________________________________________________________________________________________ IREE compile and run: test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric::cpu_llvm_sync_test ________________________________________________________________________________________________
Error invoking iree-run-module
Error code: 1
Stderr diagnostics:

Stdout diagnostics:
EXEC @test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric
[FAILED] result[0]: element at index 7 (5) does not match the expected (4); expected that the view is equal to contents of a view of 1x1x8x8xf32
  expected:
1x1x8x8xf32=[[[1 2 2 3 3 4 4 4][5 6 6 7 7 8 8 8][5 6 6 7 7 8 8 8][9 10 10 11 11 12 12 12][9 10 10 11 11 12 12 12][13 14 14 15 15 16 16 16][13 14 14 15 15 16 16 16][13 14 14 15 15 16 16 16]]]
  actual:
1x1x8x8xf32=[[[1 2 2 3 3 4 4 5][5 6 6 7 7 8 8 9][5 6 6 7 7 8 8 9][9 10 10 11 11 12 12 13][9 10 10 11 11 12 12 13][13 14 14 15 15 16 16 0][13 14 14 15 15 16 16 0][0 0 0 1.35926E-43 1.35926E-43 0 0 1.4013E-45]]]

Compiled with:
  cd /home/zjgar/code/SHARK-TestSuite/iree_tests/onnx/node/generated/test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric && iree-compile model.mlir --iree-hal-target-backends=llvm-cpu -o model_cpu_llvm_sync_test.vmfb

Run with:
  cd /home/zjgar/code/SHARK-TestSuite/iree_tests/onnx/node/generated/test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric && iree-run-module --module=model_cpu_llvm_sync_test.vmfb --device=local-sync --flagfile=test_data_flags.txt
  1. there seems to be some numerical error with a linear test using align_corners:
______________________________________________________________________________________________________ IREE compile and run: test_resize_downsample_scales_linear_align_corners::cpu_llvm_sync_test ______________________________________________________________________________________________________
Error invoking iree-run-module
Error code: 1
Stderr diagnostics:

Stdout diagnostics:
EXEC @test_resize_downsample_scales_linear_align_corners
[FAILED] result[0]: element at index 1 (4) does not match the expected (3.14286); expected that the view is equal to contents of a view of 1x1x1x2xf32
  expected:
1x1x1x2xf32=[[[1 3.14286]]]
  actual:
1x1x1x2xf32=[[[1 4]]]

Compiled with:
  cd /home/zjgar/code/SHARK-TestSuite/iree_tests/onnx/node/generated/test_resize_downsample_scales_linear_align_corners && iree-compile model.mlir --iree-hal-target-backends=llvm-cpu -o model_cpu_llvm_sync_test.vmfb

Run with:
  cd /home/zjgar/code/SHARK-TestSuite/iree_tests/onnx/node/generated/test_resize_downsample_scales_linear_align_corners && iree-run-module --module=model_cpu_llvm_sync_test.vmfb --device=local-sync --flagfile=test_data_flags.txt
  1. coordTfMode half_pixel_symmetric indeed causes a crash, so this should be fixed.

@zjgarvey
Copy link
Collaborator

The referenced PR #3443 addresses these two issues:

  1. all nearest_modes that are ceil-related have some issues along the back-edge where ceil would result in an index > (input_size - 1). E.G.:
  1. coordTfMode half_pixel_symmetric indeed causes a crash, so this should be fixed.

I'm still looking into the align_corners issue, since it seems like our calculation "does what it should" in this case. I'll try doing some more testing to confirm whether this test is giving the correct golden output.

Other updates:

#3441 Adds support for nearest mode with coordinate_transformation_mode = half_pixel (thanks @mgehre !)

zjgarvey added a commit that referenced this issue Jun 12, 2024
…3443)

This patch fixes several failing tests in our [external test
suite](https://github.com/nod-ai/SHARK-TestSuite/tree/main/iree_tests/onnx/node/generated),
and addresses some of the issues discussed in #3420
mgehre-amd pushed a commit to Xilinx/torch-mlir that referenced this issue Jun 12, 2024
…lvm#3443)

This patch fixes several failing tests in our [external test
suite](https://github.com/nod-ai/SHARK-TestSuite/tree/main/iree_tests/onnx/node/generated),
and addresses some of the issues discussed in llvm#3420
@zjgarvey zjgarvey closed this as completed Sep 3, 2024
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

No branches or pull requests

5 participants