-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add an initial wasi-nn implementation for Wasmtime #2208
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
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # install-openvino | ||
|
|
||
| A GitHub action to install OpenVINO from a package repository. This is only necessary for `wasi-nn` support but there | ||
| are enough steps here to package the functionality separately and avoid cluttering the CI. | ||
|
|
||
| Future improvements: | ||
| - make this installer work for different OS/distributions (e.g. https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_windows.html) | ||
| - it would be nice to output the install directory (i.e. `/opt/intel/openvino`) |
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: 'Install OpenVINO' | ||
| description: 'Install OpenVINO binaries from a package repository; this is significantly faster than building from source' | ||
|
|
||
| inputs: | ||
| version: | ||
| description: 'The release version of OpenVINO to install' | ||
| required: false | ||
| default: '2020.4.287' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - run: ${{ github.action_path }}/install.sh ${{ inputs.version }} | ||
| shell: bash |
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Retrieve OpenVINO checksum. | ||
| wget https://apt.repos.intel.com/openvino/2020/GPG-PUB-KEY-INTEL-OPENVINO-2020 | ||
| echo '5f5cff8a2d26ba7de91942bd0540fa4d GPG-PUB-KEY-INTEL-OPENVINO-2020' > CHECKSUM | ||
| md5sum --check CHECKSUM | ||
|
|
||
| # Add OpenVINO repository (deb). | ||
| sudo apt-key add GPG-PUB-KEY-INTEL-OPENVINO-2020 | ||
| echo "deb https://apt.repos.intel.com/openvino/2020 all main" | sudo tee /etc/apt/sources.list.d/intel-openvino-2020.list | ||
| sudo apt update | ||
|
|
||
| # Install OpenVINO package. | ||
| sudo apt install -y intel-openvino-runtime-ubuntu18-$1 |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
|
|
||
| # The following script demonstrates how to execute a machine learning inference using the wasi-nn module optionally | ||
| # compiled into Wasmtime. Calling it will download the necessary model and tensor files stored separately in $FIXTURE | ||
| # into $TMP_DIR (optionally pass a directory with existing files as the first argument to re-try the script). Then, | ||
| # it will compile the example code in crates/wasi-nn/tests/example into a Wasm file that is subsequently | ||
| # executed with the Wasmtime CLI. | ||
| set -e | ||
| WASMTIME_DIR=$(dirname "$0" | xargs dirname) | ||
| FIXTURE=https://gist.github.com/abrown/c7847bf3701f9efbb2070da1878542c1/raw/07a9f163994b0ff8f0d7c5a5c9645ec3d8b24024 | ||
|
|
||
| # Inform the environment of OpenVINO library locations. Then we use OPENVINO_INSTALL_DIR below to avoid building all of | ||
| # OpenVINO from source (quite slow). | ||
| source /opt/intel/openvino/bin/setupvars.sh | ||
|
|
||
| # Build Wasmtime with wasi-nn enabled; we attempt this first to avoid extra work if the build fails. | ||
| OPENVINO_INSTALL_DIR=/opt/intel/openvino cargo build -p wasmtime-cli --features wasi-nn | ||
|
|
||
| # Download all necessary test fixtures to the temporary directory. | ||
| TMP_DIR=${1:-$(mktemp -d -t ci-XXXXXXXXXX)} | ||
| wget --no-clobber --directory-prefix=$TMP_DIR $FIXTURE/frozen_inference_graph.bin | ||
| wget --no-clobber --directory-prefix=$TMP_DIR $FIXTURE/frozen_inference_graph.xml | ||
| wget --no-clobber --directory-prefix=$TMP_DIR $FIXTURE/tensor-1x3x300x300-f32.bgr | ||
|
|
||
| # Now build an example that uses the wasi-nn API. | ||
| pushd $WASMTIME_DIR/crates/wasi-nn/examples/classification-example | ||
| cargo build --release --target=wasm32-wasi | ||
| cp target/wasm32-wasi/release/wasi-nn-example.wasm $TMP_DIR | ||
| popd | ||
|
|
||
| # Run the example in Wasmtime (note that the example uses `fixture` as the expected location of the model/tensor files). | ||
| OPENVINO_INSTALL_DIR=/opt/intel/openvino cargo run --features wasi-nn -- run --mapdir fixture::$TMP_DIR $TMP_DIR/wasi-nn-example.wasm | ||
|
|
||
| # Clean up. | ||
| rm -rf $TMP_DIR |
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [package] | ||
| name = "wasmtime-wasi-nn" | ||
| version = "0.21.0" | ||
| authors = ["The Wasmtime Project Developers"] | ||
| description = "Wasmtime implementation of the wasi-nn API" | ||
| documentation = "https://docs.rs/wasmtime-wasi-nn" | ||
| license = "Apache-2.0 WITH LLVM-exception" | ||
| categories = ["wasm", "computer-vision"] | ||
| keywords = ["webassembly", "wasm", "neural network"] | ||
| repository = "https://github.com/bytecodealliance/wasmtime" | ||
| readme = "README.md" | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| # These dependencies are necessary for the witx-generation macros to work: | ||
| anyhow = "1.0" | ||
| log = { version = "0.4", default-features = false } | ||
| wasmtime = { path = "../wasmtime", version = "0.21.0", default-features = false } | ||
| wasmtime-runtime = { path = "../runtime", version = "0.21.0" } | ||
| wasmtime-wiggle = { path = "../wiggle/wasmtime", version = "0.21.0" } | ||
| wasmtime-wasi = { path = "../wasi", version = "0.21.0" } | ||
| wiggle = { path = "../wiggle", version = "0.21.0" } | ||
|
|
||
| # These dependencies are necessary for the wasi-nn implementation: | ||
| openvino = "0.1.5" | ||
| thiserror = "1.0" | ||
|
|
||
| [badges] | ||
| maintenance = { status = "experimental" } | ||
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.