Cialtion commited on
Commit
8953176
·
verified ·
1 Parent(s): 27b87f5

Update .ipynb_checkpoints/README_zh-checkpoint.md

Browse files
.ipynb_checkpoints/README_zh-checkpoint.md ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <a href="README.md">English</a> | <a href="README_zh.md">中文</a>
3
+ </p>
4
+ <h1 align="center">SimpleTool</h1>
5
+
6
+ <p align="center">
7
+ <b>面向实时 LLM 函数调用的并行解码架构</b>
8
+ </p>
9
+
10
+ <p align="center">
11
+ <a href="https://arxiv.org/abs/2603.00030"><img src="https://img.shields.io/badge/arXiv-2603.00030-red"></a>
12
+ <a href="https://huggingface.co/Cialtion/SimpleTool"><img src="https://img.shields.io/badge/🤗-Models-yellow"></a>
13
+ <a href="https://www.modelscope.cn/models/cialtion/SimpleTool"><img src="https://img.shields.io/badge/ModelScope-Models-blue"></a>
14
+ <a href="#演示视频"><img src="https://img.shields.io/badge/Bilibili-Demo-00A1D6?logo=bilibili&logoColor=white"></a>
15
+ <a href="#演示视频"><img src="https://img.shields.io/badge/YouTube-Demo-FF0000?logo=youtube&logoColor=white"></a>
16
+ <a href="#许可证"><img src="https://img.shields.io/badge/License-Apache%202.0-green"></a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ 一个 4B 参数的 LLM,实现 <b>16 Hz 端到端实时函数调用</b>——足以驱动游戏 AI、机械臂控制和数字人动画。
21
+ </p>
22
+
23
+ ---
24
+
25
+ SimpleTool 通过多头并行解码实现**实时 LLM 函数调用**。我们引入特殊 token 来压缩结构化输出中的冗余信息(4–6 倍压缩),并让函数名与各参数独立并行生成,从而实现**端到端 3–6 倍加速**,同时在三大应用场景——**游戏**、**机械臂控制**和**数字人动画**——中保持具有竞争力的准确率。
26
+
27
+ <p align="center">
28
+ <img src="assets/fig_title_panel_a.png" alt="SimpleTool 概览" width="700">
29
+ </p>
30
+
31
+ ## 工作原理
32
+
33
+ 传统函数调用按顺序逐 token 生成——`function → arg1 → arg2 → ...`——延迟随输出长度线性增长。SimpleTool 基于两个关键观察:
34
+
35
+ 1. **Token 冗余**:结构化输出中存在大量可预测的 token(括号、参数名、引号等),可以压缩为单个特殊 token。
36
+ 2. **弱因果依赖**:函数的各个参数之间基本相互独立,可以并行生成。
37
+
38
+ <p align="center">
39
+ <img src="assets/overview.png" alt="SimpleTool 架构" width="600">
40
+ </p>
41
+
42
+ 将函数名和各参数作为共享同一前缀 KV 缓存的并行流进行解码,延迟从 `sum(所有token耗时)` 降为 `max(单头耗时)`。并行解码头利用了解码阶段显存带宽受限时的闲置算力,使得并行化几乎零开销。
43
+
44
+ 更多细节请参阅我们的 [arXiv 论文](https://arxiv.org/abs/2603.00030)。
45
+
46
+ ---
47
+
48
+ ## 快速上手
49
+
50
+ ### 1. 配置环境
51
+
52
+ ```bash
53
+ git clone https://github.com/HaxxorCialtion/SimpleTool.git
54
+ cd SimpleTool
55
+ ```
56
+
57
+ **方案 A — uv(推荐)**
58
+ ```bash
59
+ uv venv env_rt -p python3.12
60
+ source env_rt/bin/activate
61
+ uv pip install -r requirements.txt
62
+ ```
63
+
64
+ **方案 B — conda**
65
+ ```bash
66
+ conda create -n simpletool python=3.12 -y
67
+ conda activate simpletool
68
+ pip install -r requirements.txt
69
+ ```
70
+
71
+ **方案 C — pip**
72
+ ```bash
73
+ python3.12 -m venv env_rt
74
+ source env_rt/bin/activate
75
+ pip install -r requirements.txt
76
+ ```
77
+
78
+ ### 2. 下载模型
79
+
80
+ 默认推荐模型为 **RT-Qwen3-4B-AWQ-v2**(4B 参数,AWQ W4A16 量化,v2 提示格式)。所有脚本默认路径为 `./models/RT-Qwen3-4B-AWQ-v2`。
81
+
82
+ ```bash
83
+ # HuggingFace
84
+ huggingface-cli download Cialtion/SimpleTool \
85
+ --include "RT-Qwen3-4B-AWQ-v2/*" --local-dir ./models
86
+
87
+ # 或者 ModelScope(国内推荐)
88
+ modelscope download --model cialtion/SimpleTool \
89
+ --include "RT-Qwen3-4B-AWQ-v2/*" --local_dir ./models
90
+ ```
91
+
92
+ <details>
93
+ <summary><b>全部可用模型</b></summary>
94
+
95
+ | 模型 | 参数量 | 延迟 | HuggingFace | ModelScope |
96
+ |------|--------|------|-------------|------------|
97
+ | RT-Qwen2.5-0.5B-AWQ | 0.5B | ~30ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen2.5-0.5B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen2.5-0.5B-AWQ) |
98
+ | RT-Qwen2.5-1.5B-AWQ | 1.5B | ~40ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen2.5-1.5B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen2.5-1.5B-AWQ) |
99
+ | RT-Qwen2.5-3B-AWQ | 3B | ~50ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen2.5-3B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen2.5-3B-AWQ) |
100
+ | **RT-Qwen3-4B-AWQ-v2** | **4B** | **~60ms** | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen3-4B-AWQ-v2) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen3-4B-AWQ-v2) |
101
+ | RT-Qwen3-4B-AWQ | 4B | ~60ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen3-4B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen3-4B-AWQ) |
102
+ | RT-Qwen2.5-7B-AWQ | 7B | ~70ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen2.5-7B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen2.5-7B-AWQ) |
103
+ | RT-Qwen2.5-14B-AWQ | 14B | ~130ms | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen2.5-14B-AWQ) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen2.5-14B-AWQ) |
104
+ | RT-Qwen3-30B-A3B-AWQ | 30B(A3B) | ~ | [🤗](https://huggingface.co/Cialtion/SimpleTool/tree/main/RT-Qwen3-30B_awq_w4a16) | [链接](https://www.modelscope.cn/models/cialtion/SimpleTool/tree/master/RT-Qwen3-30B_awq_w4a16) |
105
+
106
+ > 延迟数据在 RTX 4090 上使用 vLLM 前缀缓存测得。v2 模型采用改进的提示格式,包含领域专用系统提示;v1 模型使用通用的多头指令头。
107
+
108
+ </details>
109
+
110
+ ### 3. 运行基准测试(无需启动服务)
111
+
112
+ `01_benchmark.py` 通过 vLLM 直接运行多头并行解码,覆盖三大应用场景——游戏 AI、机械臂控制和数字人动画——并输出冷启动 / 热预填充 / 解码瓶颈分析。
113
+
114
+ ```bash
115
+ # v2 模型(默认)
116
+ python 01_benchmark.py --version v2
117
+
118
+ # v1 模型
119
+ python 01_benchmark.py --version v1 --model ./models/RT-Qwen3-4B-AWQ
120
+
121
+ # 自动检测每个场景的最优头数
122
+ python 01_benchmark.py --n-args auto
123
+ ```
124
+
125
+ 输出示例:
126
+ ```
127
+ PARALLEL TEST (v2)
128
+
129
+ ─── Game — Tower Defense ───
130
+ PASS use_skill(Amiya)
131
+ function use_skill 4 OK
132
+ arg1 Amiya 4 FILL
133
+ arg2 <|null|> 3 NULL
134
+ e2e=24.6ms max_tok=4
135
+
136
+ ─── Robotic Arm — Assembly ───
137
+ PASS move_to(300,150,50,slow)
138
+ function move_to 4 OK
139
+ arg1 300 5 FILL
140
+ arg2 150 5 FILL
141
+ arg3 500 5 FILL
142
+ arg4 slow 3 FILL
143
+ e2e=39.9ms max_tok=5
144
+
145
+ ─── Digital Human — Streamer ───
146
+ PASS speak(welcome,cheerful)
147
+ function speak 4 OK
148
+ arg1 Welcome! 4 FILL
149
+ arg2 cheerful 5 FILL
150
+ e2e=29.1ms max_tok=5
151
+
152
+ SUMMARY (v2)
153
+ Accuracy : 3/3
154
+ Cold start avg : 56.1ms
155
+ Hot prefill avg: 29.3ms
156
+ E2E avg (hot) : 31.2ms
157
+ E2E / max_tok : 6.7ms/tok (decode bottleneck)
158
+ ```
159
+
160
+ 脚本还会打印完整的提示结构和重构后的多头输出,便于检查调试。
161
+
162
+ ### 4. 启动服务
163
+
164
+ `02_server.py` 将推理引擎封装为 FastAPI 服务,支持 CORS 跨域。HTML 游戏客户端通过它连接模型。
165
+
166
+ ```bash
167
+ python 02_server.py
168
+ ```
169
+
170
+ 服务启动于 `http://localhost:8899`,提供以下接口:
171
+
172
+ | 接口 | 方法 | 说明 |
173
+ |------|------|------|
174
+ | `/health` | GET | 健康检查,返回模型版本信息 |
175
+ | `/v1/function_call` | POST | 多头并行函数调用 |
176
+
177
+ 编辑 `02_server.py` 顶部的 `MODEL_PATH` 和 `MODEL_VERSION` 即可切换 v1/v2 模型。
178
+
179
+ ### 5. 测试服务
180
+
181
+ 服务运行后,在另一个终端中执行:
182
+
183
+ ```bash
184
+ python 03_test_server.py
185
+ ```
186
+
187
+ 该脚本向服务端 API 发送三大场景(游戏、机械臂、数字人)的测试请求,报告准确率、冷启动/热启动延迟及各头输出。
188
+
189
+ ```bash
190
+ # 自定义服务地址
191
+ python 03_test_server.py --url http://192.168.1.100:8899
192
+
193
+ # 增加热启动轮数
194
+ python 03_test_server.py --rounds 10
195
+ ```
196
+
197
+ ### 6. 体验 Demo
198
+
199
+ 在浏览器中打开 Demo HTML 文件,它们会连接到正在运行的 SimpleTool 服务。
200
+
201
+ | Demo | 说明 | 文件 |
202
+ |------|------|------|
203
+ | **Pong** | AI 对战人类的弹球游戏 | `demos/pong_game.html` |
204
+ | **Neon Arena** | 多 AI 对战射击游戏 | `demos/neon_arena.html` |
205
+
206
+ 部分游戏需要额外资源文件:
207
+ ```bash
208
+ cd demos/neon_arena
209
+ python3 -m http.server 8080 --bind 127.0.0.1
210
+ ```
211
+ 然后打开 http://127.0.0.1:8080/neon_arena.html,输入 SimpleTool 服务地址(默认:`http://localhost:8899`)。
212
+
213
+ <p align="center">
214
+ <video src="https://github.com/user-attachments/assets/436e3b97-e8ab-4d36-9fa0-8f1962da4a38" autoplay loop muted width="400"></video>
215
+ <video src="https://github.com/user-attachments/assets/f9b127da-b65e-4a06-b48f-836e759a6029" autoplay loop muted width="400"></video>
216
+ </p>
217
+
218
+ ---
219
+
220
+ ## 项目结构
221
+
222
+ ```
223
+ SimpleTool/
224
+ ├── 01_benchmark.py # 第 1 步:直接并行解码基准测试
225
+ ├── 02_server.py # 第 2 步:FastAPI vLLM 推理服务
226
+ ├── 03_test_server.py # 第 3 步:服务端 API 测试客户端
227
+ ├── prompts/ # 外部提示词与场景文件
228
+ │ ├── v1_system.txt # v1 多头系统提示
229
+ │ ├── scenarios.json # 3 大场景测试用例
230
+ │ ├── tools_game.jsonl # 塔防游戏工具定义
231
+ │ ├── tools_arm.jsonl # 机械臂工具定义
232
+ │ └── tools_avatar.jsonl # 数字人工具定义
233
+ ├── models/ # 模型下载目录
234
+ │ └── RT-Qwen3-4B-AWQ-v2/ # 默认模型
235
+ ├── demos/ # HTML 游戏客���端
236
+ │ ├── pong_game.html
237
+ │ └── neon_arena/
238
+ ├── assets/ # README 配图
239
+ ├── requirements.txt
240
+ ├── simpletool-game.skill.md # 用 AI 构建新游戏的指南
241
+ ├── README.md
242
+ └── README_zh.md
243
+ ```
244
+
245
+ ## 构建你自己的游戏
246
+
247
+ 将 **`simpletool-game.skill.md`** 和本项目的 **`README.md`** 一起喂给你的 AI 编程智能体(Claude Code、Codex、Antigravity 等)即可开始 vibe coding。Skill 文件涵盖服务端 API 规格、工具定义格式、Query 设计最佳实践、前端模板及动态头数优化技巧;README 则帮助 AI 理解整体项目结构。两者配合,即可上手开发基于 SimpleTool 的游戏。
248
+
249
+ ---
250
+
251
+ ## 路线图
252
+
253
+ - [ ] **世界模拟** — 大规模(1,000+ NPC)实时 AI 异步世界模拟,单智能体行动端到端延迟 < 200ms
254
+ - [ ] **Windows 原生支持** — Windows 游戏引擎插件与原生运行(无需docker或wsl)
255
+ - [ ] **Apple 生态** — Mac 和 iPhone 端侧部署(CoreML / Metal)
256
+ - [ ] **v3 架构** — 快思考(实时 SimpleTool)+ 慢思考(异步元认知)融合
257
+ - [ ] **具身智能** — 虚拟 3D 数字人,大型游戏引擎集成演示
258
+ - [ ] **开源训练** — 完整训练代码与数据集开放
259
+
260
+ ---
261
+
262
+ ## 演示视频
263
+
264
+ <p align="center">
265
+ <a href="#"><img src="https://img.shields.io/badge/Bilibili-Demo-00A1D6?logo=bilibili&logoColor=white"></a>
266
+ <a href="#"><img src="https://img.shields.io/badge/YouTube-Demo-FF0000?logo=youtube&logoColor=white"></a>
267
+ </p>
268
+
269
+ > 演示视频即将上线——展示实时游戏 AI、机械臂控制和数字人动画效果。
270
+
271
+ ---
272
+
273
+ ## 引用
274
+
275
+ ```bibtex
276
+ @article{shi2026simpletool,
277
+ title={SimpleTool: Parallel Decoding for Real-Time LLM Function Calling},
278
+ author={Shi, Xiaoxin and Wan, Jiaxin and Dong, Linkang and Jiang, Wei and Liu, Yue and Huang, Zengfeng},
279
+ journal={arXiv preprint arXiv:2603.00030},
280
+ year={2026}
281
+ }
282
+ ```
283
+
284
+ ## 联系方式
285
+
286
+ - **邮箱**:cialtion737410@sjtu.edu.cn / cialtion@outlook.com
287
+ - **QQ 群**:861244702
288
+ - **Bilibili**:[Cialtion](https://space.bilibili.com/Cialtion)
289
+
290
+ ## 许可证
291
+
292
+ Apache 2.0