本文将使用LlamaEdge+WasmEdge来在本地部署Qwen2.5-0.5B-Instruct-GGUF。
系统环境
- Ubuntu 24.04 (无GPU,将部署为在CPU上推理)
安装WasmEdge
wasmedge版本信息如下:
wasmedge -v
wasmedge version 0.14.1
(plugin "wasi_logging") version 0.1.0.0
~/.wasmedge/lib/../plugin/libwasmedgePluginWasiNN.so (plugin "wasi_nn") version 0.10.1.0下载LlamaEdge API Sserver
LlamaEdge API Server是一个跨平台的可移植 Wasm 应用,可以在不同CPU和GPU设备上运行。
wget https://github.com/LlamaEdge/LlamaEdge/releases/download/0.14.11/llama-api-server.wasm下载Qwen2.5-0.5B-Instruct-GGUF
Qwen2.5-0.5B-Instruct的GGUF 文件:
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download Qwen/Qwen2.5-0.5B-Instruct-GGUF qwen2.5-0.5b-instruct-fp16.gguf --local-dir ./ 上面的命令将只下载qwen2.5-0.5b-instruct-fp16.gguf文件到本地目录。模型文件有1.27GB,下载需要一定的时间。
启动LlamaEdge API Sserver
使用以下命令行为模型qwen2.5-0.5b-instruct-fp16.gguf启动LlamaEdge API server:
wasmedge --dir .:. --nn-preload default:GGML:CPU:qwen2.5-0.5b-instruct-fp16.gguf \
llama-api-server.wasm \
--model-name=qwen2.5-0.5b-instruct \
--prompt-template=chatml-tool \
--ctx-size=32768注意: --nn-preload default:GGML:CPU:qwen2.5-0.5b-instruct-fp16.gguf表示加载模型,在CPU上推理。
llama-api-server.wasm的参数信息可以使用下面的命令查看
wasmedge llama-api-server.wasm --help在另一个终端中测试API:
curl -s http://localhost:8080/v1/models | jq .
{
"object": "list",
"data": [
{
"id": "qwen2.5-0.5b-instruct",
"object": "model",
"owned_by": "Not specified"
}
]
}curl -s http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "qwen2.5-0.5b-instruct",
"messages": [
{"role": "system", "content": "你是一个数学家."},
{"role": "user", "content": "9.11和9.8这两个小数谁比较大?"}
],
"max_tokens": 512
}' | jq '.choices[0].message.content'
"9.11 和 9.8 的大小比较可以这样进行:\n- 确定哪个小数是从左到右开始的。9.11 从左边的0 开始,而 9.8 从左边的8 开始。\n- 在两者相同时,继续比 较它们的后面的小数部分。\n- 如果后一个数字大于前一个,则当前值更大;否则后一个数小。\n\n所以,我们可以通过逐位比较的方式来确定:\n1. 首先, 可以肯定的是 9.11 比 9.8 大。因为 0 和 8 在第一个位置上。\n2. 然后是第二个位,9.11 的 1 和 8 在两个数字的右边的第一个位置上。\n\n所以,从左 到右:\n- 9.11 > 9.1\n- 9.11 < 9.13\n\n因此,9.11 比 9.8 大。"使用chatbot UI
LlamaEdge还提供了一个chatbot UI可以配合llama-api-server.wasm一起使用。
wget https://github.com/LlamaEdge/chatbot-ui/releases/latest/download/chatbot-ui.tar.gz
tar -zxvf chatbot-ui.tar.gz
rm chatbot-ui.tar.gzwasmedge --dir .:. --nn-preload default:GGML:CPU:qwen2.5-0.5b-instruct-fp16.gguf \
llama-api-server.wasm \
--model-name=qwen2.5-0.5b-instruct \
--prompt-template=chatml-tool \
--ctx-size=128000在浏览器中打开http://<host>:8080即可使用:
