Hub 文件

GGUF 在 llama.cpp 中的使用

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

GGUF 在 llama.cpp 中的使用

您現在可以在 Hugging Face 端點上部署任何 llama.cpp 相容的 GGUF,請在此處閱讀更多相關資訊。

Llama.cpp 允許您透過提供 Hugging Face 倉庫路徑和檔名來下載 GGUF 並進行推理。llama.cpp 會下載模型檢查點並自動快取它。快取位置由 LLAMA_CACHE 環境變數定義;請在此處閱讀更多相關資訊。

您可以透過 brew(適用於 Mac 和 Linux)安裝 llama.cpp,也可以從原始碼構建它。還有預構建的二進位制檔案和 Docker 映象,您可以在官方文件中檢視

選項 1:使用 brew/winget 安裝

brew install llama.cpp

或者,在 Windows 上透過 winget 安裝

winget install llama.cpp

選項 2:從原始碼構建

步驟 1:從 GitHub 克隆 llama.cpp。

git clone https://github.com/ggerganov/llama.cpp

步驟 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

注意:對於其他硬體支援(例如:AMD ROCm、Intel SYCL),請參閱llama.cpp 的構建指南

安裝後,您可以按如下方式使用 llama-clillama-server

llama-cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0

注意:您可以顯式新增 -no-cnv 以在原始完成模式(非聊天模式)下執行 CLI。

此外,您可以使用 llama.cpp 伺服器直接呼叫 OpenAI 規範的聊天完成端點

llama-server -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0

執行伺服器後,您可以簡單地按如下方式使用該端點

curl https://: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 倉庫名稱 - 開始吧!🦙

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.