跳至主要内容

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​

  1. 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-ggml
    source "$HOME/.wasmedge/env"
    wasmedge --version
  2. 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.wasm
    curl -fLO https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf
  3. Run the example from that directory. The --nn-preload option makes the model available to the GGML backend under the alias default. 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 0

    The application prints [Answer]: followed by generated text. For example, it might complete Once upon a time with , 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 --version and 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, set WASMEDGE_PLUGIN_PATH to 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-preload and 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.