danielhanchen commited on
Commit
37d43a2
·
verified ·
1 Parent(s): b8f6f7a

Delete README_CN.md

Browse files
Files changed (1) hide show
  1. README_CN.md +0 -415
README_CN.md DELETED
@@ -1,415 +0,0 @@
1
- <p align="center">
2
- <img src="https://dscache.tencent-cloud.cn/upload/uploader/hunyuan-64b418fd052c033b228e04bc77bbc4b54fd7f5bc.png" width="400"/> <br>
3
- </p><p></p>
4
-
5
-
6
- <p align="center">
7
- 🤗&nbsp;<a href="https://huggingface.co/tencent/Hunyuan-A13B-Instruct"><b>Hugging Face</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
8
- 🖥️&nbsp;<a href="https://hunyuan.tencent.com" style="color: red;"><b>Official Website</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
9
- 🕖&nbsp;<a href="https://cloud.tencent.com/product/hunyuan"><b>HunyuanAPI</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
10
- 🕹️&nbsp;<a href="https://hunyuan.tencent.com/?model=hunyuan-a13b"><b>Demo</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
11
- 🤖&nbsp;<a href="https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-A13B-Instruct"><b>ModelScope</b></a>
12
- </p>
13
-
14
-
15
- <p align="center">
16
- <a href="https://github.com/Tencent-Hunyuan/Hunyuan-A13B/blob/main/report/Hunyuan_A13B_Technical_Report.pdf"><b>Technical Report</b> </a> |
17
- <a href="https://github.com/Tencent-Hunyuan/Hunyuan-A13B"><b>GITHUB</b></a> |
18
- <a href="https://cnb.cool/tencent/hunyuan/Hunyuan-A13B"><b>cnb.cool</b></a> |
19
- <a href="https://github.com/Tencent-Hunyuan/Hunyuan-A13B/blob/main/LICENSE"><b>LICENSE</b></a> |
20
- <a href="https://raw.githubusercontent.com/Tencent-Hunyuan/Hunyuan-A13B/main/assets/1751881231452.jpg"><b>WeChat</b></a> |
21
- <a href="https://discord.gg/bsPcMEtV7v"><b>Discord</b></a>
22
- </p>
23
-
24
-
25
-
26
-
27
- ## 模型介绍
28
-
29
- 随着人工智能技术的快速发展,大型语言模型(LLMs)在自然语言处理、计算机视觉和科学任务等领域取得了显著进展。然而,随着模型规模的扩大,如何在保持高性能的同时优化资源消耗成为一个关键挑战。为了应对这一挑战,我们研究了混合专家(MoE)模型,当前亮相的 Hunyuan-A13B 模型,拥有800亿总参数和130亿激活参数。不仅在效果上达到了高标准,而且在尺寸上也做到了极致的优化,成功平衡了模型性能与资源占用。
30
-
31
-
32
- ### 核心特性与优势
33
- - ​**小参数量,高性能**​:仅激活130亿参数(总参数量800亿),即可在多样化基准任务中媲美更大规模模型的竞争力表现
34
- - ​**混合推理支持**​:同时支持快思考和慢思考两种模式,支持用户灵活选择
35
- - ​**超长上下文理解**​:原生支持256K上下文窗口,在长文本任务中保持稳定性能
36
- - ​**增强Agent能力**​:优化Agent能力,在BFCL-v3、τ-Bench等智能体基准测试中领先
37
- - ​**高效推理**​:采用分组查询注意力(GQA)策略,支持多量化格式,实现高效推理
38
-
39
-
40
- ### 为何选择Hunyuan-A13B?
41
- 作为兼具强大性能与计算效率的大模型,Hunyuan-A13B是研究者与开发者在资源受限条件下追求高性能的理想选择。无论学术研究、高性价比AI解决方案开发,还是创新应用探索,本模型都能提供强大的基础支持。
42
-
43
-
44
- &nbsp;
45
-
46
- ## 新闻
47
- <br>
48
-
49
- * 2025.6.26 我们在Hugging Face开源了 **Hunyuan-A13B-Instruct**,**Hunyuan-A13B-Pretrain**, **Hunyuan-A13B-Instruct-FP8**, **Hunyuan-A13B-Instruct-GPTQ-Int4**。并发布了技术报告和训练推理操作手册,详细介绍了模型能力和训练与推理的操作。
50
-
51
- ## 模型结构
52
-
53
- Hunyuan-A13B采用了细粒度混合专家(Fine-grained Mixture of Experts,Fine-grained MoE)架构,包含800亿参数和130亿激活参数,累计训练了超过 20T tokens。该模型支持 256K 的上下文长度,以下为模型结构细节:
54
- * 总参数: 80B
55
- * 激活参数: 13B
56
- * 层数: 32
57
- * Attention Heads: 32
58
- * 共享专家数: 1
59
- * 非共享专家数: 64
60
- * 路由策略: Top-8
61
- * 激活函数: SwiGLU
62
- * 隐层维度: 4096
63
- * 专家隐层维度: 3072
64
-
65
- ## Benchmark评估榜单
66
-
67
- **Hunyuan-A13B-Pretrain** 在 12/14 个任务上超越了Hunyuan上一代52B激活参数的MoE模型Hunyuan-Large,证实了它在预训练任务上出色的能力。与业界更大参数量的Dense和MoE模型相比, Hunyuan-A13B在多个代码和数学任务上都取得了最高分数。在MMLU, MMLU-PRO等诸多众聚合任务上, Hunyuan-A13B达到了与Qwen3-A22B模型同等的水平,表现出优秀的综合能力。
68
-
69
- | Model | Hunyuan-Large | Qwen2.5-72B | Qwen3-A22B | Hunyuan-A13B |
70
- |------------------|---------------|--------------|-------------|---------------|
71
- | MMLU | 88.40 | 86.10 | 87.81 | 88.17 |
72
- | MMLU-Pro | 60.20 | 58.10 | 68.18 | 67.23 |
73
- | MMLU-Redux | 87.47 | 83.90 | 87.40 | 87.67 |
74
- | BBH | 86.30 | 85.80 | 88.87 | 87.56 |
75
- | SuperGPQA | 38.90 | 36.20 | 44.06 | 41.32 |
76
- | EvalPlus | 75.69 | 65.93 | 77.60 | 78.64 |
77
- | MultiPL-E | 59.13 | 60.50 | 65.94 | 69.33 |
78
- | MBPP | 72.60 | 76.00 | 81.40 | 83.86 |
79
- | CRUX-I | 57.00 | 57.63 | - | 70.13 |
80
- | CRUX-O | 60.63 | 66.20 | 79.00 | 77.00 |
81
- | MATH | 69.80 | 62.12 | 71.84 | 72.35 |
82
- | CMATH | 91.30 | 84.80 | - | 91.17 |
83
- | GSM8k | 92.80 | 91.50 | 94.39 | 91.83 |
84
- | GPQA | 25.18 | 45.90 | 47.47 | 49.12 |
85
-
86
- **Hunyuan-A13B-Instruct** 在多项基准测试中取得了极具有竞争力的表现,尤其是在数学、科学、agent等领域。我们与一些强力模型进行了对比,结果如下所示。
87
-
88
- | Topic | Bench | OpenAI-o1-1217 | DeepSeek R1 | Qwen3-A22B | Hunyuan-A13B-Instruct |
89
- |:-------------------:|:-----------------------------:|:-------------:|:------------:|:-----------:|:---------------------:|
90
- | **Mathematics** | AIME 2024<br>AIME 2025<br>MATH | 74.3<br>79.2<br>96.4 | 79.8<br>70<br>94.9 | 85.7<br>81.5<br>94.0 | 87.3<br>76.8<br>94.3 |
91
- | **Science** | GPQA-Diamond<br>OlympiadBench | 78<br>83.1 | 71.5<br>82.4 | 71.1<br>85.7 | 71.2<br>82.7 |
92
- | **Coding** | Livecodebench<br>Fullstackbench<br>ArtifactsBench | 63.9<br>64.6<br>38.6 | 65.9<br>71.6<br>44.6 | 70.7<br>65.6<br>44.6 | 63.9<br>67.8<br>43 |
93
- | **Reasoning** | BBH<br>DROP<br>ZebraLogic | 80.4<br>90.2<br>81 | 83.7<br>92.2<br>78.7 | 88.9<br>90.3<br>80.3 | 89.1<br>91.1<br>84.7 |
94
- | **Instruction<br>Following** | IF-Eval<br>SysBench | 91.8<br>82.5 | 88.3<br>77.7 | 83.4<br>74.2 | 84.7<br>76.1 |
95
- | **Text<br>Creation**| LengthCtrl<br>InsCtrl | 60.1<br>74.8 | 55.9<br>69 | 53.3<br>73.7 | 55.4<br>71.9 |
96
- | **NLU** | ComplexNLU<br>Word-Task | 64.7<br>67.1 | 64.5<br>76.3 | 59.8<br>56.4 | 61.2<br>62.9 |
97
- | **Agent** | BDCL v3<br> τ-Bench<br>ComplexFuncBench<br> $C^3$-Bench | 67.8<br>60.4<br>47.6<br>58.8 | 56.9<br>43.8<br>41.1<br>55.3 | 70.8<br>44.6<br>40.6<br>51.7 | 78.3<br>54.7<br>61.2<br>63.5 |
98
-
99
- ## transformers推理
100
-
101
- 我们的模型默认使用“慢思考”(即推理模式),有两种方式可以关闭 CoT(Chain-of-Thought,思维链)推理:
102
- 1. 在调用 `apply_chat_template` 时传入参数 `"enable_thinking=False"`。
103
- 2. 在提示词(prompt)前加上 `/no_think` 可以强制模型不使用 CoT 推理。类似地,在提示词前加上 `/think` 则会强制模型启用 CoT 推理。
104
-
105
- 以下代码片段展示了如何使用 `transformers` 库加载并应用该模型。
106
- 它还演示了如何开启和关闭推理模式,
107
- 以及如何解析推理过程和最终输出。
108
-
109
- ```python
110
- from transformers import AutoModelForCausalLM, AutoTokenizer
111
- import os
112
- import re
113
-
114
- model_name_or_path = os.environ['MODEL_PATH']
115
- # model_name_or_path = "tencent/Hunyuan-A13B-Instruct"
116
-
117
- tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True)
118
- model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map="auto",trust_remote_code=True) # You may want to use bfloat16 and/or move to GPU here
119
- messages = [
120
- {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
121
- ]
122
-
123
- text = tokenizer.apply_chat_template(
124
- messages,
125
- tokenize=False,
126
- enable_thinking=True
127
- )
128
-
129
- model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
130
- model_inputs.pop("token_type_ids", None)
131
- outputs = model.generate(**model_inputs, max_new_tokens=4096)
132
-
133
-
134
- output_text = tokenizer.decode(outputs[0])
135
-
136
- think_pattern = r'<think>(.*?)</think>'
137
- think_matches = re.findall(think_pattern, output_text, re.DOTALL)
138
-
139
- answer_pattern = r'<answer>(.*?)</answer>'
140
- answer_matches = re.findall(answer_pattern, output_text, re.DOTALL)
141
-
142
- think_content = [match.strip() for match in think_matches][0]
143
- answer_content = [match.strip() for match in answer_matches][0]
144
- print(f"thinking_content:{think_content}\n\n")
145
- print(f"answer_content:{answer_content}\n\n")
146
- ```
147
-
148
-
149
-
150
- ### 快速思考与慢速思考切换
151
-
152
- 本模型支持两种运行模式:
153
-
154
- - **慢速思考模式(默认)**:在生成最终答案之前进行详细的内部推理步骤。
155
- - **快速思考模式**:跳过内部推理过程,直接输出最终答案,从而实现更快的推理速度。
156
-
157
- **切换到快速思考模式的方法:**
158
-
159
- 要禁用推理过程,请在调用 `apply_chat_template` 时设置 `enable_thinking=False`:
160
-
161
- ```python
162
- text = tokenizer.apply_chat_template(
163
- messages,
164
- tokenize=False,
165
- enable_thinking=False # 使用快速思考模式
166
- )
167
- ```
168
-
169
- ## 推理和部署
170
-
171
- HunyuanLLM可以采用vLLM,sglang或TensorRT-LLM部署。为了简化部署过程HunyuanLLM提供了预构建docker镜像。
172
-
173
-
174
- ## 使用TensorRT-LLM推理
175
-
176
- ### BF16部署
177
-
178
- #### Step1:执行推理
179
-
180
- #### 方式1:命令行推理
181
-
182
- 下面我们展示一个代码片段,采用`TensorRT-LLM`快速请求chat model:
183
- 修改 examples/pytorch/quickstart_advanced.py 中如下代码:
184
-
185
-
186
- ```python
187
- from tensorrt_llm import SamplingParams
188
- from tensorrt_llm._torch import LLM
189
- from tensorrt_llm._torch.pyexecutor.config import PyTorchConfig
190
- from tensorrt_llm.llmapi import (EagleDecodingConfig, KvCacheConfig,
191
- MTPDecodingConfig)
192
-
193
- prompt = "Write a short summary of the benefits of regular exercise"
194
-
195
- def main():
196
- args = parse_arguments()
197
-
198
- llm, sampling_params = setup_llm(args)
199
- new_prompts = []
200
- if args.apply_chat_template:
201
- messages = [{"role": "user", "content": f"{prompt}"}]
202
- new_prompts.append(llm.tokenizer.apply_chat_template(
203
- messages, tokenize=False, add_generation_prompt=True)
204
- )
205
-
206
- outputs = llm.generate(new_prompts, sampling_params)
207
-
208
- for i, output in enumerate(outputs):
209
- prompt = output.prompt
210
- generated_text = output.outputs[0].text
211
- print(f"[{i}] Prompt: {prompt!r}, Generated text: {generated_text!r}")
212
- ```
213
-
214
- 运行方式:
215
-
216
- ```shell
217
- python3 quickstart_advanced.py --model_dir "HunyuanLLM模型路径" --tp_size 4 --apply_chat_template
218
- ```
219
-
220
- #### 方式2:服务化推理
221
-
222
- 下面我们展示使用`TensorRT-LLM`服务化的方式部署模型和请求。
223
-
224
- ```shell
225
- model_path="HunyuanLLM模型路径"
226
- trtllm-serve <model_path> [--backend pytorch --tp_size <tp> --ep_size <ep> --host <host> --port <port>]
227
- ```
228
-
229
- 服务启动成功后, 运行请求脚本:
230
- ```python
231
- ### OpenAI Chat Client
232
-
233
- from openai import OpenAI
234
-
235
- client = OpenAI(
236
- base_url="http://localhost:8000/v1",
237
- api_key="tensorrt_llm",
238
- )
239
-
240
- response = client.chat.completions.create(
241
- model="default",
242
- messages=[{
243
- "role": "user",
244
- "content": "Write a short summary of the benefits of regular exercise"
245
- }],
246
- max_tokens=4096,
247
- )
248
- print(response)
249
- ```
250
-
251
- #### FP8/Int4量化模型部署:
252
- 目前 TensorRT-LLM 的 fp8 和 int4 量化模型正在支持中,敬请期待。
253
-
254
-
255
- ## vLLM 部署
256
-
257
- ### Docker 镜像推理
258
-
259
- 我们提供了一个基于官方 vLLM 0.8.5 版本的 Docker 镜像方便快速部署和测试。**注意:该镜像要求使用 CUDA 12.4 版本。**
260
-
261
- - 首先,下载 Docker 镜像文件:
262
-
263
- **从Docker Hub下载**:
264
- ```
265
- docker pull hunyuaninfer/hunyuan-infer-vllm-cuda12.4:v1
266
- ```
267
-
268
- **中国国内镜像**:
269
-
270
- 考虑到下载速度, 也可以选择从 CNB 下载镜像,感谢[CNB云原生构建](https://cnb.cool/)提供支持:
271
-
272
- 1. 下载镜像
273
- ```
274
- docker pull docker.cnb.cool/tencent/hunyuan/hunyuan-a13b/hunyuan-infer-vllm-cuda12.4:v1
275
- ```
276
-
277
- 2. 然后更名镜像(可选,更好的和下面脚本名字匹配)
278
- ```
279
- docker tag docker.cnb.cool/tencent/hunyuan/hunyuan-a13b/hunyuan-infer-vllm-cuda12.4:v1 hunyuaninfer/hunyuan-infer-vllm-cuda12.4:v1
280
- ```
281
-
282
- - 下载模型文件:
283
- - Huggingface:vLLM 会自动下载。
284
- - ModelScope:`modelscope download --model Tencent-Hunyuan/Hunyuan-A13B-Instruct`
285
-
286
- - 启动 API 服务(从 Huggingface 下载模型):
287
-
288
- ```bash
289
- docker run --rm --ipc=host \
290
- -v ~/.cache:/root/.cache/ \
291
- --security-opt seccomp=unconfined \
292
- --net=host \
293
- --gpus=all \
294
- -it \
295
- --entrypoint python3 hunyuaninfer/hunyuan-infer-vllm-cuda12.4:v1 \
296
- -m vllm.entrypoints.openai.api_server \
297
- --host 0.0.0.0 \
298
- --tensor-parallel-size 4 \
299
- --port 8000 \
300
- --model tencent/Hunyuan-A13B-Instruct \
301
- --trust_remote_code
302
- ```
303
-
304
- - 启动 API 服务(从 ModelScope 下载模型):
305
-
306
- ```bash
307
- docker run --rm --ipc=host \
308
- -v ~/.cache/modelscope:/root/.cache/modelscope \
309
- --security-opt seccomp=unconfined \
310
- --net=host \
311
- --gpus=all \
312
- -it \
313
- --entrypoint python3 hunyuaninfer/hunyuan-infer-vllm-cuda12.4:v1 \
314
- -m vllm.entrypoints.openai.api_server \
315
- --host 0.0.0.0 \
316
- --tensor-parallel-size 4 \
317
- --port 8000 \
318
- --model /root/.cache/modelscope/hub/models/Tencent-Hunyuan/Hunyuan-A13B-Instruct/ \
319
- --trust_remote_code
320
- ```
321
-
322
-
323
- ### 源码部署
324
-
325
- 对本模型的支持已通过 [PR 20114](https://github.com/vllm-project/vllm/pull/20114) 提交至 vLLM 项目并已经合并, 可以使用 vllm git commit`ecad85`以后的版本进行源代码编译。
326
-
327
-
328
- ### 模型上下文长度支持
329
-
330
- Hunyuan A13B 模型支持最大 **256K token(262,144 Token)** 的上下文长度。但由于大多数 GPU 硬件配置的显存限制,默认 `config.json` 中将上下文长度限制为 **32K token**,以避免出现显存溢出(OOM)问题。
331
-
332
- #### 将上下文长度扩展至 256K
333
-
334
- 如需启用完整的 256K 上下文支持,请手动修改模型 `config.json` 文件中的 `max_position_embeddings` 字段如下:
335
-
336
- ```json
337
- {
338
- ...
339
- "max_position_embeddings": 262144,
340
- ...
341
- }
342
- ```
343
-
344
- 当使用 **vLLM** 进行服务部署时,也可以通过添加以下参数来明确设置最大模型长度:
345
-
346
- ```bash
347
- --max-model-len 262144
348
- ```
349
-
350
- #### 推荐的 256K 上下文长度配置
351
-
352
- 以下是在配备 **NVIDIA H20 显卡(96GB 显存)** 的系统上部署 256K 上下文长度服务的推荐配置:
353
-
354
- | 模型数据类型 | KV-Cache 数据类型 | 设备数量 | 模型长度 |
355
- |----------------|-------------------|------------|--------------|
356
- | `bfloat16` | `bfloat16` | 4 | 262,144 |
357
-
358
- > ⚠️ **注意:** 使用 FP8 对 KV-cache 进行量化可能会影响生成质量。上述配置是用于稳定部署 256K 长度服务的建议设置。
359
-
360
-
361
- ### 使用 vLLM 调用工具
362
-
363
- 为了支持基于 Agent 的工作流和函数调用能力,本模型包含专门的解析机制,用于处理工具调用及内部推理步骤。
364
-
365
- 关于如何在 Agent 场景中实现和使用这些功能的完整示例,请参见我们的 GitHub 示例代码:
366
- 🔗 [Hunyuan A13B Agent 示例](https://github.com/Tencent-Hunyuan/Hunyuan-A13B/blob/main/agent/)
367
-
368
- 在使用 **vLLM** 部署模型时,可以使用以下参数配置工具解析行为:
369
-
370
- | 参数名 | 值 |
371
- |-------------------------|--------------------------------------------------------------------|
372
- | `--tool-parser-plugin` | [本地 Hunyuan A13B 工具解析器文件](https://github.com/Tencent-Hunyuan/Hunyuan-A13B/blob/main/agent/hunyuan_tool_parser.py) |
373
- | `--tool-call-parser` | `hunyuan` |
374
-
375
- 这些设置可使 vLLM 根据预期格式正确解析和路由模型生成的工具调用。
376
-
377
-
378
- ### Reasoning Parser(推理解析器)
379
-
380
- 目前,Hunyuan A13B 模型在 vLLM 中的推理解析器支持仍在开发中。
381
-
382
-
383
- ## SGLang
384
-
385
- ### Docker 镜像
386
-
387
- 我们还提供基于 SGLang 最新版本构建的 Docker 镜像。
388
-
389
- 快速开始方式如下:
390
-
391
- - 拉取 Docker 镜像:
392
-
393
- ```
394
- docker pull docker.cnb.cool/tencent/hunyuan/hunyuan-a13b:hunyuan-moe-A13B-sglang
395
-
396
- docker pull hunyuaninfer/hunyuan-a13b:hunyuan-moe-A13B-sglang
397
- ```
398
-
399
- - 启动 API 服务:
400
-
401
- ```bash
402
- docker run --gpus all \
403
- --shm-size 32g \
404
- -p 30000:30000 \
405
- --ipc=host \
406
- docker.cnb.cool/tencent/hunyuan/hunyuan-a13b:hunyuan-moe-A13B-sglang \
407
- -m sglang.launch_server --model-path hunyuan/huanyuan_A13B --tp 4 --trust-remote-code --host 0.0.0.0 --port 30000
408
- ```
409
-
410
-
411
- ## 交互式Demo Web
412
- hunyuan-A13B 现已开放网页demo。访问 https://hunyuan.tencent.com/?model=hunyuan-a13b 即可简单体验我们的模型。
413
-
414
- ## 联系我们
415
- 如果你想给我们的研发和产品团队留言,欢迎联系我们腾讯混元LLM团队。你可以通过邮件(hunyuan_opensource@tencent.com)联系我们。