Skip to content

Commit

Permalink
Merge pull request #103 from second-state/add_llamaedge
Browse files Browse the repository at this point in the history
sysext: add llamaedge recipe
  • Loading branch information
tormath1 authored Dec 3, 2024
2 parents 9f5fdf3 + 8952fca commit dd38a27
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,32 @@ storage:
hard: false
```

#### LlamaEdge

The llamaedge sysext can be configured by using the following snippet:

```
variant: flatcar
version: 1.0.0
storage:
files:
- path: /opt/extensions/wasmedge-0.14.1-x86-64.raw
mode: 0420
contents:
source: https://github.com/flatcar/sysext-bakery/releases/download/latest/wasmaedge-0.14.1-x86-64.raw
- path: /opt/extensions/llamaedge-0.14.16-x86-64.raw
mode: 0420
contents:
source: https://github.com/flatcar/sysext-bakery/releases/download/latest/llamaedge-0.14.16-x86-64.raw
links:
- target: /opt/extensions/llamaedge-0.14.16-x86-64.raw
path: /etc/extensions/llamaedge.raw
hard: false
- target: /opt/extensions/wasmedge-0.14.1-x86-64.raw
path: /etc/extensions/wasmedge.raw
hard: false
```

### Building sysext images

To use the build scripts in this repository, the following packages are required:
Expand Down
54 changes: 54 additions & 0 deletions create_llamaedge_sysext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euo pipefail

export ARCH="${ARCH-x86-64}"
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"

if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 VERSION SYSEXTNAME"
echo "The script will download the llamaedge release tar ball (e.g., for 0.14.16) and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder."
echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again."
echo "All files in the sysext image will be owned by root."
echo "To use arm64 pass 'ARCH=arm64' as environment variable (current value is '${ARCH}')."
"${SCRIPTFOLDER}"/bake.sh --help
exit 1
fi

VERSION="$1"
SYSEXTNAME="$2"

# The github release uses different arch identifiers, we map them here
# and rely on bake.sh to map them back to what systemd expects
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "x86-64" ]; then
ARCH="x86_64"
elif [ "${ARCH}" = "arm64" ]; then
ARCH="aarch64"
fi

# llamaedge is a wasm application, which requires WasmEdge and its WASI-NN GGML/GGUF plugin
WASMEDGE_VERSION="0.14.1"

# Download WasmEdge WASI-NN GGML/GGUF plugin
rm -f "WasmEdge-plugin-wasi_nn-ggml-${WASMEDGE_VERSION}.tar.gz"
curl -o "WasmEdge-plugin-wasi_nn-ggml-${WASMEDGE_VERSION}.tar.gz" -fsSL "https://github.com/WasmEdge/WasmEdge/releases/download/${WASMEDGE_VERSION}/WasmEdge-plugin-wasi_nn-ggml-${WASMEDGE_VERSION}-ubuntu20.04_${ARCH}.tar.gz"

# Download llamaedge api server
rm -f "llama-api-server.wasm"
curl -o "llama-api-server.wasm" -fsSL "https://github.com/LlamaEdge/LlamaEdge/releases/download/${VERSION}/llama-api-server.wasm"

rm -rf "${SYSEXTNAME}"
mkdir -p "${SYSEXTNAME}"

tar --force-local -xvf "WasmEdge-plugin-wasi_nn-ggml-${WASMEDGE_VERSION}.tar.gz" -C "${SYSEXTNAME}"
mv "llama-api-server.wasm" "${SYSEXTNAME}"

rm "WasmEdge-plugin-wasi_nn-ggml-${WASMEDGE_VERSION}.tar.gz"

mkdir -p "${SYSEXTNAME}"/usr/lib/wasmedge # for plugins
mkdir -p "${SYSEXTNAME}"/usr/lib/wasmedge/wasm # for llamaedge application

mv "${SYSEXTNAME}"/libwasmedgePluginWasiNN.so "${SYSEXTNAME}"/usr/lib/wasmedge
mv "${SYSEXTNAME}"/llama-api-server.wasm "${SYSEXTNAME}"/usr/lib/wasmedge/wasm

"${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}"
rm -rf "${SYSEXTNAME}"
2 changes: 2 additions & 0 deletions release_build_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ ollama-0.3.9
containerd-2.0.0

wasmedge-0.14.1

llamaedge-0.14.16

0 comments on commit dd38a27

Please sign in to comment.