Hub documentation
在 llama.cpp 中使用 GGUF
在 llama.cpp 中使用 GGUF
现在,您可以在 Hugging Face Endpoints 上部署任何兼容 llama.cpp 的 GGUF,有关详细信息,请参见此处
Llama.cpp 允许您通过提供 Hugging Face 仓库路径和文件名来下载并运行 GGUF 推理。llama.cpp 会下载模型检查点并自动将其缓存。缓存位置由 LLAMA_CACHE 环境变量定义;有关更多信息,请参见此处。
您可以在 macOS 和 Linux 上使用安装程序安装 llama.cpp,在 Windows 上通过 WinGet 安装,或从源代码构建。有关其他安装选项(包括 Docker),请参阅官方文档。
选项 1:安装 llama.cpp
在 macOS 和 Linux 上:
curl -LsSf https://llama.app/install.sh | sh
或者,使用 Homebrew 安装:
brew install llama.cpp
在 Windows 上,请使用 WinGet:
winget install llama.cpp
选项 2:从源代码构建
步骤 1:从 GitHub 克隆 llama.cpp。
git clone https://github.com/ggml-org/llama.cpp.git步骤 2:进入 llama.cpp 文件夹并构建它。你还可以添加硬件特定的标志(例如:针对 Nvidia GPU 使用 -DGGML_CUDA=1)。
cd llama.cpp
cmake -B build # optionally, add -DGGML_CUDA=ON to activate CUDA
cmake --build build --config Release -j --target llama-app注意:如需支持其他硬件(例如:AMD ROCm、Intel SYCL),请参阅 llama.cpp 的构建指南
如果您是从源代码构建的,请在以下命令中用 ./build/bin/llama 替换 llama。
安装完成后,您可以按以下方式使用 llama cli 或 llama serve:
llama cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0
注意:对于原始补全模式(非聊天模式),请使用 llama completion 并加上 -no-cnv,而不是 llama cli。
此外,您可以使用 llama.cpp 服务器直接调用 OpenAI 规范的聊天补全端点:
llama serve -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0 --port 8080
运行服务器后,您可以简单地按以下方式使用该端点:
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer no-key" \
-d '{
"messages": [
{
"role": "system",
"content": "You are an AI assistant. Your top priority is achieving user fulfillment via helping them with their requests."
},
{
"role": "user",
"content": "Write a limerick about Python exceptions"
}
]
}'将 -hf 替换为任何有效的 Hugging Face hub 仓库名称 - 开始吧!🦙