如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
C/C++实现的LLM推理
-hf 下载的模型现在存储在标准 Hugging Face 缓存目录中,可与其他 HF 工具共享。llama-server 现已支持多模态:https://github.com/ggml-org/llama.cpp/pull/*** | 文档llama.cpp 的入门非常简单。以下是在您的机器上安装它的几种方法:
llama.cpp安装完成后,您需要一个模型才能使用。请前往获取和量化模型部分了解更多信息。
示例命令:
# 使用本地模型文件
llama-cli -m my_model.gguf
# 或直接从 Hugging Face 下载并运行模型
llama-cli -hf ggml-org/gemma-3-1b-it-GGUF
# 启动兼容 OpenAI 的 API 服务器
llama-server -hf ggml-org/gemma-3-1b-it-GGUF
llama.cpp 的主要目标是在各种硬件上(本地和云端)以最少的设置实现最先进的 LLM 推理性能。
llama.cpp 项目是为 https://github.com/ggml-org/ggml 库开发新功能的主要实验场。
模型
通常也支持基于以下基础模型的微调模型。
添加新模型支持的说明:HOWTO-add-model.md
纯文本
多模态
LLaVA 1.5 模型、LLaVA 1.6 模型
BakLLaVA
Obsidian
ShareGPT4V
MobileVLM 1.7B/3B 模型
Yi-VL
Mini CPM
Moondream
https://github.com/BAAI-DCAI/Bunny
GLM-EDGE
Qwen2-VL
LFM2-VL
Python: https://github.com/ddh0/easy-llama
Python: https://github.com/abetlen/llama-cpp-python
Go: https://github.com/go-skynet/go-llama.cpp
Node.js: https://github.com/withcatai/node-llama-cpp
JS/TS(llama.cpp 服务器客户端): lgrammel/modelfusion
JS/TS(可编程提示引擎 CLI): https://github.com/offline-ai/cli
JavaScript/Wasm(可在浏览器中运行): https://github.com/tangledgroup/llama-cpp-wasm
Typescript/Wasm(更友好的 API,可在 npm 上获取): https://github.com/ngxson/wllama
Ruby: https://github.com/yoshoku/llama_cpp.rb
Ruby: https://github.com/docusealco/rllama
Rust(功能更丰富): https://github.com/edgenai/llama_cpp-rs
Rust(更友好的 API): https://github.com/mdrokz/rust-llama.cpp
Rust(更直接的绑定): https://github.com/utilityai/llama-cpp-rs
Rust(可从 crates.io 自动构建): https://github.com/ShelbyJenkins/llm_client
C#/.NET: https://github.com/SciSharp/LLamaSharp
C#/VB.NET(功能更丰富 - 社区许可证): LM-Kit.NET
Scala 3: https://github.com/donderom/llm4s
Clojure: https://github.com/phronmophobic/llama.clj
React Native: https://github.com/mybigday/llama.rn
Java: https://github.com/kherud/java-llama.cpp
Java: https://github.com/QuasarByte/llama-cpp-jna
Zig: https://github.com/Deins/llama.cpp.zig
Flutter/Dart: https://github.com/netdur/llama_cpp_dart
Flutter: https://github.com/xuegao-tzx/Fllama
PHP(基于 llama.cpp 构建的 API 绑定和功能): https://github.com/distantmagic/resonance https://github.com/ggml-org/llama.cpp/pull/6326
Guile Scheme: guile_llama_cpp
Swift: https://github.com/srgtuszy/llama-cpp-swift
Swift: https://github.com/ShenghaiWang/SwiftLlama
Delphi: https://github.com/Embarcadero/llama-cpp-delphi
Go(无需 CGo): https://github.com/hybridgroup/yzma
Android: llama.android
用户界面
(要在此处列出项目,该项目应明确说明其依赖于 llama.cpp)
工具
基础设施
llama-cli一个用于访问和试验 llama.cpp 大部分功能的 CLI 工具。
以对话模式运行
具有内置聊天模板的模型会自动激活对话模式。如果未自动激活,可通过添加 -cnv 并使用 --chat-template NAME 指定合适的聊天模板来手动启用。
llama-cli -m model.gguf
#
> hi, who are you?
# Hi there! I'm your helpful assistant! I'm an AI-powered chatbot designed to assist and provide information to users like you. I'm here to help answer your questions, provide guidance, and offer support on a wide range of topics. I'm a friendly and knowledgeable AI, and I'm always happy to help with anything you need. What's on your mind, and how can I assist you today?
#
#
> what is 1+1?
# Easy peasy! The answer to 1+1 is... 2!
使用自定义聊天模板运行对话模式
# 使用 "chatml" 模板(使用 -h 查看支持的模板列表)
llama-cli -m model.gguf -cnv --chat-template chatml
# 使用自定义模板
llama-cli -m model.gguf -cnv --in-prefix 'User: ' --reverse-prompt 'User:'
使用自定义语法约束输出
llama-cli -m model.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:'
# {"appointmentTime": "8pm", "appointmentDetails": "schedule a a call"}
grammars/ 文件夹包含一些示例语法。要编写自己的语法,请查看 GBNF 指南。
如需编写更复杂的 JSON 语法,请访问 [***]
llama-server一个轻量级、与 https://github.com/openai/openai-openapi 兼容的 HTTP 服务器,用于部署 LLM。
使用默认配置在 8080 端口启动本地 HTTP 服务器
llama-server -m model.gguf --port 8080
# 可通过浏览器访问基本 Web UI:http://localhost:8080
# 聊天补全端点:http://localhost:8080/v1/chat/completions
支持多用户和并行解码
# 最多 4 个并发请求,每个请求最大上下文为 4096
llama-server -m model.gguf -c 16384 -np 4
启用推测解码
# draft.gguf 模型应为目标 model.gguf 的小型变体
llama-server -m model.gguf -md draft.gguf
部署嵌入模型
# 使用 /embedding 端点
llama-server -m model.gguf --embedding --pooling cls -ub 8192
部署重排序模型
# 使用 /reranking 端点
llama-server -m model.gguf --reranking
使用语法约束所有输出
# 自定义语法
llama-server -m model.gguf --grammar-file grammar.gbnf
# JSON
llama-server -m model.gguf --grammar-file grammars/json.gbnf
XCFramework 是适用于 iOS、visionOS、tvOS 和 macOS 的预编译库版本。它可用于 Swift 项目,无需从源代码编译库。例如:
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyLlamaPackage",
targets: [
.executableTarget(
name: "MyLlamaPackage",
dependencies: [
"LlamaFramework"
]),
.binaryTarget(
name: "LlamaFramework",
url: "https://github.com/ggml-org/llama.cpp/releases/download/b5046/llama-b5046-xcframework.zip",
checksum: "c19be78b5f00d8d29a25da41042cb7afa094cbf6280a225abe614b03b20029ab"
)
]
)
上述示例使用的是库的中间构建版本 b5046。可以通过更改 URL 和校验和来修改为使用不同版本。
部分环境支持命令行补全。
Bash 补全
$ build/bin/llama-cli --completion-bash
> ~/.llama-completion.bash
$ source ~/.llama-completion.bash
也可以选择将其添加到 .bashrc 或 .bash_profile 中以自动加载。例如:
$ echo "source ~/.llama-completion.bash"
>> ~/.bashrc
llama-server 使用 - MIT license来自真实用户的反馈,见证轩辕镜像的优质服务