Hub 文档
GGUF 与 llama.cpp 的用法
加入 Hugging Face 社区
并获取增强的文档体验
开始使用
GGUF 与 llama.cpp 的用法
现在你可以将任何 llama.cpp 兼容的 GGUF 部署在 Hugging Face Endpoints 上,在此处了解更多here
Llama.cpp 允许你通过提供 Hugging Face repo 路径和文件名来下载并对 GGUF 运行推理。llama.cpp 下载模型检查点并自动缓存它。缓存的位置由 LLAMA_CACHE
环境变量定义;在此处了解更多here。
你可以通过 brew (适用于 Mac 和 Linux) 安装 llama.cpp,或者你可以从源代码构建它。还有预构建的二进制文件和 Docker 镜像,你可以在官方文档中查看。
选项 1:使用 brew 安装
brew install llama.cpp
选项 2:从源代码构建
步骤 1:从 GitHub 克隆 llama.cpp。
git clone https://github.com/ggerganov/llama.cpp
步骤 2:移动到 llama.cpp 文件夹中,并使用 LLAMA_CURL=1
标志以及其他硬件特定标志(例如:Linux 上 Nvidia GPU 的 LLAMA_CUDA=1)构建它。
cd llama.cpp && LLAMA_CURL=1 make
安装完成后,你可以按如下方式使用 llama-cli
或 llama-server
llama-cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0
注意:你可以移除 -cnv
以在聊天完成模式下运行 CLI。
此外,你可以使用 llama.cpp 服务器直接调用 OpenAI 规范的聊天完成端点
llama-server -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0
运行服务器后,你可以按如下方式简单地使用该端点
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 fulfilment via helping them with their requests."
},
{
"role": "user",
"content": "Write a limerick about Python exceptions"
}
]
}'
将 -hf
替换为任何有效的 Hugging Face hub repo 名称 - 开始吧!🦙
注意:请记住使用 LLAMA_CURL=1
构建 llama.cpp :)