Instructions to use whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16 with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16 --local-dir LycheeAI-coder-2b-II-pro-MLX-bf16
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
README: 无损版说明(含 MLX / transformers 用法与踩坑)
Browse files
README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
tags:
|
| 7 |
+
- mlx
|
| 8 |
+
- bf16
|
| 9 |
+
- tool-calling
|
| 10 |
+
- function-calling
|
| 11 |
+
- minicpm
|
| 12 |
+
- chinese
|
| 13 |
+
base_model: openbmb/MiniCPM5-2B
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# LycheeAI-coder-2b-II-pro-MLX-bf16
|
| 17 |
+
|
| 18 |
+
> **无损版本(bfloat16)** · v7 · 基于 [MiniCPM5-2B](https://huggingface.co/openbmb/MiniCPM5-2B) · Apache 2.0 · **5.03 GB**
|
| 19 |
+
|
| 20 |
+
这是 [LycheeAI-coder-2b-II-pro](https://huggingface.co/whcl412/LycheeAI-coder-2b-II-pro) 的**未量化**版本:
|
| 21 |
+
LoRA adapter 已融合进基座,权重是 bf16 全精度,**没有经过任何量化**。
|
| 22 |
+
|
| 23 |
+
**MLX 和 transformers 都能直接加载**——它是标准 safetensors 格式,所以一套权重两种用法。
|
| 24 |
+
|
| 25 |
+
> **和 `-f16` 仓库的关系**:同一份权重。两个仓库名只是为了让不同用户都能找到它——
|
| 26 |
+
> 想在 MLX 上找无损版的人,看到 `-f16` 这个名字不会意识到"这个 MLX 也能用"。
|
| 27 |
+
> 如果你只想要一份,用哪个都行,字节完全相同。
|
| 28 |
+
>
|
| 29 |
+
> 国内用户推荐 ModelScope:[modelscope.cn/models/whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16](https://modelscope.cn/models/whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16)
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## 什么时候该用这个(而不是 4bit)
|
| 34 |
+
|
| 35 |
+
| 你的目的 | 用哪个 |
|
| 36 |
+
|---|---|
|
| 37 |
+
| 就想跑起来用,越省事越好 | [MLX 4bit](https://huggingface.co/whcl412/LycheeAI-coder-2b-II-pro)(1.42 GB) |
|
| 38 |
+
| **质量基准 / 要"没有量化误差"的结果** | ✅ **本仓库** |
|
| 39 |
+
| 在无损基础上做自己的量化(q4/q8/custom) | ✅ **本仓库** |
|
| 40 |
+
| 继续微调(续训 LoRA) | ✅ **本仓库**(4bit 不能训) |
|
| 41 |
+
| 转 GGUF | ✅ 本仓库,或直接用现成的 [GGUF 仓库](https://huggingface.co/whcl412/LycheeAI-coder-2b-II-pro-GGUF) |
|
| 42 |
+
| CUDA 卡上跑 | ✅ 本仓库 |
|
| 43 |
+
|
| 44 |
+
**一句话**:**要在它身上"再加工",就必须用这个版本**;只是想用它,4bit 更省。
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## 快速开始
|
| 49 |
+
|
| 50 |
+
### MLX
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
pip install mlx-lm
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from mlx_lm import load, generate
|
| 58 |
+
|
| 59 |
+
model, tok = load("whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16")
|
| 60 |
+
|
| 61 |
+
msgs = [
|
| 62 |
+
{"role": "system", "content": "你是 LycheeAI-coder-2b-II-pro,由 MiniCPM5-2B 通过 LoRA 微调而来的编程助手。回答简洁、直接,不谄媚;做不到的事直接说明,不要编造。"},
|
| 63 |
+
{"role": "user", "content": "递归是什么?一句话。"},
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
# ★ 必须套 chat template,否则会复读乱码(见下文"踩坑")
|
| 67 |
+
prompt = tok.apply_chat_template(msgs, tokenize=False,
|
| 68 |
+
add_generation_prompt=True,
|
| 69 |
+
enable_thinking=False)
|
| 70 |
+
print(generate(model, tok, prompt=prompt, max_tokens=256, verbose=False))
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
实测输出:
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
递归是**函数自己调用自己**。
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
命令行也行(`mlx_lm.generate` 自己会套模板):
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python -m mlx_lm.generate \
|
| 83 |
+
--model whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16 \
|
| 84 |
+
--prompt "用 Python 写一个二分查找,带注释。" \
|
| 85 |
+
--max-tokens 256 --temp 0.4
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### transformers
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 92 |
+
|
| 93 |
+
mid = "whcl412/LycheeAI-coder-2b-II-pro-MLX-bf16"
|
| 94 |
+
tok = AutoTokenizer.from_pretrained(mid, trust_remote_code=True)
|
| 95 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 96 |
+
mid, torch_dtype="bfloat16", device_map="auto", trust_remote_code=True)
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### 工具的用法
|
| 100 |
+
|
| 101 |
+
和 4bit 版完全一致——**模型输出裸 JSON**:
|
| 102 |
+
|
| 103 |
+
```json
|
| 104 |
+
{"name": "calculate", "arguments": {"expression": "789*123"}}
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
完整接入代码(含多步循环、JSON 兜底解析)见主仓库的
|
| 108 |
+
[宿主接入章节](https://huggingface.co/whcl412/LycheeAI-coder-2b-II-pro#工具调用)。
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
## ⚠️ 踩过的坑
|
| 113 |
+
|
| 114 |
+
**1. 不套 chat template 会复读。**
|
| 115 |
+
|
| 116 |
+
直接 `generate(model, tok, prompt="递归是什么?")` 会得到类似这样的东西:
|
| 117 |
+
|
| 118 |
+
```
|
| 119 |
+
还是说:递归是函数自己调用自己。区别很大,对吧。还是说:递归是**把问题缩小到更小的问题**。还是说:…
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
这不是模型坏了,是你喂的是**裸补全**而不是对话。用 `tok.apply_chat_template(...)`,
|
| 123 |
+
或者干脆用 `mlx_lm.generate` 命令行。
|
| 124 |
+
|
| 125 |
+
**2. `enable_thinking` 记得显式传 `False`。**
|
| 126 |
+
|
| 127 |
+
模板里有 `<think>` 开关,不传的话没有默认值,输出可能带游离的 `</think>`。
|
| 128 |
+
想要思考内容就传 `True`,它会单独出现(不混在回答里)。
|
| 129 |
+
|
| 130 |
+
**3. 加载比 4bit 慢、占内存多——这是正常的。**
|
| 131 |
+
|
| 132 |
+
实测对比(MacBook Pro M4 / 16GB):
|
| 133 |
+
|
| 134 |
+
| | MLX 4bit | 本仓库(bf16) |
|
| 135 |
+
|---|---|---|
|
| 136 |
+
| 磁盘 | 1.42 GB | 5.03 GB |
|
| 137 |
+
| 峰值内存 | 1.52 GB | ~5.5 GB |
|
| 138 |
+
| 冷启动 | 3.4 s | ~10 s |
|
| 139 |
+
|
| 140 |
+
差的是文件大小,不是模型质量——**两者输出质量的区别只来自量化误差**。
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
## 关于这个版本
|
| 145 |
+
|
| 146 |
+
| 项 | 值 |
|
| 147 |
+
|---|---|
|
| 148 |
+
| 基座 | MiniCPM5-2B(面壁智能 OpenBMB,Apache 2.0) |
|
| 149 |
+
| 精度 | **bfloat16(无量化)** |
|
| 150 |
+
| 微调 | LoRA(rank 8,16 层),已融合进基座 |
|
| 151 |
+
| 训练数据 | 精选 980 �� × 1 epoch(490 步) |
|
| 152 |
+
| 验收 | **26 / 27**(上一版 25/27) |
|
| 153 |
+
| 许可 | Apache 2.0(可商用) |
|
| 154 |
+
|
| 155 |
+
完整能力说明、局限、训练方法论见主仓库:
|
| 156 |
+
**[whcl412/LycheeAI-coder-2b-II-pro](https://huggingface.co/whcl412/LycheeAI-coder-2b-II-pro)**
|
| 157 |
+
|
| 158 |
+
**已知问题(简版)**:
|
| 159 |
+
① 无工具时算术会算错 → 在 system 里要求"一律调 calculate";
|
| 160 |
+
② 通用 system 下身份可能答错 → system 里写清身份;
|
| 161 |
+
③ 偶发控制字符 `\x08` → 输出前过滤;
|
| 162 |
+
④ 偶发工具名幻觉 → 宿主必须查注册表。
|
| 163 |
+
|
| 164 |
+
---
|
| 165 |
+
|
| 166 |
+
## 📁 文件说明
|
| 167 |
+
|
| 168 |
+
| 文件 | 大小 | 说明 |
|
| 169 |
+
|---|---|---|
|
| 170 |
+
| `model.safetensors` | 5,033,556,906 B | bf16 全精度权重(已融合 LoRA) |
|
| 171 |
+
| `model.safetensors.index.json` | — | 分片索引 |
|
| 172 |
+
| `config.json` | — | 无 `quantization` 字段(= 未量化) |
|
| 173 |
+
| `chat_template.jinja` | — | 含 tools 支持的完整对话模板 |
|
| 174 |
+
| `tokenizer.json` / `tokenizer_config.json` | — | 分词器 |
|
| 175 |
+
| `generation_config.json` | — | 生成默认参数 |
|
| 176 |
+
|
| 177 |
+
---
|
| 178 |
+
|
| 179 |
+
## 🙏 致谢
|
| 180 |
+
|
| 181 |
+
- 基座:[MiniCPM5-2B](https://huggingface.co/openbmb/MiniCPM5-2B)(面壁智能 OpenBMB)
|
| 182 |
+
- 许可:**Apache 2.0**
|
| 183 |
+
|
| 184 |
+
个人项目,欢迎提 issue。有用的话 [Bilibili 关注一下](https://space.bilibili.com/3493128967293256) 🤖
|