@sudoingX:每天都有人问我如何在理论上跑不动的硬件上运行bonsai 27b。所以这里全部内容在此……
摘要
一份详细指南,介绍如何在仅有8GB显存的硬件上运行27B Bonsai模型,使用1位量化版本和PrismML分支的llama.cpp,包含精确的服务器命令和配置。
查看缓存全文
缓存时间: 2026/07/21 01:36
每天都会有人问我,为什么我能在不支持的硬件上运行 Bonsai 27B。所以这里一次性说明白,存好。这个模型是 Qwen 3.6 27B 的 1-bit 量化版,磁盘占用不到 4GB,但有一个没人提过的关键点:标准 llama.cpp 无法加载它。1-bit 内核只在 @PrismML 的分支中存在。你需要构建那个分支,否则权重根本无法打开。http://github.com/PrismML-Eng/llama.cpp…,为你的架构开启 CUDA(3060 Ti 用 sm_86,1660 Super 用 sm_75)。然后启动服务。这是我用来在 8GB 显存上运行 128K 智能体时使用的精确命令:llama-server -m Bonsai-27B-Q1_0.gguf -ngl 99 -c 131072 -np 1 -fa --cache-type-k q4_0 --cache-type-v q4_0。-ngl 99 把每一层都放到 GPU 上,-c 131072 是完整的 128K 上下文窗口,-fa 开启 Flash Attention,q4 的 KV 缓存让它占用 6.8GB(8GB 中)而不会内存溢出。如果你的显卡需要共享显存给显示器,将 -c 降到 65536。全部技巧就这些:一个分支,一条命令,27B 模型本地运行。收藏它,当你重新启用那块显卡时你会需要的。
PrismML-Eng/llama.cpp
来源:https://github.com/PrismML-Eng/llama.cpp
llama.cpp
这是 llama.cpp 的 PrismML 分支。 它添加了 Bonsai (https://huggingface.co/collections/prism-ml/bonsai) 模型使用的
Q2_02-bit 量化。初次使用?请从 Bonsai-demo (https://github.com/PrismML-Eng/Bonsai-demo) 仓库开始。 它会自动为你的硬件/后端下载正确的模型和预构建二进制文件。
三元 (
Q2_0) 支持正在逐个后端地合并到主线的 llama.cpp 中,因此使用哪个构建版本 + 模型文件取决于你的运行环境:
*-Q2_0.gguf(组大小 128):本分支使用的格式。使用本分支的构建/发布版 (https://github.com/PrismML-Eng/llama.cpp/releases) 运行。无法在主线的 llama.cpp 中加载。*-Q2_0_g64.gguf(组大小 64):官方主线 llama.cpp 格式(目前支持 CPU 和 Metal)。请使用最近的ggml-org/llama.cpp构建版,而不是本分支。*-PQ2_0.gguf:计划中的未来分支格式,目前任何地方都不支持。请使用完整匹配的构建版本。不要将本分支的
ggml-*库放入标准 llama.cpp 构建中(ABI/格式不匹配,模型无法加载)。关于每个后端迁移状态的最新信息,请参阅 Bonsai-demo README 中的 Upstream Status for Ternary (https://github.com/PrismML-Eng/Bonsai-demo#upstream-status-for-ternary)。
llama
许可证:MIT (https://opensource.org/licenses/MIT)
发布版 (https://github.com/ggml-org/llama.cpp/releases)
服务端 (https://github.com/ggml-org/llama.cpp/actions/workflows/server.yml)
Docker (https://github.com/ggml-org/llama.cpp/actions/workflows/docker.yml)
Winget (https://github.com/ggml-org/llama.cpp/actions/workflows/winget.yml)
宣言 (https://github.com/ggml-org/llama.cpp/discussions/205) / ggml (https://github.com/ggml-org/ggml) / ops (https://github.com/ggml-org/llama.cpp/blob/master/docs/ops.md)
用 C/C++ 实现 LLM 推理
近期 API 变更
libllamaAPI 变更日志 (https://github.com/ggml-org/llama.cpp/issues/9289)llama-serverREST API 变更日志 (https://github.com/ggml-org/llama.cpp/issues/9291)
热门话题
- Hugging Face 缓存迁移:使用
-hf下载的模型现在存储在标准的 Hugging Face 缓存目录中,便于与其他 HF 工具共享。 - 指南:使用 llama.cpp 的新 WebUI (https://github.com/ggml-org/llama.cpp/discussions/16938)
- 指南:使用 llama.cpp 运行 gpt-oss (https://github.com/ggml-org/llama.cpp/discussions/15396)
- [反馈] 更好的 llama.cpp 打包以支持下游消费者 🤗
- 增加对
gpt-oss模型(原生 MXFP4 格式)的支持 | PR (https://github.com/ggml-org/llama.cpp/pull/15091) | 与 NVIDIA 合作 (https://blogs.nvidia.com/blog/rtx-ai-garage-openai-oss) | 评论 (https://github.com/ggml-org/llama.cpp/discussions/15095) - 多模态支持已加入
llama-server: #12898 (https://github.com/ggml-org/llama.cpp/pull/12898) | 文档 - VS Code 扩展(FIM 补全):https://github.com/ggml-org/llama.vscode
- Vim/Neovim 插件(FIM 补全):https://github.com/ggml-org/llama.vim
- Hugging Face Inference Endpoints 现已原生支持 GGUF!https://github.com/ggml-org/llama.cpp/discussions/9669
- Hugging Face GGUF 编辑器:讨论 (https://github.com/ggml-org/llama.cpp/discussions/9268) | 工具 (https://huggingface.co/spaces/CISCai/gguf-editor)
- WebGPU 支持现已可在浏览器中使用,这里有一篇博客/演示介绍它 (https://reeselevine.github.io/llamas-on-the-web/)。
快速开始
开始使用 llama.cpp 很简单。以下是在你的机器上安装它的几种方法:
- 使用 brew, nix 或 winget 安装
llama.cpp - 使用 Docker 运行——查看我们的 Docker 文档
- 从发布页面 (https://github.com/ggml-org/llama.cpp/releases) 下载预构建的二进制文件
- 克隆此仓库后从源码构建——查看 我们的构建指南
安装完成后,你需要一个模型来使用。请前往 获取和量化模型 部分了解更多。
示例命令:
``sh
使用本地模型文件
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 推理。
- 纯 C/C++ 实现,无任何依赖
- Apple Silicon 是一等公民——通过 ARM NEON、Accelerate 和 Metal 框架优化
- 支持 x86 架构的 AVX、AVX2、AVX512 和 AMX
- 支持 RISC-V 架构的 RVV、ZVFH、ZFH、ZICBOP 和 ZIHINTPAUSE
- 1.5-bit、2-bit、3-bit、4-bit、5-bit、6-bit 和 8-bit 整数量化,实现更快的推理和更少的内存使用
- 自定义 CUDA 内核,用于在 NVIDIA GPU 上运行 LLM(通过 HIP 支持 AMD GPU,通过 MUSA 支持 Moore Threads GPU)
- Vulkan 和 SYCL 后端支持
- CPU+GPU 混合推理,可部分加速比总 VRAM 容量更大的模型
llama.cpp 项目是为 ggml (https://github.com/ggml-org/ggml) 库开发新功能的主要试验场。
模型
通常,以下基础模型的微调版本也受支持。添加新模型支持的说明:HOWTO-add-model.md
仅文本
- LLaMA 🦙
- LLaMA 2 🦙🦙
- LLaMA 3 🦙🦙🦙
- Mistral 7B (https://huggingface.co/mistralai/Mistral-7B-v0.1)
- Mixtral MoE (https://huggingface.co/models?search=mistral-ai/Mixtral)
- DBRX (https://huggingface.co/databricks/dbrx-instruct)
- Jamba (https://huggingface.co/ai21labs)
- Falcon (https://huggingface.co/models?search=tiiuae/falcon)
- Chinese LLaMA / Alpaca (https://github.com/ymcui/Chinese-LLaMA-Alpaca) 和 Chinese LLaMA-2 / Alpaca-2 (https://github.com/ymcui/Chinese-LLaMA-Alpaca-2)
- Vigogne (法语) (https://github.com/bofenghuang/vigogne)
- BERT (https://github.com/ggml-org/llama.cpp/pull/5423)
- Koala (https://bair.berkeley.edu/blog/2023/04/03/koala/)
- Baichuan 1 & 2 (https://huggingface.co/models?search=baichuan-inc/Baichuan) + 衍生版本 (https://huggingface.co/hiyouga/baichuan-7b-sft)
- Aquila 1 & 2 (https://huggingface.co/models?search=BAAI/Aquila)
- Starcoder 模型 (https://github.com/ggml-org/llama.cpp/pull/3187)
- Refact (https://huggingface.co/smallcloudai/Refact-1_6B-fim)
- MPT (https://github.com/ggml-org/llama.cpp/pull/3417)
- Bloom (https://github.com/ggml-org/llama.cpp/pull/3553)
- Yi 模型 (https://huggingface.co/models?search=01-ai/Yi)
- StableLM 模型 (https://huggingface.co/stabilityai)
- Deepseek 模型 (https://huggingface.co/models?search=deepseek-ai/deepseek)
- Qwen 模型 (https://huggingface.co/models?search=Qwen/Qwen)
- PLaMo-13B (https://github.com/ggml-org/llama.cpp/pull/3557)
- Phi 模型 (https://huggingface.co/models?search=microsoft/phi)
- PhiMoE (https://github.com/ggml-org/llama.cpp/pull/11003)
- GPT-2 (https://huggingface.co/gpt2)
- Orion 14B (https://github.com/ggml-org/llama.cpp/pull/5118)
- InternLM2 (https://huggingface.co/models?search=internlm2)
- CodeShell (https://github.com/WisdomShell/codeshell)
- Gemma (https://ai.google.dev/gemma)
- Mamba (https://github.com/state-spaces/mamba)
- Grok-1 (https://huggingface.co/keyfan/grok-1-hf)
- Xverse (https://huggingface.co/models?search=xverse)
- Command-R 模型 (https://huggingface.co/models?search=CohereForAI/c4ai-command-r)
- SEA-LION (https://huggingface.co/models?search=sea-lion)
- GritLM-7B (https://huggingface.co/GritLM/GritLM-7B) + GritLM-8x7B (https://huggingface.co/GritLM/GritLM-8x7B)
- OLMo (https://allenai.org/olmo)
- OLMo 2 (https://allenai.org/olmo)
- OLMoE (https://huggingface.co/allenai/OLMoE-1B-7B-0924)
- Granite 模型 (https://huggingface.co/collections/ibm-granite/granite-code-models-6624c5cec322e4c148c8b330)
- GPT-NeoX (https://github.com/EleutherAI/gpt-neox) + Pythia (https://github.com/EleutherAI/pythia)
- Snowflake-Arctic MoE (https://huggingface.co/collections/Snowflake/arctic-66290090abe542894a5ac520)
- Smaug (https://huggingface.co/models?search=Smaug)
- Poro 34B (https://huggingface.co/LumiOpen/Poro-34B)
- Bitnet b1.58 模型 (https://huggingface.co/1bitLLM)
- Flan T5 (https://huggingface.co/models?search=flan-t5)
- Open Elm 模型 (https://huggingface.co/collections/apple/openelm-instruct-models-6619ad295d7ae9f868b759ca)
- ChatGLM3-6b (https://huggingface.co/THUDM/chatglm3-6b) + ChatGLM4-9b (https://huggingface.co/THUDM/glm-4-9b) + GLMEdge-1.5b (https://huggingface.co/THUDM/glm-edge-1.5b-chat) + GLMEdge-4b (https://huggingface.co/THUDM/glm-edge-4b-chat)
- GLM-4-0414 (https://huggingface.co/collections/THUDM/glm-4-0414-67f3cbcb34dd9d252707cb2e)
- SmolLM (https://huggingface.co/collections/HuggingFaceTB/smollm-6695016cad7167254ce15966)
- EXAONE-3.0-7.8B-Instruct (https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct)
- FalconMamba 模型 (https://huggingface.co/collections/tiiuae/falconmamba-7b-66b9a580324dd1598b0f6d4a)
- Jais (https://huggingface.co/inceptionai/jais-13b-chat)
- Bielik-11B-v2.3 (https://huggingface.co/collections/speakleash/bielik-11b-v23-66ee813238d9b526a072408a)
- RWKV-7 (https://huggingface.co/collections/shoumenchougou/rwkv7-gxx-gguf)
- RWKV-6 (https://github.com/BlinkDL/RWKV-LM)
- QRWKV-6 (https://huggingface.co/recursal/QRWKV6-32B-Instruct-Preview-v0.1)
- GigaChat-20B-A3B (https://huggingface.co/ai-sage/GigaChat-20B-A3B-instruct)
- Trillion-7B-preview (https://huggingface.co/trillionlabs/Trillion-7B-preview)
- Ling 模型 (https://huggingface.co/collections/inclusionAI/ling-67c51c85b34a7ea0aba94c32)
- LFM2 模型 (https://huggingface.co/collections/LiquidAI/lfm2-686d721927015b2ad73eaa38)
- Hunyuan 模型 (https://huggingface.co/collections/tencent/hunyuan-dense-model-6890632cda26b19119c9c5e7)
- BailingMoeV2 (Ring/Ling 2.0) 模型 (https://huggingface.co/collections/inclusionAI/ling-v2-68bf1dd2fc34c306c1fa6f86)
- Mellum 模型 (https://huggingface.co/JetBrains/models?search=mellum)
多模态
- LLaVA 1.5 模型 (https://huggingface.co/collections/liuhaotian/llava-15-653aac15d994e992e2677a7e), LLaVA 1.6 模型 (https://huggingface.co/collections/liuhaotian/llava-16-65b9e40155f60fd046a5ccf2)
- BakLLaVA (https://huggingface.co/models?search=SkunkworksAI/Bakllava)
- Obsidian (https://huggingface.co/NousResearch/Obsidian-3B-V0.5)
- ShareGPT4V (https://huggingface.co/models?search=Lin-Chen/ShareGPT4V)
- MobileVLM 1.7B/3B 模型 (https://huggingface.co/models?search=mobileVLM)
- Yi-VL (https://huggingface.co/models?search=Yi-VL)
- Mini CPM (https://huggingface.co/models?search=MiniCPM)
- Moondream (https://huggingface.co/vikhyatk/moondream2)
- Bunny (https://github.com/BAAI-DCAI/Bunny)
- GLM-EDGE (https://huggingface.co/models?search=glm-edge)
- Qwen2-VL (https://huggingface.co/collections/Qwen/qwen2-vl-66cee7455501d7126940800d)
- LFM2-VL (https://huggingface.co/collections/LiquidAI/lfm2-vl-68963bbc84a610f7638d5ffa)
绑定
- Python: ddh0/easy-llama (https://github.com/ddh0/easy-llama)
- Python: abetlen/llama-cpp-python (https://github.com/abetlen/llama-cpp-python)
- Go: go-skynet/go-llama.cpp (https://github.com/go-skynet/go-llama.cpp)
- Node.js: withcatai/node-llama-cpp (https://github.com/withcatai/node-llama-cpp)
- JS/TS (llama.cpp 服务端客户端): lgrammel/modelfusion (https://modelfusion.dev/integration/model-provider/llamacpp)
- JS/TS (可编程 Prompt 引擎 CLI): offline-ai/cli (https://github.com/offline-ai/cli)
- JavaScript/Wasm (可在浏览器中运行): tangledgroup/llama-cpp-wasm (https://github.com/tangledgroup/llama-cpp-wasm)
- Typescript/Wasm (更友好的 API,可在 npm 上获取): ngxson/wllama (https://github.com/ngxson/wllama)
- Ruby: yoshoku/llama_cpp.rb (https://github.com/yoshoku/llama_cpp.rb)
- Ruby: docusealco/rllama (https://github.com/docusealco/rllama)
- Rust (更多功能): edgenai/llama_cpp-rs (https://github.com/edgenai/llama_cpp-rs)
- Rust (更友好的 API): mdrokz/rust-llama.cpp (https://github.com/mdrokz/rust-llama.cpp)
- Rust (更直接的绑定): utilityai/llama-cpp-rs (https://github.com/utilityai/llama-cpp-rs)
- Rust (从 crates.io 自动构建): ShelbyJenkins/llm_client (https://github.com/ShelbyJenkins/llm_client)
- C#/.NET: SciSharp/LLamaSharp (https://github.com/SciSharp/LLamaSharp)
- C#/VB.NET (更多功能 - 社区许可证): LM-Kit.NET (https://docs.lm-kit.com/lm-kit-net/index.html)
- Scala 3: donderom/llm4s (https://github.com/donderom/llm4s)
- Clojure: phronmophobic/llama.clj (https://github.com/phronmophobic/llama.clj)
- React Native: mybigday/llama.rn (https://github.com/mybigday/llama.rn)
- Java: kherud/java-llama.cpp (https://github.com/kherud/java-llama.cpp)
- Java: QuasarByte/llama-cpp-jna (https://github.com/QuasarByte/llama-cpp-jna)
- Zig: deins/llama.cpp.zig (https://github.com/Deins/llama.cpp.zig)
- Flutter/Dart: netdur/llama_cpp_dart (https://github.com/netdur/llama_cpp_dart)
- Flutter: xuegao-tzx/Fllama (https://github.com/xuegao-tzx/Fllama)
- PHP (基于 llama.cpp 构建的 API 绑定和功能): distantmagic/resonance (https://github.com/distantmagic/resonance) (更多信息) (https://github.com/ggml-org/llama.cpp/pull/6326)
- Guile Scheme: guile_llama_cpp (https://savannah.nongnu.org/projects/guile-llama-cpp)
- Swift: srgtuszy/llama-cpp-swift (https://github.com/srgtuszy/llama-cpp-swift)
- Swift: ShenghaiWang/SwiftLlama (https://github.com/ShenghaiWang/SwiftLlama)
- Delphi: Embarcadero/llama-cpp-delphi (https://github.com/Embarcadero/llama-cpp-delphi)
- Go (无需 CGo): hybridgroup/yzma (https://github.com/hybridgroup/yzma)
- Android: llama.android
用户界面
(要使项目在此处列出,它应明确说明依赖于 llama.cpp)
- AI Sublime Text 插件 (https://github.com/yaroslavyaroslav/OpenAI-sublime-text) (MIT)
- BonzAI App (https://apps.apple.com/us/app/bonzai-your-local-ai-agent/id6752847988) (专有)
- cztomsik/ava (https://github.com/cztomsik/ava) (MIT)
- Dot (https://github.com/alexpinel/Dot) (GPL)
- eva (https://github.com/ylsdamxssjxxdd/eva) (MIT)
- iohub/collama (https://github.com/iohub/coLLaMA) (Apache-2.0)
- janhq/jan (https://github.com/janhq/jan) (AGPL)
- johnbean393/Sidekick (https://github.com/johnbean393/Sidekick) (MIT)
- KanTV (https://github.com/zhouwg/kantv?tab=readme-ov-file) (Apache-2.0)
- KodiBot (https://github.com/firatkiral/kodibot) (GPL)
相似文章
如何运行 Prism Bonsai 27B
使用 llama.cpp 运行 Prism Bonsai 27B 的逐步指南,包含 GGUF 量化、编译及服务器设置。
我在8GB显存下在Terminal-Bench 2.0上运行了Ternary-Bonsai-27B(2-bit)和Bonsai-27B(1-bit)
一位用户在Terminal-Bench 2.0上测试了27B参数Bonsai模型的量化1-bit和2-bit版本,在8GB显存内获得了结果。
Bonsai 27B:使用自定义WebGPU内核在浏览器中本地运行的1比特密集型大语言模型
Bonsai 27B是一个1比特密集型大语言模型,通过使用自定义WebGPU内核可以在浏览器中本地运行,实现高效的设备端推理。
@xenovacom: Bonsai 27B 彻底改变了本地 LLM 的游戏规则。1位量化将其从 54GB 缩小到仅 3.8GB(减少 93%),同时……
Bonsai 27B 通过 1 位量化实现了 93% 的体积缩减,同时保留了 90% 的智能,借助自定义 WebGPU 内核实现本地浏览器推理。
Bonsai 27B(1位LLM):首个能在手机上运行的27B级别模型
PrismML宣布推出Bonsai 27B,这是Qwen3.6 27B的1位与三元量化版本,可在手机和笔记本电脑上运行,保留基线性能的90-95%,占用3.9GB空间,支持自主智能体与多模态的端侧AI。