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 import issue: Reshape: shape tensor must be present for Node #2115

Open
SimonBrandner opened this issue Aug 5, 2024 · 7 comments
Open
Assignees
Labels
bug Something isn't working onnx

Comments

@SimonBrandner
Copy link

ERROR burn_import::logger: PANIC => panicked at /home/simon/.cargo/git/checkouts/burn-178c6829f420dae1/f7639bd/crates/onnx-ir/src/dim_inference.rs:814:15:
Only tensor input is valid but received: Shape(4)

Link to model: https://drive.google.com/file/d/1qgM6ZqMyB60FYlzzxNDyUefifLS0lhag/view?usp=sharing

@antimora antimora added onnx bug Something isn't working labels Aug 5, 2024
@SimonBrandner SimonBrandner changed the title Error importing the FaceONNX model landmarks_68_pfld: Only tensor input is valid but received: Shape(4) ONNX import issue: Only tensor input is valid but received: Shape(4) in gather_update_outputs() due to node.input[0] being Shape rather than Tensor Aug 5, 2024
@hexd0t
Copy link
Contributor

hexd0t commented Aug 7, 2024

c2b6318 switched to using ArgType::Shape for the output of the shapes-Operator instead of just using a 1D Tensor.

As far as I can tell, the ONNX Spec does not differentiate between Shapes and other 1D Tensors; each time an input or output argument contains a shape, the spec defines it as

1D tensor. The shape of the expected output tensor.

or similar.

Now, I can see 2 ways forward:

  • Differentiating Args that are a shape vs. just a random 1D Tensor might still be useful, but then other functions like gather need to also work on Shapes.
  • Or the Shape ArgType is dropped in favor of just using 1D Tensors everywhere they were used, aligning with how the ONNX spec does it.

Is there a way to know if many operators besides Gather are usually fed the output from the Shape Op?

@antimora
Copy link
Collaborator

antimora commented Aug 7, 2024

c2b6318 switched to using ArgType::Shape for the output of the shapes-Operator instead of just using a 1D Tensor.

As far as I can tell, the ONNX Spec does not differentiate between Shapes and other 1D Tensors; each time an input or output argument contains a shape, the spec defines it as

1D tensor. The shape of the expected output tensor.

or similar.

Now, I can see 2 ways forward:

  • Differentiating Args that are a shape vs. just a random 1D Tensor might still be useful, but then other functions like gather need to also work on Shapes.
  • Or the Shape ArgType is dropped in favor of just using 1D Tensors everywhere they were used, aligning with how the ONNX spec does it.

Is there a way to know if many operators besides Gather are usually fed the output from the Shape Op?

We started using Shape arg/input/output type. Please see my comment here in the PR: #1815 (comment)

Although ONNX spec does not differentiate types (scalar, shape, tensor are all the same), Burn and other frameworks do. Shape calculation will be a overkill if we use tensor ops because shape information is stored on CPU so it will require constant syncing from GPU device.

Our reshape onnx node can accept Shape arg type.

@SimonBrandner
Copy link
Author

After #2128 was merge this is now:

ERROR burn_import::logger: PANIC => panicked at /home/simon/.cargo/git/checkouts/burn-178c6829f420dae1/27ca6ce/crates/onnx-ir/src/dim_inference.rs:819:9:
Gather: indices tensor rank above 1 not supported    

@SimonBrandner SimonBrandner changed the title ONNX import issue: Only tensor input is valid but received: Shape(4) in gather_update_outputs() due to node.input[0] being Shape rather than Tensor ONNX import issue: Gather: indices tensor rank above 1 not supported in gather_update_outputs() Aug 8, 2024
@laggui
Copy link
Member

laggui commented Aug 8, 2024

Yeah the gather op translates to tensor.select(dim, indices) but the indices are expected to be 1d. There's a discrepancy between ONNX spec and the Burn tensor method.

@SimonBrandner
Copy link
Author

After be5eb91:

ERROR burn_import::logger: PANIC => panicked at /home/simon/.cargo/git/checkouts/burn-178c6829f420dae1/be5eb91/crates/burn-import/src/onnx/to_burn.rs:1245:18:
Can't transform scalar to tensor.    

@SimonBrandner SimonBrandner changed the title ONNX import issue: Gather: indices tensor rank above 1 not supported in gather_update_outputs() ONNX import issue: Can't transform scalar to tensor. in impl From<&OnnxArgument> for TensorType Aug 11, 2024
@SimonBrandner
Copy link
Author

After #2148:

ERROR burn_import::logger: PANIC => panicked at /home/simon/.cargo/git/checkouts/burn-178c6829f420dae1/16239db/crates/burn-import/src/burn/ty.rs:135:19:
Ident cannot be a number; use Literal instead

@SimonBrandner SimonBrandner changed the title ONNX import issue: Can't transform scalar to tensor. in impl From<&OnnxArgument> for TensorType ONNX import issue: Ident cannot be a number; use Literal instead in TensorType::new() Aug 15, 2024
@SimonBrandner
Copy link
Author

This has evolved to:

ERROR burn_import::logger: PANIC => panicked at /home/simon/.cargo/git/checkouts/burn-178c6829f420dae1/c94e743/crates/burn-import/src/onnx/op_configuration.rs:1056:9:
Reshape: shape tensor must be present for Node { node_type: Reshape, name: "reshape1", inputs: [Argument { name: "conv2d62_out1", ty: Tensor(TensorType { elem_type: Float32, dim: 4, shape: Some([1, 3, 640
, 640]) }), value: None, passed: false }, Argument { name: "concat15_out1", ty: Tensor(TensorType { elem_type: Float32, dim: 1, shape: None }), value: None, passed: false }], outputs: [Argument { name: "res
hape1_out1", ty: Tensor(TensorType { elem_type: Float32, dim: 0, shape: None }), value: None, passed: false }], attrs: {} }    

@SimonBrandner SimonBrandner changed the title ONNX import issue: Ident cannot be a number; use Literal instead in TensorType::new() ONNX import issue: Reshape: shape tensor must be present for Node Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working onnx
Projects
None yet
Development

No branches or pull requests

5 participants