From 8952fca0f0b9328f01177052cae0efe4e2e1f8f3 Mon Sep 17 00:00:00 2001 From: hydai Date: Thu, 28 Nov 2024 16:40:42 +0800 Subject: [PATCH] sysext: add llamaedge recipe Signed-off-by: hydai --- README.md | 26 ++++++++++++++++++ create_llamaedge_sysext.sh | 54 ++++++++++++++++++++++++++++++++++++++ release_build_versions.txt | 2 ++ 3 files changed, 82 insertions(+) create mode 100755 create_llamaedge_sysext.sh diff --git a/README.md b/README.md index 65c0757..a88c1c2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/create_llamaedge_sysext.sh b/create_llamaedge_sysext.sh new file mode 100755 index 0000000..df3bb88 --- /dev/null +++ b/create_llamaedge_sysext.sh @@ -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}" diff --git a/release_build_versions.txt b/release_build_versions.txt index 7716281..976f6f5 100644 --- a/release_build_versions.txt +++ b/release_build_versions.txt @@ -32,3 +32,5 @@ ollama-0.3.9 containerd-2.0.0 wasmedge-0.14.1 + +llamaedge-0.14.16