Instructions to use tchbcb/MiniCPM5-2B-cpu-mixed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use tchbcb/MiniCPM5-2B-cpu-mixed with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf tchbcb/MiniCPM5-2B-cpu-mixed # Run inference directly in the terminal: llama cli -hf tchbcb/MiniCPM5-2B-cpu-mixed
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf tchbcb/MiniCPM5-2B-cpu-mixed # Run inference directly in the terminal: llama cli -hf tchbcb/MiniCPM5-2B-cpu-mixed
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf tchbcb/MiniCPM5-2B-cpu-mixed # Run inference directly in the terminal: ./llama-cli -hf tchbcb/MiniCPM5-2B-cpu-mixed
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf tchbcb/MiniCPM5-2B-cpu-mixed # Run inference directly in the terminal: ./build/bin/llama-cli -hf tchbcb/MiniCPM5-2B-cpu-mixed
Use Docker
docker model run hf.co/tchbcb/MiniCPM5-2B-cpu-mixed
- LM Studio
- Jan
- Ollama
How to use tchbcb/MiniCPM5-2B-cpu-mixed with Ollama:
ollama run hf.co/tchbcb/MiniCPM5-2B-cpu-mixed
- Unsloth Desktop
- Docker Model Runner
How to use tchbcb/MiniCPM5-2B-cpu-mixed with Docker Model Runner:
docker model run hf.co/tchbcb/MiniCPM5-2B-cpu-mixed
- Lemonade
How to use tchbcb/MiniCPM5-2B-cpu-mixed with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull tchbcb/MiniCPM5-2B-cpu-mixed
Run and chat with the model
lemonade run user.MiniCPM5-2B-cpu-mixed-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
add README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MiniCPM5-2B-cpu-mixed — 混合精度量化权重 (4-bit 主体 / 8-bit 边缘层 / 3值部分层)
|
| 2 |
+
|
| 3 |
+
本仓库是 [tchbcb/MiniCPM5-2B-cpu](https://huggingface.co/tchbcb/MiniCPM5-2B-cpu)(MiniCPM-2B)的**混合精度 CPU 量化版本**,配套一个零依赖的 AVX2 C 推理服务器。
|
| 4 |
+
|
| 5 |
+
## 权重文件
|
| 6 |
+
|
| 7 |
+
`minicpm_mixed.bin` — 单文件混合精度权重容器(1.56 GiB,bf16 原始 5.03 GB → **3.2× 压缩**)。
|
| 8 |
+
|
| 9 |
+
容器格式:`magic('MCPQ') | count | [key_len | key | ndim | dims | qtype | payload_len | payload]...`
|
| 10 |
+
|
| 11 |
+
## 混合精度分布(294 个权重矩阵)
|
| 12 |
+
|
| 13 |
+
| 类型 | 矩阵数 | 说明 |
|
| 14 |
+
|------|--------|------|
|
| 15 |
+
| Q8_0 (8-bit block q) | 14 | 第 0 / 41 层(网络首尾边缘层,对量化敏感) |
|
| 16 |
+
| Q4_K (4-bit, llama.cpp 兼容超块) | 272 | 主体权重,6-bit scale + 4-bit sub-block min/max |
|
| 17 |
+
| TERNARY (3值, {-1,0,+1}) | 8 | 自适应余弦门控挑选(cos ≥ 0.897 的 top-8,块级最小二乘 scale,TWN 阈值) |
|
| 18 |
+
| Q8 row-wise | embed + lm_head | 词嵌入与输出头(512 MB) |
|
| 19 |
+
| F32 | 所有 norm | RMSNorm/Attention/QKV-Norm 全程保持 FP32 |
|
| 20 |
+
|
| 21 |
+
## 质量方案
|
| 22 |
+
|
| 23 |
+
- 三值量化采用 **TWN(Trained Ternary Weight Networks)阈值** `δ = 0.7·mean(|W|)` 产生三值矩阵,再用**块级最小二乘**求 scale:`s* = Σ|W|·T / ΣT²`,避免 absmean 幅度塌缩(余弦相似度从 ~0.80 提升到 ~0.897)。
|
| 24 |
+
- 对全部 48 个候选矩阵计算与原 bf16 权重的**余弦相似度**,仅保留 cos ≥ 0.897 的 top-8 做三值,其余自动回退 Q4_K。
|
| 25 |
+
|
| 26 |
+
## CPU 推理服务器
|
| 27 |
+
|
| 28 |
+
`server/minicpm_server.c`(~850 行 C,单文件零依赖,仅 Windows API + AVX2):
|
| 29 |
+
|
| 30 |
+
- LlamaForCausalLM 前向:GQA(16 Q heads / 2 KV heads)、RoPE theta=5e6、SwiGLU
|
| 31 |
+
- 混合精度逐矩阵分发:Q8row / Q8_0 / Q4_K / TERNARY 各自内核
|
| 32 |
+
- TERNARY 内核:bit0/bit1 位流 + LUT 展开 + `maddubs`/`madd` AVX2
|
| 33 |
+
- Q4_K 内核与 llama.cpp 位级兼容
|
| 34 |
+
- `CreateFileMapping` mmap 权重、QPC 精确计时、greedy longest-match BPE、MiniCPM5 chat template
|
| 35 |
+
|
| 36 |
+
## 性能(i5-4258U 2C4T / 16 GB / Windows 11,纯 CPU)
|
| 37 |
+
|
| 38 |
+
| 线程 | 生成速度 |
|
| 39 |
+
|------|---------|
|
| 40 |
+
| 1 | 3.5 tok/s |
|
| 41 |
+
| 2 | 5.3 tok/s |
|
| 42 |
+
| 4 | 5.5 tok/s |
|
| 43 |
+
|
| 44 |
+
运行内存占用 ≈ 1.8 GB RSS。
|
| 45 |
+
|
| 46 |
+
## 转换脚本
|
| 47 |
+
|
| 48 |
+
```
|
| 49 |
+
python convert_minicpm_mixed.py --model <safetensors 目录> --out minicpm_mixed.bin
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
`vocab.tsv` 为从 tokenizer.json 预提取的词表(id / token / score 三列),供服务器 tokenizer 使用。
|