环境要求
需要至少 16GB 内存的 Linux VPS(推荐 32GB)。纯 CPU 推理对于个人用途完全可用。
bash
# Tested on Ubuntu 22.04 LTS
# RAM: 16–32 GB | CPU: 4–8 cores
# Monthly cost: ~€15–25 (Hetzner CX32 / OVH Advance)安装 llama.cpp
从源码编译以获得最佳 CPU 性能,启用 OpenBLAS 加速。
bash
sudo apt update && sudo apt install -y build-essential cmake libopenblas-dev
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
cmake -B build -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
cmake --build build --config Release -j$(nproc)下载模型
内存有限时使用 Q4_K_M,8B 模型轻松放入 16GB 内存。
bash
pip install huggingface_hub
huggingface-cli download bartowski/Meta-Llama-3.1-8B-Instruct-GGUF \
--include "Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf" \
--local-dir ./models启动服务
在 8080 端口以服务模式运行 llama.cpp,添加 API 密钥进行基础鉴权。
bash
./build/bin/llama-server \
-m ./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \
--host 0.0.0.0 --port 8080 \
-c 8192 \
-t $(nproc) \
--api-key "your-secret-key"相关指南
部署指南仅供学习参考。每个模型均有独立许可协议 — 下载或部署前请阅读 Hugging Face 官方模型卡。