-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add an initial wasi-nn implementation for Wasmtime #2208
Conversation
Hi @abrown, I think it's a great idea to add neural network module in WASI and Wasmtime, and I'm also interested in expanding other inference frameworks into wasi-nn backend plugin. Could u give some guidelines to develop a new backend plugin? Thanks! |
I think the process currently looks like this (at a very high level):
Hopefully that covers the basics but as you might guess there are details that could bear more documentation. |
Tagging a few people as reviewers to solicit some early feedback on this approach to adding optional WASI modules to Wasmtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks pretty reasonable to me! It seems like a relatively straightforward application of what we already have with wasi-nn
using wiggle to bridge OpenVINO and Wasmtime. The wasi-nn
bindings crate looks pretty simple as well being generated by witx-bindgen
. Overall looks great!
In terms of integration I don't think that the .github
folder in a subdirectory will work, I think it needs to be up near the top. This is a lot of code though about stuff I don't really know about (the wasi-nn
proposal), and I suspect most others don't as well. Do you feel that there's benefit from being in this repository itself, vs external? Externally would make CI easier, but the cost would be that you'd need to update it whenever Wasmtime itself updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not familiar with openvino specifically, but at a high level the integration with wiggle looks reasonable.
Thinking about this more, it occurs to me that that using a cargo feature to guard wasi-nn has a potential downside. If people not working on wasi-nn change Wasmtime's APIs, they'll still have to build wasi-nn to avoid CI failures. As such, I started thinking about what this would look like in a separate repo. I'm not convinced it's the right thing yet, but here's the idea:
- Move Wasmtime's src/commands into a proper library crate, say
wasmtime-commands
- Add a way to add additional modules to load in
RunCommand
- Make wasi-nn a separate repo which uses this
wasmtime-commands
crate to build a CLI program just likewasmtime
but which includeswasi-nn
.
That way, wasi-nn would be in control of when it sees Wasmtime API changes. That would also avoid the 95 MB file in the Wasmtime repo. Thoughts?
a376ab2
to
8213c3b
Compare
Belatedly, but this sounds good to me! |
055ce87
to
4e17510
Compare
e8fa9e5
to
a784567
Compare
Subscribe to Label Actioncc @kubkon
This issue or pull request has been labeled: "cranelift", "wasi"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
c1fd697
to
d0ce5ad
Compare
@pchickey, @sunfishcode, @alexcrichton: I think this is ready for an official review (pending any crazy CI failures... I think I've seen the majority of them already). What you will see with the current state of this PR is two commits:
|
Seems reasonable to me, but are you thinking we should land all the support in this repository? I may have misunderstood but it sounded like we were shooting instead for landing this as a separate repository with integration hooks provided here. |
@sunfishcode and @abrown what do y'all think of making a wasmtime-nn (or similar) repository in the bytecodealliance org to house this integration? |
d0ce5ad
to
22d36b2
Compare
This change adds a crate, `wasmtime-wasi-nn`, that uses `wiggle` to expose the current state of the wasi-nn API and `openvino` to implement the exposed functions. It includes an end-to-end test demonstrating how to do classification using wasi-nn: - `crates/wasi-nn/tests/classification-example` contains Rust code that is compiled to the `wasm32-wasi` target and run with a Wasmtime embedding that exposes the wasi-nn calls - the example uses Rust bindings for wasi-nn contained in `crates/wasi-nn/tests/wasi-nn-rust-bindings`; this crate contains code generated by `witx-bindgen` and eventually should be its own standalone crate
This change adds: - a GitHub action for installing OpenVINO - a script, `ci/run-wasi-nn-example.sh`, to run the classification example
22d36b2
to
8ca42c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok everything looks good to me, thanks again for the patience here!
* Add an initial wasi-nn implementation for Wasmtime This change adds a crate, `wasmtime-wasi-nn`, that uses `wiggle` to expose the current state of the wasi-nn API and `openvino` to implement the exposed functions. It includes an end-to-end test demonstrating how to do classification using wasi-nn: - `crates/wasi-nn/tests/classification-example` contains Rust code that is compiled to the `wasm32-wasi` target and run with a Wasmtime embedding that exposes the wasi-nn calls - the example uses Rust bindings for wasi-nn contained in `crates/wasi-nn/tests/wasi-nn-rust-bindings`; this crate contains code generated by `witx-bindgen` and eventually should be its own standalone crate * Test wasi-nn as a CI step This change adds: - a GitHub action for installing OpenVINO - a script, `ci/run-wasi-nn-example.sh`, to run the classification example
This change adds a crate,
wasmtime-wasi-nn
, that useswiggle
to expose the current state of the wasi-nn API andopenvino
to implement the exposed functions. It includes an end-to-end test demonstrating how to do classification using wasi-nn:crates/wasi-nn/examples/classification-example
contains Rust code that is compiled to thewasm32-wasi
target and run with a Wasmtime embedding that exposes the wasi-nn callscrates/wasi-nn/tests/wasi-nn-rust-bindings
; this crate contains code generated bywitx-bindgen
and eventually should be its own standalone crateThis change does not wire up wasi-nn to Wasmtime in any way that an external user would be able to observe.
Things to discuss:
git clone
--what to do? Removing the test would mean that the CI could not verify thatwasmtime-wasi-nn
worksopenvino
crate is not yet published but should be when Add a Rust bridge openvinotoolkit/openvino#2342 is merged; this means that builds of this PR will fail until then [edit: I ended up publishing them prior to merging that PR; we are still trying to figure out where that code will end up]wasi-nn-rust-bindings
crate should probably be its own repository but I cannot move it there until I wade through Intel's external release process (for reference, it took me several weeks for theopenvino
crate); it could be moved to its own repository in a separate PR