Skip to content
New issue

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

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

Already on GitHub? # to your account

Impossible to import ONNX model #2592

Open
anagaev opened this issue Dec 5, 2024 · 4 comments
Open

Impossible to import ONNX model #2592

anagaev opened this issue Dec 5, 2024 · 4 comments
Labels
bug Something isn't working onnx

Comments

@anagaev
Copy link

anagaev commented Dec 5, 2024

Hi all!

I tried to use an .onnx model from Hugging Face with burn when I found this potential issues.

Describe the bug
One node (Where to be precise) throw error:

ERROR burn_import::logger: PANIC => panicked at crates/onnx-ir/src/dim_inference.rs:821:5:
assertion `left == right` failed: Where x and y have different element types!
  left: Int64
 right: Float32

After debugging I found that one of the previous node ( Unsqueeze ) took two Int64 input arguments and return a Float32 tensor. So, it causes the error above and doesn't correspond to onnx graph from Netron.

To Reproduce

  1. Download the .onnx model from HuggingFace (also tried with this model)
  2. Following instruction for Importing ONNX Models in Burn
  3. Build the project and see the error.

Expected behavior
Correct import from .onnx files.

Screenshots
screeen

Desktop (please complete the following information):

  • OS: archlinux 6.12.1-arch1-1
  • Version: rustc 1.83.0
 [dependencies]
burn = "0.15.0"
burn-ndarray = "0.15.0"

[build-dependencies]
burn-import = "~0.15"

Potential fixing
It seems the type here which is default right now should match the type of the inputs.

@laggui laggui added bug Something isn't working onnx labels Dec 5, 2024
@anagaev
Copy link
Author

anagaev commented Dec 7, 2024

I think ArgType::Tensor(tensor) => tensor.elem_type.clone(), should be ArgType::Tensor(_) => node.inputs[1].ty.elem_type().clone(), here in order to match input type.

If it seems ok, I could do a pr.

Anyway, importing the onnx model doesn't work correctly even after this change because of another node (Slice). Output shape isn't correct.
@laggui would be better to continue discussion here or create a new bug report for Slice?

@laggui
Copy link
Member

laggui commented Dec 9, 2024

I think ArgType::Tensor(tensor) => tensor.elem_type.clone(), should be ArgType::Tensor(_) => node.inputs[1].ty.elem_type().clone(), here in order to match input type.

Hmm hat doesn't seem correct either, the node.inputs[1] doesn't represent the input data but rather the axis. But the output type should match the input type 🙂

If it seems ok, I could do a pr.

We're always opened to PRs!

Anyway, importing the onnx model doesn't work correctly even after this change because of another node (Slice). Output shape isn't correct. @laggui would be better to continue discussion here or create a new bug report for Slice?

We can keep the same issue open to represent your ONNX model.

I know there are many things that are far from perfect with the current ONNX import approach, but iirc @antimora was working on some improvements recently

@anagaev
Copy link
Author

anagaev commented Dec 9, 2024

@laggui thank you for your reply!
Ok, I'm continuing posting bug reports here
I thought node.inputs[0] was the axis... I'll check it again

@anagaev
Copy link
Author

anagaev commented Dec 12, 2024

A potential issue with Slice

Describe the bug
The output shape of the node Slice is always the same as the input shape. If the arguments starts, ends, steps are arbitrary, the output shape can differ.

To Reproduce

  1. Load a .onnx model with Slice node that return a smaller slice of the input data (e.g. each value of steps > 1). The model I mentioned above contains this Slice node.
  2. Following instruction for Importing ONNX Models in Burn
  3. Compare the output dimension and shape of this node from Netron and Burn.

Expected behavior
The node uses starts, ends, steps to correctly set the output shape.

Screenshots
2024-12-12_15-27

Desktop (please complete the following information):

  • OS: archlinux 6.12.1-arch1-1
  • Version: rustc 1.83.0

Additional context
This issue clearly affects inputs of ArgType::Shape. If I'm not mistaken, in this case all shapes and values (data, starts, ends, Optional(steps)) are defined. So, it's possible to correctly define the output shape during model building.
The shape of ArgType::Tensor is defined during runtime (correct me please, if I'm wrong). So, it's simply possible to set ArgType::Tensor.shape as None

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working onnx
Projects
None yet
Development

No branches or pull requests

2 participants