PyTorch examples #868
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
| name: PyTorch examples | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| logLevel: | |
| description: 'Log level' | |
| required: true | |
| default: 'info' | |
| push: | |
| branches: [ '*' ] | |
| paths: | |
| - ".github/workflows/pytorch.yml" | |
| - "pytorch-mobilenet-image/**" | |
| pull_request: | |
| branches: [ '*' ] | |
| paths: | |
| - ".github/workflows/pytorch.yml" | |
| - "pytorch-mobilenet-image/**" | |
| merge_group: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ubuntu:20.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install apt-get packages | |
| run: | | |
| ACCEPT_EULA=Y apt-get update | |
| ACCEPT_EULA=Y apt-get upgrade -y | |
| apt-get install -y wget git curl software-properties-common build-essential unzip | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| - name: Install Rust target for wasm | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| target: wasm32-wasip1 | |
| - name: Install WasmEdge + WASI-NN + PyTorch | |
| run: | | |
| VERSION=0.13.4 | |
| curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v $VERSION --plugins wasi_nn-pytorch -p /usr/local | |
| export PYTORCH_VERSION="1.8.2" | |
| # For the Ubuntu 20.04 or above, use the libtorch with cxx11 abi. | |
| export PYTORCH_ABI="libtorch-cxx11-abi" | |
| curl -s -L -O --remote-name-all https://download.pytorch.org/libtorch/lts/1.8/cpu/${PYTORCH_ABI}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip | |
| unzip -q "${PYTORCH_ABI}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" | |
| rm -f "${PYTORCH_ABI}-shared-with-deps-${PYTORCH_VERSION}%2Bcpu.zip" | |
| export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/libtorch/lib | |
| - name: Example | |
| run: | | |
| export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/libtorch/lib | |
| cd pytorch-mobilenet-image/rust | |
| cargo build --target wasm32-wasip1 --release | |
| cd .. | |
| wasmedge compile rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet-image.wasm wasmedge-wasinn-example-mobilenet-image-aot.wasm | |
| wasmedge compile rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet-image-named-model.wasm wasmedge-wasinn-example-mobilenet-image-named-model-aot.wasm | |
| echo "Run without named model" | |
| wasmedge --dir .:. wasmedge-wasinn-example-mobilenet-image-aot.wasm mobilenet.pt input.jpg | |
| echo "Run with named model" | |
| wasmedge --dir .:. --nn-preload demo:PyTorch:CPU:mobilenet.pt wasmedge-wasinn-example-mobilenet-image-named-model-aot.wasm demo input.jpg |