Use a plug-in with the CLI
A WasmEdge plug-in supplies host functions that a Wasm application can call. Install the plug-in on the machine running WasmEdge, then pass the application's .wasm file to the CLI. WasmEdge loads plug-ins from its search paths when the CLI starts.
Choose a plug-in for your application
Start with the plug-in or backend named by the application. For example, a chat program that loads a GGUF model needs the WASI-NN GGML backend. Check the plug-in compatibility table for its installer key, release packages and dependencies. Choose one WASI-NN backend per installation.
Run a small text-generation example
-
On a supported Linux or macOS machine, review the GGML dependencies, then install WasmEdge with the GGML backend. These commands use the default per-user install location.
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --plugins wasi_nn-ggmlsource "$HOME/.wasmedge/env"wasmedge --version -
Look for
(plugin "wasi_nn")in the version output. Download the precompiled LlamaEdge text-generation program and its small GGUF test model (about 1.2 MB) into the same directory.curl -fLO https://github.com/LlamaEdge/LlamaEdge/releases/download/0.29.0/llama-simple.wasmcurl -fLO https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf -
Run the example from that directory. The
--nn-preloadoption makes the model available to the GGML backend under the aliasdefault. The application asks it to continue the prompt for up to eight tokens.wasmedge --dir .:. --nn-preload default:GGML:AUTO:stories260K.gguf \llama-simple.wasm --prompt "Once upon a time" --ctx-size 512 --n-predict 8 --n-gpu-layers 0The application prints
[Answer]:followed by generated text. For example, it might completeOnce upon a timewith, there was a little girl. A completion confirms that the Wasm program called the plug-in and ran inference.
If the application cannot use the plug-in
- The CLI cannot find the plug-in or its options. Run
wasmedge --versionand look for the plug-in in the list below the runtime version. Check that your terminal uses the same installation as your plug-in. For the default per-user installation on Linux or macOS, look in~/.wasmedge/plugin/. For a custom location, setWASMEDGE_PLUGIN_PATHto the directory containing the native plug-in library, then run the application again. - A native library is missing. Check the operating system, architecture, runtime version, and dependency listed for that plug-in in the compatibility table.
- The application cannot open the model. Check that the GGUF filename matches the filename passed to
--nn-preloadand that you launched the command from the directory containing the downloaded files.
To load an existing plug-in from your own C host, see Load plug-ins with the C API. To implement a new native plug-in, see Develop a WasmEdge plug-in.