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

Et 4299 try onnx runtime #1041

Closed
wants to merge 6 commits into from
Closed

Et 4299 try onnx runtime #1041

wants to merge 6 commits into from

Conversation

krajewskiML
Copy link
Contributor

Implements script responsible for running onnxruntime and tract comparison in the examples folder

@github-actions github-actions bot added the work-in-progress The author is still working on this PR label Jul 25, 2023
bert/Cargo.toml Outdated
@@ -14,6 +14,7 @@ lindera-core = "0.25.0"
lindera-dictionary = "0.25.0"
lindera-tokenizer = "0.25.0"
ndarray = { workspace = true, features = ["serde"] }
onnxruntime = {version = ">=0.0.2", features = ["model-fetching"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a dev-dependency examples, tests, benchmarks have access to dev dependencies.

let attention_mask = token_reshaper(tokens.get_attention_mask());
let type_ids = token_reshaper(tokens.get_type_ids());
let in_tensor = vec![token_ids, attention_mask, type_ids];
let outputs: Vec<OrtOwnedTensor<f32, _>> = session.run(in_tensor)?;
Copy link
Contributor

@rustonaut rustonaut Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending internal details of OrtOwnedTensor<f32, _> and session.run(in_tensor)? the compiler could theoretically be able to deduce that output is not used session (besides costing time) has no side effects and then end up eliminating the while loop 🙃

practically this is impossible to happen as session will call C-FFI so the compiler doesn't know anymore that it doesn't have side effects etc.

still because of this you want to to pass unused output of benchmarks through std::hint::black_box (similar const input values, but we don't have them here)

libraries like criterion do that for you, but aren't supper trivial to use

@rustonaut
Copy link
Contributor

Wrt. the issues with running it and so/dll loading:

The rust crate onnxruntime only provides rust bindings to the microsoft onnxruntime, it (for good reasons) does not bundle the runtime, nor does the runtime need to even be available to build it.

What that means is that the runtime must be preinstalled in the computer where you want to run it in a compatible version.

E.g. when build on my system libonnxruntime.so.1.7.0 i.e. ABI version 1.7.0 of the runtime.

@rustonaut
Copy link
Contributor

Wrt. running it on ARM:

  • it also needs to have the runtime pre-installed (luckily we don't try this on a phone)
  • it might be easier to "just" build the example on the device
  • alternatively you could consider cargo-cross or cargo-dinghy
    • e.g. if you ssh to the arm device this guid explains how to setup dinghy with ssh and then you can run cargo dinghy -d raspi run --example onnx_runtime and it will cross compile send it over ssh and feed back the output etc. (BUT the onnxruntime library from microsoft still needs to already be there compiled for ARM)

@rustonaut
Copy link
Contributor

rustonaut commented Jul 25, 2023

I think you can find a prebuild blob of the microsoft onnxruntime here: https://github.com/microsoft/onnxruntime/releases/tag/v1.15.1

only issue the rust bindings seem to be servely outdated, but it might still be ABI compatible idk. we would have to try out

@rustonaut
Copy link
Contributor

was integrated in different PR AFIK

@rustonaut rustonaut closed this Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work-in-progress The author is still working on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants