BENMFeng / wasm-faas-tensorflow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebAssembly based AI as a Service with Kubernetes

Demo 1: Run locally with WasmEdge

Prerequisite:

  • Install Rust with rustup
  • Have GCC installed
  • Git and cURL

Steps:

  1. Install the wasm32-wasi target
rustup target add wasm32-wasi
  1. Install wasmedge
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash
source $HOME/.wasmedge/env
  1. Build the QuickJS interpreter with the WasmEdge Tensorflow extension
cd wasmedge-quickjs
cargo build --target wasm32-wasi --release --features=tensorflow
cd ..
  1. Run JS Examples locally
cd js_food
wasmedge-tensorflow-lite --dir .:. wasmedge_quickjs.wasm main.js
cd ..
  1. Run Rust examples locally
cd rust_mobilenet
cargo build --target wasm32-wasi --release

We can AOT compile our Rust code to machine native code, and then use WasmEdge sandbox to run the native code.

wasmedgec-tensorflow target/wasm32-wasi/release/classify.wasm classify.so
wasmedge-tensorflow-lite classify.so < grace_hopper.jpg

Demo 2: Deploy as a FAAS

Prerequisite:

  • Install Rust with rustup
  • Have GCC installed
  • Git and cURL
  • Vercel CLI

Steps:

  1. Install the wasm32-wasi target
rustup target add wasm32-wasi
  1. Build the Rust program to WebAssembly bytecode
cd faas
cd api/functions/image-classification/
cargo build --release --target wasm32-wasi
  1. Prepare the build artifacts for deployment
cp target/wasm32-wasi/release/classify.wasm ../../
  1. Deploy the function
cd ../../../
vercel deploy

Demo 3

Build container

sudo buildah build --annotation "module.wasm.image/variant=compat" -t classify .

About

License:Apache License 2.0


Languages

Language:JavaScript 43.2%Language:Rust 29.2%Language:CSS 19.8%Language:Shell 7.9%