Skip to content

ONNX "resize" op test failures #17345

Open

Description

@ScottTodd

What happened?

#17330 updates our LLVM and torch-mlir commits, pulling in llvm/torch-mlir#3013. Some tests are newly passing, many tests are still failing somewhere (compiler, runtime numerics), and a few tests are hanging on certain platforms.

At least CUDA is hanging on test_resize_downsample_scales_linear:
https://github.com/iree-org/iree/actions/runs/9034897378/job/24828864270?pr=17330#step:9:1813
I can't reproduce that on Windows though.

Steps to reproduce your issue

Generally follow the instructions at https://github.com/nod-ai/SHARK-TestSuite/tree/main/iree_tests and pull the config files from this repo.

For example, to run on CUDA:

pytest onnx/ -k test_resize -rA \
  --config-files=D:\dev\projects\iree\build_tools\pkgci\external_test_suite\onnx_gpu_cuda.json \
  --ignore-xfails

or Vulkan:

pytest onnx/ -k test_resize -rA \
  --config-files=D:\dev\projects\iree\build_tools\pkgci\external_test_suite\onnx_gpu_vulkan.json \
  --ignore-xfails
Config Logs
CPU https://gist.github.com/ScottTodd/0778165b2d31a54bfefbb9fa2b2662d6
CUDA https://gist.github.com/ScottTodd/dd34be6577da489f3d5b6b0a0a65ed0d
Vulkan https://gist.github.com/ScottTodd/b2f509585bee804ebd900e2144258241

Note that Vulkan has model.mlir:4:10: error: failed to legalize operation 'arith.fptosi' that was explicitly marked illegal

What component(s) does this issue relate to?

Frontends, Compiler, Runtime

Version information

No response

Additional context

No response

Activity

  1. added
    bug 🐞
    codegen/spirv
    integrations/pytorch
    on May 10, 2024
  2. bjacob commented on May 10, 2024

    @bjacob
    Collaborator

    FYI @AmosLewis this is the reason why llvm/torch-mlir#3013 was ultimately dropped from the integrate #17330.

  3. AmosLewis commented on May 10, 2024

    @AmosLewis
    Contributor

    FYI @AmosLewis this is the reason why llvm/torch-mlir#3013 was ultimately dropped from the integrate #17330.

    Will you start a new PR to bump it next? Do you have any idea is it a torch-mlir bug or is it an iree bug?

  4. ScottTodd commented on May 10, 2024

    @ScottTodd
    MemberAuthor
    • I suspect the Vulkan failed to legalize operation 'arith.fptosi' error is in upstream MLIR SPIRV (missing lowering)
    • Numerical errors in tests could be issues in the torch-mlir lowerings
    • CUDA hang ... no idea, couldn't get much from CI logs and couldn't reproduce on Windows. Maybe a miscompile (torch-mlir lowering) or runtime issue (IREE CUDA HAL), if compilation succeeded but the hang was a runtime.
  5. AmosLewis commented on May 10, 2024

    @AmosLewis
    Contributor

    nod-ai/AMD-SHARK-ModelDev#616 the model and failure resize mlir are listed in the description

  6. bjacob commented on May 10, 2024

    @bjacob
    Collaborator

    Will you start a new PR to bump it next?

    I don't plan to do it myself. We have an integration rotation schedule and the integrates of this week were already done out-of-schedule :-)

  7. ScottTodd commented on May 10, 2024

    @ScottTodd
    MemberAuthor

    We have a separate rotation for updating torch-mlir (in fact, @AmosLewis is up for next week 🤔). They are usually updated separately but needed to be updated together in this case.

  8. AmosLewis commented on May 12, 2024

    @AmosLewis
    Contributor
  9. added
    integrations/onnx
    on Aug 19, 2024
  10. zjgarvey commented on Feb 18, 2025

    @zjgarvey
    Contributor

    @ScottTodd , if it is okay with you, I'd like to re-use this thread to discuss the regressions: https://github.com/iree-org/iree/pull/19976/files#diff-bee4a6131cfebf0dfde5714b80c726dc145acc43b1c76e35e6447634f96071d1R238-R246

    Running these locally, I notice that the compilation fails on cpu due to

    model.mlir:4:10: error: failed to legalize operation 'arith.extf' that was explicitly marked illegal
        %0 = torch.operator "onnx.Resize"(%arg0, %none, %arg1) {torch.onnx.mode = "linear"} : (!torch.vtensor<[1,1,2,4],f32>, !torch.none, !torch.vtensor<[4],f32>) -> !torch.vtensor<[1,1,1,2],f32> 
             ^
    model.mlir:4:10: note: see current operation: %98 = "arith.extf"(%97) : (f32) -> f64
    

    This is introduced because of an assert added in llvm/torch-mlir#3945. This assert checks that scale values are exactly 1.0 for dimensions we expect to be non-spatial. Adding the assert is valuable to guard against unsupported configurations in the ONNX op; however, it seems to be causing some issues. Note: this regression doesn't affect models, since models will typically not have the scale input as a graph input (but rather an IR constant), and it will properly fold-out the asserts.

    Running this test without the flag --iree-input-demote-f64-to-f32=false in https://github.com/iree-org/iree-test-suites/blob/f8f2771c932322a2a813a51a9e6ef71ca7eb1f80/onnx_ops/configs/onnx_ops_cpu_llvm_sync.json#L5 will result in the tests passing, but I think we needed this flag for numeric issues in other tests.

  11. ScottTodd commented on Feb 18, 2025

    @ScottTodd
    MemberAuthor

    I can respond with some ideas briefly, without taking too big a context switch:

    • We could update the test suite to set --iree-input-demote-f64-to-f32=false for only tests that actually need f64 then let all other tests use the default of =true
    • Compiler asserts are generally pretty overused in MLIR, and possibly also torch-mlir. A valid program triggering an assert is a sign that the code is wrong, and that should be exceptionally rare. I haven't looked too closely at the runtime asserts added in that PR or related code, but the same general idea might apply there too.
    • We have some work ongoing to strip asserts by default in IREE, only adding them back when the users opts out of optimizations (-O1 vs -O2)
  12. zjgarvey commented on Feb 19, 2025

    @zjgarvey
    Contributor

    I can respond with some ideas briefly, without taking too big a context switch:

    * We could update the test suite to set `--iree-input-demote-f64-to-f32=false` for only tests that actually need f64 then let all other tests use the default of `=true`
    

    I think I'm going to try and fix the issue with f64 in the VM conversion if possible. That way we can just do f64 and call it a day.

    * Compiler asserts are generally pretty overused in MLIR, and possibly also torch-mlir. A valid program triggering an assert is a sign that the code is wrong, and that should be exceptionally rare. I haven't looked too closely at the runtime asserts added in that PR or related code, but the same general idea might apply there too.
    
    * We have some work ongoing to strip asserts by default in IREE, only adding them back when the users opts out of optimizations (`-O1` vs `-O2`)
    

    How do you suggest properly guarding against unsupported op configurations which can only be known at runtime? From my perspective, if an op is silently miscompiling (e.g. bad numerics), I'd much rather have an assert that I can grep for in the codebase.

  13. ScottTodd commented on Feb 19, 2025

    @ScottTodd
    MemberAuthor

    How do you suggest properly guarding against unsupported op configurations which can only be known at runtime?

    I'd prefer to handle such cases in application code, outside of the compiler and runtime. Ideally the entire "model" that the compiler is given will run on an accelerator, and error checking, handling, and propagation on accelerators is complicated and slow.

    Short of that, hoist the error checks up to the entry point of the model, rather than have individual operations deep down do their own checking. If a valid input to the program (as defined by what the entry point function accepts and allows to get passed further down) triggers an assert later, that's a bug in the program/compiler/runtime.

  14. benvanik commented on Feb 19, 2025

    @benvanik
    Collaborator

    We still need a new assert op - cf.assert is the worst possible op to be emitting in torch. The problem is not runtime checks but that torch is using cf.assert.

  15. benvanik commented on Feb 19, 2025

    @benvanik
    Collaborator

    oh, I didn't check what kind of asserts these are - a new op would help us with non-device-data-dependent ones - device-data-dependent asserts are always bad and should only be emitted if the user at the torch level explicitly asks for them. If you see any flow.tensor.load -> cf.assert dependency chains that's a massive red flag.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞codegen/spirvintegrations/onnxintegrations/pytorch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions