-
Notifications
You must be signed in to change notification settings - Fork 1.6k
wasi-nn: refactor to allow preview2 access
#6821
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f93df0c
wasi-nn: refactor to allow `preview2` access
abrown 34ef495
wasi-nn: use `preview1` linkage
abrown 45a0374
review: rename `preview*` to `wit*`
abrown e38b61b
review: update README
abrown 3efa7f5
fix: remove broken doc links
abrown aed6471
fix: replace typo `wit` with `gen`
abrown fd36048
review: use `wit` types everywhere
abrown efc4b46
review: move `BackendKind` conversion into `witx.rs`
abrown 1b6c386
review: remove `<'a>`
abrown 7a07592
review: use `tracing` crate instead of `eprintln!`
abrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,45 @@ | ||
| # wasmtime-wasi-nn | ||
|
|
||
| This crate enables support for the [wasi-nn] API in Wasmtime. Currently it contains an implementation of [wasi-nn] using | ||
| OpenVINO™ but in the future it could support multiple machine learning backends. Since the [wasi-nn] API is expected | ||
| to be an optional feature of WASI, this crate is currently separate from the [wasi-common] crate. This crate is | ||
| experimental and its API, functionality, and location could quickly change. | ||
| This crate enables support for the [wasi-nn] API in Wasmtime. Currently it | ||
| contains an implementation of [wasi-nn] using OpenVINO™ but in the future it | ||
| could support multiple machine learning backends. Since the [wasi-nn] API is | ||
| expected to be an optional feature of WASI, this crate is currently separate | ||
| from the [wasi-common] crate. This crate is experimental and its API, | ||
| functionality, and location could quickly change. | ||
|
|
||
| [examples]: examples | ||
| [openvino]: https://crates.io/crates/openvino | ||
| [wasi-nn]: https://github.com/WebAssembly/wasi-nn | ||
| [wasi-common]: ../wasi-common | ||
| [bindings]: https://crates.io/crates/wasi-nn | ||
|
|
||
| ### Use | ||
|
|
||
| Use the Wasmtime APIs to instantiate a Wasm module and link in the `WasiNn` implementation as follows: | ||
| Use the Wasmtime APIs to instantiate a Wasm module and link in the `wasi-nn` | ||
| implementation as follows: | ||
|
|
||
| ``` | ||
| let wasi_nn = WasiNn::new(&store, WasiNnCtx::new()?); | ||
| wasi_nn.add_to_linker(&mut linker)?; | ||
| ```rust | ||
| let wasi_nn = WasiNnCtx::new()?; | ||
| wasmtime_wasi_nn::witx::add_to_linker(...); | ||
| ``` | ||
|
|
||
| ### Build | ||
|
|
||
| This crate should build as usual (i.e. `cargo build`) but note that using an existing installation of OpenVINO™, rather | ||
| than building from source, will drastically improve the build times. See the [openvino] crate for more information | ||
| ```sh | ||
| $ cargo build | ||
| ``` | ||
|
|
||
| To use the WIT-based ABI, compile with `--features component-model` and use `wasmtime_wasi_nn::wit::add_to_linker`. | ||
|
|
||
| ### Example | ||
|
|
||
| An end-to-end example demonstrating ML classification is included in [examples]: | ||
| - `tests/wasi-nn-rust-bindings` contains ergonomic bindings for writing Rust code against the [wasi-nn] APIs | ||
| - `tests/classification-example` contains a standalone Rust project that uses the [wasi-nn] APIs and is compiled to the | ||
| `wasm32-wasi` target using the `wasi-nn-rust-bindings` | ||
| `examples/classification-example` contains a standalone Rust project that uses | ||
| the [wasi-nn] APIs and is compiled to the `wasm32-wasi` target using the | ||
| high-level `wasi-nn` [bindings]. | ||
|
|
||
| Run the example from the Wasmtime project directory: | ||
|
|
||
| ``` | ||
| ci/run-wasi-nn-example.sh | ||
| ```sh | ||
| $ ci/run-wasi-nn-example.sh | ||
| ``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
if the goal of this list of lists is just to pass in a
list<u8>for xml and alist<u8>for weights, then can we just make it two arguments that are eachlist<u8>?Uh oh!
There was an error while loading. Please reload this page.
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.
well, other backends will have different numbers of
list<u8>to be passed in so the spec has to account for that; theBackendtrait mirrors that so that other backends can be implemented.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 think eventually we should use named parameters here as well, but @abrown is correct that different frameworks take a different number of options and some even take an execution plan for a model.