Ternary Bonsai 2 27B:把 27B 模型压进 5.9GB,三值量化怎么做到的

Ternary Bonsai 2 27B: How PrismML Squeezed a 27B Model Into 5.9GB with Ternary Quantization

Tech-Experiment #本地模型#开源模型#量化#Apple Silicon#AI工具
🇨🇳 中文

27B 参数模型,5.9 GB 跑起来。

这不是靠激进降精度做到的——Ternary Bonsai 2 27B 用的方法不一样:把每个权重的数值空间从浮点数压缩到三个整数 {-1, 0, +1}。

HuggingFace: https://huggingface.co/prism-ml/Ternary-Bonsai-2-27B-gguf | Apache 2.0 | PrismML


三值量化是什么

传统 2-bit 量化把权重映射到 0/1/2/3 共四个值,而 Ternary 量化只用三个值:{-1, 0, +1}。看起来精度更低,实际上有额外补偿机制:

每 128 个权重共享一个 FP16 缩放因子(scale factor)。核心变换是 Hadamard 旋转——在量化之前对权重矩阵做正交变换,把权重分布调整得更均匀,让 {-1, 0, +1} 三个值能够尽量贴近原始浮点值的分布。

结果:权重位宽很低,但信息损失比直接截断要小得多。


两个 GGUF 变体

变体位宽文件大小适用场景
PTQ1_0(dense trits)1.75 bits/weight5.95 GB内存受限,CPU 推理
PQ2_0(2-bit slots)2.13 bits/weight7.21 GBGPU 加速,速度更快

PTQ1_0 是面积最小的选项,PQ2_0 在 GPU 上跑得更快。


性能对比:和竞品比

模型综合得分文件大小
Qwen3.8-27B FP1686.3254 GB
Ternary Bonsai 2(PTQ1_0)84.785.9 GB
Q4_K_XL85.1817.6 GB
IQ2_XXS72.599.4 GB

几个值得注意的数字:

  • vs FP16:损失 1.54 分,体积缩小 9 倍,性能保留 98.2%
  • vs Q4_K_XL:分数差 0.4 分(几乎打平),体积是它的 1/3
  • vs IQ2_XXS:比它高 12 分,体积还比它小 37%

IQ2_XXS 是当前常用的激进 2-bit 量化方案之一。Bonsai 2 不只是”和它差不多”,而是在更小体积下明显更好。


速度参考(PQ2_0 变体,tok/s)

硬件生成速度
RTX 5090130 tok/s
H100114 tok/s
RTX 409081 tok/s
Apple M5 Max47 tok/s
Apple M5 Pro28 tok/s

M5 Pro 28 tok/s 对话完全够用。RTX 3060 12GB 也有社区测试报告,能跑但速度未公布。


分类损失:哪里扣分了

量化不均匀——有的任务受影响更大:

类别相对 FP16 变化
指令遵循+1.41(反而更好)
代码生成+0.35
数学推理-0.49
工具调用-1.82

工具调用损失最大(-1.82 分)。如果你的主要用途是 AI Agent / Function Calling,这个数字需要注意。


基础模型:Qwen3.8-27B 不是简单的 27B

底层是 Qwen3.8-27B(27.36B 参数总计:24.35B LM 主体 + 2.54B 嵌入 + 0.46B 视觉塔)。架构:混合注意力(75% 线性注意力 + 25% 完整注意力),SwiGLU 激活,RoPE 位置编码,RMSNorm,支持 262K 上下文。

三值量化在这个架构上量化的是 LM 主体权重,视觉塔通常保持更高精度。


部署现实:标准工具暂时用不了

⚠️ LM Studio 和 Ollama 目前无法原生运行这个模型。

原因:PTQ1_0 和 PQ2_0 是 PrismML 自定义的张量类型(type 142/143),标准 llama.cpp 不认识,也没有 Hadamard 旋转的实现。上游 Issue #29058(“Support Prism PQ2_0 type 142 and PTQ1_0 type 143”)仍处于开放状态。

可以运行的路径:

1. PrismML 自定义 llama.cpp fork(推荐)

git clone https://github.com/PrismML-Eng/llama.cpp
cd llama.cpp && cmake -B build && cmake --build build -j
# 然后按 Bonsai-demo 的 README 操作

参考仓库:https://github.com/PrismML-Eng/Bonsai-demo

2. MLX(Mac 专用,无需特殊配置)

# 无需自定义工具,标准 mlx-lm 运行
pip install mlx-lm
mlx_lm.generate --model prism-ml/Ternary-Bonsai-2-27B-mlx-2bit \
  --prompt "你好"

Mac M 系列用户推荐这条路,正常的 mlx-lm 就能跑。

3. OpenRouter(不想自己部署) 模型 ID:prism-ml/ternary-bonsai-2-27b,$0.075/M input,$0.50/M output。


WebGPU 版本

PrismML 还发布了一个 WebGPU Kernels HuggingFace Space,理论上可以在支持 WebGPU 的浏览器里直接跑,但社区反馈有在测试 prompt 下循环卡死的问题,稳定性待观察。


一句话说清楚

Ternary Bonsai 2 27B 把每个权重压成 {-1, 0, +1},Hadamard 旋转补偿精度损失,5.9GB 保留 98.2% 性能——这是目前在 8-16GB 内存上能跑的质量最好的 27B 量化模型之一。部署门槛:需要 PrismML 自定义 llama.cpp,Mac 用 MLX 无此限制。工具调用场景慎用(-1.82 分损失)。


Apache 2.0 许可。PrismML 2026-09-17 发布,Google v5 TPU 训练。开源仅供学习参考。


🇬🇧 English

Ternary Bonsai 2 27B: How PrismML Squeezed a 27B Model Into 5.9GB with Ternary Quantization

A 27B parameter model running in 5.9 GB. Not through aggressive precision reduction — through a different approach: compressing each weight’s value space to just three integers: {-1, 0, +1}.

HuggingFace: https://huggingface.co/prism-ml/Ternary-Bonsai-2-27B-gguf | Apache 2.0 | PrismML


What Ternary Quantization Does

Standard 2-bit quantization maps weights to {0, 1, 2, 3}. Ternary uses only {-1, 0, +1} — seemingly less precision, but with a compensation mechanism: every 128 weights share one FP16 scale factor.

The key transformation is a Hadamard rotation — an orthogonal transform applied to the weight matrix before quantization, redistributing weight values so the three-state approximation fits the distribution better.

Result: very low bit-width, but significantly less information loss than naive truncation.


Two GGUF Variants

VariantBit-widthFile sizeBest for
PTQ1_0 (dense trits)1.75 bits/weight5.95 GBMemory-constrained, CPU
PQ2_0 (2-bit slots)2.13 bits/weight7.21 GBGPU acceleration

PTQ1_0 for minimum footprint, PQ2_0 for speed on GPU.


Performance Against Competitors

ModelScoreSize
Qwen3.8-27B FP1686.3254 GB
Ternary Bonsai 2 (PTQ1_0)84.785.9 GB
Q4_K_XL85.1817.6 GB
IQ2_XXS72.599.4 GB

Key comparisons:

  • vs FP16: -1.54 points, 9× smaller, 98.2% retained
  • vs Q4_K_XL: nearly tied (-0.4 pts), at one-third the size
  • vs IQ2_XXS: +12 points with a 37% smaller file

Speed (PQ2_0, tok/s)

HardwareSpeed
RTX 5090130 tok/s
H100114 tok/s
RTX 409081 tok/s
Apple M5 Max47 tok/s
Apple M5 Pro28 tok/s

M5 Pro at 28 tok/s is comfortable for conversation.


Category-Level Losses

Categoryvs FP16
Instruction following+1.41 (better)
Code generation+0.35
Math reasoning-0.49
Tool calling-1.82

Tool calling takes the biggest hit (-1.82). Flag this if your use case is AI agent / function calling.


Deployment Reality: Standard Tools Don’t Work Yet

⚠️ LM Studio and Ollama cannot run this model natively.

PTQ1_0 and PQ2_0 are custom tensor types (type 142/143) that stock llama.cpp doesn’t recognize. Upstream Issue #29058 is still open.

Working paths:

1. PrismML’s custom llama.cpp fork (recommended for non-Mac)

git clone https://github.com/PrismML-Eng/llama.cpp
cd llama.cpp && cmake -B build && cmake --build build -j
# follow Bonsai-demo README

2. MLX (Mac only, works with standard tools)

pip install mlx-lm
mlx_lm.generate --model prism-ml/Ternary-Bonsai-2-27B-mlx-2bit \
  --prompt "hello"

No custom tooling needed for Mac M-series.

3. OpenRouter (no local setup): prism-ml/ternary-bonsai-2-27b, $0.075/M input, $0.50/M output.


Apache 2.0 license. Released by PrismML on 2026-09-17, trained on Google v5 TPU. For technical reference only.

💬 评论与讨论

使用 GitHub 账号登录后发表评论

关于本站 · 免责声明

🍄 Mushroom Research Blog 是非营利、免费公开的个人科技观察博客与公众号 XStack18,不接受商业合作、不代表任何企业或机构立场,也不谋求商业利益。我们以个人视角客观中立地记录和分析 AI、Web3 等领域的最新模型发布与技术动态——不止转述新闻标题或二手信息,而是给出有独立思考的深入分析,希望帮更多人获得有价值的一手科技认知。

⚠️ 文中介绍的开源代码与模型,仅供学习交流与技术借鉴。它们大多仍处于早期阶段,有待进一步研究和验证,请勿直接用于工作或生产环境;如需采用,请先自行充分测试,并核实其许可证与安全性。
Open-source code and models featured here are shared for learning and reference only. Most are early-stage and still need further study and verification — please don't use them directly in your work or in production. Test them thoroughly and check their licenses and security first.

  1. 本站文章均为作者基于公开信息的个人研究与观点整理,不代表文中提及的任何公司、产品、模型的官方立场,未与其构成商业关联或合作关系。
  2. 科技行业信息更新极快,我们尽力保证内容准确、及时,但不对完整性、实时性做绝对保证,具体请以相关企业/项目官方公告为准。
  3. 文中引用的第三方商标、产品名称、图片、数据等版权归原权利人所有,我们会尽量注明来源;如你认为存在版权疑问或侵权,请通过下方邮箱联系我们,收到通知后会尽快核实处理(更正、加注来源或删除)。
  4. 文章内容仅为技术科普与个人观点,不构成投资、法律或其他专业建议,据此进行任何决策的后果需自行判断和承担。

📮 侵权 / 勘误 / 合作咨询:[email protected]