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

burn_import::onnx::ModelGen hangs in build.rs if record type is NamedMpkGz #952

Closed
seftontycho opened this issue Nov 13, 2023 · 9 comments
Closed
Labels
bug Something isn't working onnx

Comments

@seftontycho
Copy link

seftontycho commented Nov 13, 2023

I have the following build.rs file that I have copied from https://burn.dev/book/import/onnx-model.html.

use burn_import::onnx::ModelGen;

fn main() {
    // Generate Rust code from the ONNX model file
    ModelGen::new()
        .input("src/model/identifier.onnx")
        .out_dir("model/")
        .run_from_script();
}

When I try to build it gets to my_crate_name(build) and then never completes.
I have waited for 2 hours and nothing.

No errors are thrown either.
identifier.onnx is a resnet50 model that I exported from pytorch.

Any ideas what I am doing wrong?

@antimora
Copy link
Collaborator

Thanks for reporting. Are you able to share your ONNX file so that we attempt to recreate the issue?

@antimora antimora added the onnx label Nov 13, 2023
@seftontycho
Copy link
Author

seftontycho commented Nov 13, 2023

Hi, thanks for the fast response.
I have had to upload the onnx file to google drive as it was too large to attach.

https://drive.google.com/file/d/1pt7aOK_4zrQYW3bs6bSpRKk0Lhr5OOg6/view?usp=drive_link

@antimora
Copy link
Collaborator

Yes. I can confirm the build keeps going. I am not sure what the root cause yet. I'll report back.

@antimora antimora self-assigned this Nov 13, 2023
@antimora antimora added the bug Something isn't working label Nov 13, 2023
@antimora
Copy link
Collaborator

OK. I have narrowed down the problem. If the record type is named message pack compressed (RecordType::NamedMpkGz), it will hang but other record types work. NamedMpkGz is default record type.

The following will work (the build should be fast):

ModelGen::new()
        .input("src/model/identifier.onnx")
        .out_dir("model/")
        .record_type(RecordType::NamedMpk)
        .embed_states(false)
        .run_from_script();

Or

ModelGen::new()
        .input("src/model/identifier.onnx")
        .out_dir("model/")
        .record_type(RecordType::Bincode)
        .embed_states(false)
        .run_from_script();

Or

    ModelGen::new()
        .input("src/model/identifier.onnx")
        .out_dir("model/")
        .record_type(RecordType::PrettyJson)
        .embed_states(false)
        .run_from_script();

This will hang:

    ModelGen::new()
        .input("src/model/identifier.onnx")
        .out_dir("model/")
        .record_type(RecordType::NamedMpkGz)
        .embed_states(false)
        .run_from_script();

So for now as a workaround, I recommend using NamedMpk or Bincode for record type. Use Bincode if you intend to embed the weights into your executable binary.

CCing @nathanielsimard , so he's aware of this.

@antimora antimora changed the title burn_import::onnx::ModelGen hangs in build.rs burn_import::onnx::ModelGen hangs in build.rs if record type is NamedMpkGz Nov 13, 2023
@antimora
Copy link
Collaborator

@seftontycho , let us know if the workaround works for you. I can confirm all ops in your ONNX should be supported (at least they are compiled). I did not run the model.

@antimora antimora removed their assignment Nov 13, 2023
@seftontycho
Copy link
Author

I can confirm that this works!
Thank you so much for the very quick fix.

@antimora
Copy link
Collaborator

I can confirm that this works! Thank you so much for the very quick fix.

Great! We will investigate the root cause for NamedMpkGz and will have a fix.

antimora added a commit to antimora/burn that referenced this issue Nov 30, 2023
This temporarily workaround of tracel-ai#952 bug.
louisfd pushed a commit that referenced this issue Nov 30, 2023
* Change ONNX default record type to NamedMpk

This temporarily workaround of #952 bug.

* Fix formatting

* Fix URL in the doc
@antimora
Copy link
Collaborator

In #1019 PR, I changed the default recordtype to be NamedMpk as a temp measure. We will keep this ticket open till we understand what the issue is.

antimora added a commit to antimora/models that referenced this issue Dec 1, 2023
@antimora
Copy link
Collaborator

antimora commented Mar 1, 2024

We decided not to support compressed Gz version. Closing it.

@antimora antimora closed this as completed Mar 1, 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

2 participants