-
Notifications
You must be signed in to change notification settings - Fork 514
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
bug(onnx): model created using tf2onnx panics with non-valid Ident #2878
Comments
Following on from this, I removed all the special characters from the onnx graph nodes manually, then had an issue that the Split node was not supported in burn v0.16.0, so I upgraded to v0.17.0 using the main branch of this repo. However, the model still fails to import with the following error:
|
ok, after a little more digging I've found that:
I note that the |
Sorry for the delayed response!
The link is invalid, but there seems to be a script to generate it here? Could you share the ONNX model in this issue? Might have to zip it for github to accept the upload.
If this is valid ONNX, then this is a bug. During code generation we parse the names and format them for variables but looks like not all symbols are handled.
As you noted, support for the split node was just added recently. Perhaps the implementation does not handle the whole specification. If you include the model I could take a look! |
Yes, that script will generate the models, but I'll also attach it below. Thanks for looking into this :) |
Ok so my initial hypothesis was correct.
The name formatting really only handles alphanumeric values. burn/crates/burn-import/src/burn/ty.rs Lines 67 to 74 in a1ca434
If we change the last line to replace the invalid ident values in your model, it correctly parses the model. name.to_string().replace(":", "_").replace("/", "_") // replace ":" -> "_", "/" -> "_" But I get another error:
In your case, the model actually has a lhs scalar and rhs tensor, which is not handled. A quick fix pub(crate) fn div(lhs: Type, rhs: Type, output: Type) -> Self {
let function = match (&lhs, &rhs) {
(Type::Tensor(_), Type::Tensor(_)) => move |lhs, rhs| quote! { #lhs.div(#rhs) },
(Type::Tensor(_), Type::Scalar(_)) => move |lhs, rhs| quote! { #lhs.div_scalar(#rhs) },
(Type::Scalar(_), Type::Scalar(_)) => move |lhs, rhs| quote! { #lhs / #rhs },
(Type::Scalar(_), Type::Tensor(_)) => {
move |lhs, rhs| quote! { #rhs.recip().mul_scalar(#lhs) }
}
_ => panic!("Division is supported for tensor and scalar only"),
};
Self::new(lhs, rhs, output, BinaryType::Div, Arc::new(function))
} And finally, the codegen worked.. but it's not correct 😓
The |
Describe the bug
I have a equinox jax model I want to import into burn. I used
jax2tf
to get a tensorflow model, thentf2onnx
to obtain the onnx file. When I try to import this into burn it panics with the message:I'd imagine it is the ":" or "/" characters in the ident, which seem to be used to identify blocks and outputs in the model. Is this panic expected or a bug?
To Reproduce
You can get the onnx file here: https://github.com/martinjrobins/diffsol/raw/refs/heads/workspace/examples/neural-ode-weather-prediction/rhs.onnx
Then I read it in as per the onnx example: https://burn.dev/burn-book/import/onnx-model.html
Expected behavior
The model to import without panic
Desktop (please complete the following information):
Additional context
Using burn v0.16.0
The text was updated successfully, but these errors were encountered: