manaestras commited on
Commit
418f4db
·
verified ·
1 Parent(s): 9e1144c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +503 -5
README.md CHANGED
@@ -1,5 +1,503 @@
1
- ---
2
- license: other
3
- license_name: tencent-hunyuan
4
- license_link: LICENSE
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <p align="left">
3
+ <a href="README_CN.md">中文</a>&nbsp | English</a>
4
+ </p>
5
+ <br><br>
6
+
7
+ <p align="center">
8
+ <img src="https://dscache.tencent-cloud.cn/upload/uploader/hunyuan-64b418fd052c033b228e04bc77bbc4b54fd7f5bc.png" width="400"/> <br>
9
+ </p><p></p>
10
+
11
+
12
+ <p align="center">
13
+ 🤗&nbsp;<a href="https://huggingface.co/tencent/"><b>Hugging Face</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
14
+ <img src="https://avatars.githubusercontent.com/u/109945100?s=200&v=4" width="16"/>&nbsp;<a href="https://modelscope.cn/models/Tencent-Hunyuan/Hunyuan-A13B-Instruct"><b>ModelScope</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
15
+ <img src="https://cdn-avatars.huggingface.co/v1/production/uploads/6594d0c6c5f1cd69a48b261d/04ZNQlAfs08Bfg4B1o3XO.png" width="14"/>&nbsp;<a href="https://github.com/Tencent/AngelSlim/tree/main"><b>AngelSlim</b></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ 🖥️&nbsp;<a href="https://hunyuan.tencent.com" style="color: red;"><b>Official Website</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
20
+ 🕖&nbsp;<a href="https://cloud.tencent.com/product/hunyuan"><b>HunyuanAPI</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
21
+ 🕹️&nbsp;<a href="https://hunyuan.tencent.com/"><b>Demo</b></a>&nbsp;&nbsp;&nbsp;&nbsp;
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://github.com/Tencent-Hunyuan/Hunyuan-7B"><b>GITHUB</b></a> |
26
+ <a href="https://cnb.cool/tencent/hunyuan/Hunyuan-7B"><b>cnb.cool</b></a> |
27
+ <a href="https://github.com/Tencent-Hunyuan/Hunyuan-7B/blob/main/LICENSE"><b>LICENSE</b></a>
28
+ </p>
29
+
30
+
31
+ ## Model Introduction
32
+
33
+ Hunyuan is Tencent's open-source efficient large language model series, designed for versatile deployment across diverse computational environments. From edge devices to high-concurrency production systems, these models deliver optimal performance with advanced quantization support and ultra-long context capabilities.
34
+
35
+ We have released a series of Hunyuan dense models, comprising both pre-trained and instruction-tuned variants, with parameter scales of 0.5B, 1.8B, 4B, and 7B. These models adopt training strategies similar to the Hunyuan-A13B, thereby inheriting its robust performance characteristics. This comprehensive model family enables flexible deployment optimization - from resource-constrained edge computing with smaller variants to high-throughput production environments with larger models, all while maintaining strong capabilities across diverse scenarios.
36
+
37
+ ### Key Features and Advantages
38
+
39
+ - **Hybrid Reasoning Support**: Supports both fast and slow thinking modes, allowing users to flexibly choose according to their needs.
40
+ - **Ultra-Long Context Understanding**: Natively supports a 256K context window, maintaining stable performance on long-text tasks.
41
+ - **Enhanced Agent Capabilities**: Optimized for agent tasks, achieving leading results on benchmarks such as BFCL-v3, τ-Bench and C3-Bench.
42
+ - **Efficient Inference**: Utilizes Grouped Query Attention (GQA) and supports multiple quantization formats, enabling highly efficient inference.
43
+
44
+ ## Related News
45
+ * 2025.7.30 We have open-sourced **Hunyuan-0.5B-Pretrain** , **Hunyuan-1.8B-Pretrain** , **Hunyuan-4B-Pretrain** , **Hunyuan-7B-Pretrain** , **Hunyuan-0.5B-Instruct** , **Hunyuan-1.8B-Instruct** , **Hunyuan-4B-Instruct** , **Hunyuan-7B-Instruct** on Hugging Face.
46
+ <br>
47
+
48
+
49
+ ## Benchmark
50
+
51
+ Note: The following benchmarks are evaluated by TRT-LLM-backend on several **base models**.
52
+
53
+ | Model | Hunyuan-0.5B-Pretrain | Hunyuan-1.8B-Pretrain | Hunyuan-4B-Pretrain | Hunyuan-7B-Pretrain|
54
+ |:------------------:|:---------------:|:--------------:|:-------------:|:---------------:|
55
+ | MMLU | 54.02 | 64.62 | 74.01 | 79.82 |
56
+ | MMLU-Redux | 54.72 | 64.42 | 73.53 | 79 |
57
+ | MMLU-Pro | 31.15 | 38.65 | 51.91 | 57.79 |
58
+ | SuperGPQA | 17.23 | 24.98 | 27.28 | 30.47 |
59
+ | BBH | 45.92 | 74.32 | 75.17 | 82.95 |
60
+ | GPQA | 27.76 | 35.81 | 43.52 | 44.07 |
61
+ | GSM8K | 55.64 | 77.26 | 87.49 | 88.25 |
62
+ | MATH | 42.95 | 62.85 | 72.25 | 74.85 |
63
+ | EvalPlus | 39.71 | 60.67 | 67.76 | 66.96 |
64
+ | MultiPL-E | 21.83 | 45.92 | 59.87 | 60.41 |
65
+ | MBPP | 43.38 | 66.14 | 76.46 | 76.19 |
66
+ | CRUX-O | 30.75 | 36.88 | 56.5 | 60.75 |
67
+ | Chinese SimpleQA | 12.51 | 22.31 | 30.53 | 38.86 |
68
+ | simpleQA (5shot) | 2.38 | 3.61 | 4.21 | 5.69 |
69
+
70
+
71
+ | Topic | Bench | Hunyuan-0.5B-Instruct | Hunyuan-1.8B-Instruct | Hunyuan-4B-Instruct | Hunyuan-7B-Instruct|
72
+ |:-------------------:|:----------------------------------------------------:|:-------------:|:------------:|:-----------:|:---------------------:|
73
+ | **Mathematics** | AIME 2024<br>AIME 2025<br>MATH | 17.2<br>20<br>48.5 | 56.7<br>53.9<br>86 | 78.3<br>66.5<br>92.6 | 81.1<br>75.3<br>93.7 |
74
+ | **Science** | GPQA-Diamond<br>OlympiadBench | 23.3<br>29.6 | 47.2<br>63.4 | 61.1<br>73.1 | 60.1<br>76.5 |
75
+ | **Coding** | Livecodebench<br>Fullstackbench | 11.1<br>20.9 | 31.5<br>42 | 49.4<br>54.6 | 57<br>56.3 |
76
+ | **Reasoning** | BBH<br>DROP<br>ZebraLogic | 40.3<br>52.8<br>34.5 | 64.6<br>76.7<br>74.6 | 83<br>78.2<br>83.5 | 87.8<br>85.9<br>85.1 |
77
+ | **Instruction<br>Following** | IF-Eval<br>SysBench | 49.7<br>28.1 | 67.6<br>55.5 | 76.6<br>68 | 79.3<br>72.7 |
78
+ | **Agent** | BFCL v3<br> τ-Bench<br>ComplexFuncBench<br> C3-Bench | 49.8<br>14.4<br>13.9<br>45.3 | 58.3<br>18.2<br>22.3<br>54.6 | 67.9<br>30.1<br>26.3<br>64.3 | 70.8<br>35.3<br>29.2<br>68.5 |
79
+ | **Long<br>Context** | PenguinScrolls<br>longbench-v2<br>FRAMES | 53.9<br>34.7<br>41.9 | 73.1<br>33.2<br>55.6 | 83.1<br>44.1<br>79.2 | 82<br>43<br>78.6 |
80
+
81
+
82
+ &nbsp;
83
+
84
+ ### Use with transformers
85
+ First, please install transformers. We will merge it into the main branch later.
86
+ ```SHELL
87
+ pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca
88
+ ```
89
+ Our model defaults to using slow-thinking reasoning, and there are two ways to disable CoT reasoning.
90
+ 1. Pass **"enable_thinking=False"** when calling apply_chat_template.
91
+ 2. Adding **"/no_think"** before the prompt will force the model not to use perform CoT reasoning. Similarly, adding **"/think"** before the prompt will force the model to perform CoT reasoning.
92
+
93
+ The following code snippet shows how to use the transformers library to load and apply the model. It also demonstrates how to enable and disable the reasoning mode , and how to parse the reasoning process along with the final output.
94
+
95
+ we use tencent/Hunyuan-7B-Instruct for example
96
+
97
+ ```python
98
+ from transformers import AutoModelForCausalLM, AutoTokenizer
99
+ import os
100
+ import re
101
+
102
+ model_name_or_path = "tencent/Hunyuan-7B-Instruct"
103
+
104
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
105
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map="auto") # You may want to use bfloat16 and/or move to GPU here
106
+ messages = [
107
+ {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
108
+ ]
109
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True,return_tensors="pt",
110
+ enable_thinking=True # Toggle thinking mode (default: True)
111
+ )
112
+
113
+ outputs = model.generate(tokenized_chat.to(model.device), max_new_tokens=2048)
114
+
115
+ output_text = tokenizer.decode(outputs[0])
116
+ print("output_text=",output_text)
117
+ think_pattern = r'<think>(.*?)</think>'
118
+ think_matches = re.findall(think_pattern, output_text, re.DOTALL)
119
+
120
+ answer_pattern = r'<answer>(.*?)</answer>'
121
+ answer_matches = re.findall(answer_pattern, output_text, re.DOTALL)
122
+
123
+ think_content = [match.strip() for match in think_matches][0]
124
+ answer_content = [match.strip() for match in answer_matches][0]
125
+ print(f"thinking_content:{think_content}\n\n")
126
+ print(f"answer_content:{answer_content}\n\n")
127
+
128
+
129
+ ```
130
+
131
+ We recommend using the following set of parameters for inference. Note that our model does not have the default system_prompt.
132
+
133
+ ```json
134
+
135
+ {
136
+ "do_sample": true,
137
+ "top_k": 20,
138
+ "top_p": 0.8,
139
+ "repetition_penalty": 1.05,
140
+ "temperature": 0.7
141
+ }
142
+ ```
143
+
144
+ &nbsp;
145
+
146
+ ### Training Data Format
147
+
148
+ If you need to fine-tune our Instruct model, we recommend processing the data into the following format, corresponding to both slow-thinking and fast-thinking scenarios.
149
+
150
+ ```python
151
+ # think_pattern
152
+ think = ""
153
+ answer = ""
154
+ think_pattern = f"<think>\n{think}\n</think>\n<answer>\n{answer}\n</answer>"
155
+
156
+ # fast think pattern
157
+ messages = [
158
+ {"role": "system", "content": "You are a helpful assistant."},
159
+ {"role": "user", "content": "/no_think海水为什么是咸的" },
160
+ {"role": "assistant", "content": "<think>\n\n</think>\n<answer>\n海水是咸的主要是因为其中含有许多溶解在水中的盐类和矿物质。这些盐类和矿物质来自于地球表面的岩石和土壤中的化学物质,随着时间的推移,它们被带到了海洋中。当海水蒸发时,水分蒸发掉了,但盐类和矿物质仍然留在水中,导致海水变得更加咸味。因此,海水的咸度是由其中的盐类和矿物质的含量决定的。\n</answer>"}
161
+ ]
162
+
163
+ # slow think pattern
164
+ messages = [
165
+ {"role": "system", "content": "You are a helpful assistant."},
166
+ {"role": "user", "content": "1+1=" },
167
+ {"role": "assistant", "content": "<think>\n嗯,用户问���是1加1等于多少。首先,我需要确认这是一个基本的算术问题。1加1在十进制的数学体系中,通常的结果是2。不过,可能需要考虑是否有其他情况,比如二进制或者其他数制,但用户没有特别说明,所以默认应该是十进制。另外,有时候可能会有脑筋急转弯的情况,比如在某些语境下1+1可能等于1(比如1滴水加1滴水还是1滴水),但通常数学问题中都是2。所以最准确的回答应该是2。</think>\n<answer>\n在十进制的基本算术运算中,1加1的结果是2。这是数学中最基础的加法运算之一,遵循自然数的加法规则。因此,1 + 1 = 2。\n</answer>"}
168
+ ]
169
+
170
+ from transformers import AutoTokenizer
171
+ tokenizer = AutoTokenizer.from_pretrained("your_tokenizer_path", trust_remote_code=True)
172
+ train_ids = tokenizer.apply_chat_template(messages)
173
+ ```
174
+
175
+ &nbsp;
176
+
177
+ ### Train with LLaMA-Factory
178
+
179
+ In the following chapter, we will introduce how to use `LLaMA-Factory` to fine-tune the `Hunyuan` model.
180
+
181
+ #### Prerequisites
182
+
183
+ Verify installation of the following dependencies:
184
+ - **LLaMA-Factory**: Follow [official installation guide](https://github.com/hiyouga/LLaMA-Factory)
185
+ - **DeepSpeed** (optional): Follow [official installation guide](https://github.com/deepspeedai/DeepSpeed#installation)
186
+ - **Transformer Library**: Use the companion branch (Hunyuan-submitted code is pending review)
187
+ ```
188
+ pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca
189
+ ```
190
+
191
+ #### Data preparation
192
+
193
+ We need to prepare a custom dataset:
194
+ 1. Organize your data in `json` format and place it in the `data` directory in `LLaMA-Factory`. The current implementation uses the `sharegpt` dataset format, which requires the following structure:
195
+ ```
196
+ [
197
+ {
198
+ "messages": [
199
+ {
200
+ "role": "system",
201
+ "content": "System prompt (optional)"
202
+ },
203
+ {
204
+ "role": "user",
205
+ "content": "Human instruction"
206
+ },
207
+ {
208
+ "role": "assistant",
209
+ "content": "Model response"
210
+ }
211
+ ]
212
+ }
213
+ ]
214
+ ```
215
+ Refer to the [Data Format](#training-data-format) section mentioned earlier for details.
216
+
217
+ 2. Define your dataset in the data/dataset_info.json file using the following format:
218
+ ```
219
+ "dataset_name": {
220
+ "file_name": "dataset.json",
221
+ "formatting": "sharegpt",
222
+ "columns": {
223
+ "messages": "messages"
224
+ },
225
+ "tags": {
226
+ "role_tag": "role",
227
+ "content_tag": "content",
228
+ "user_tag": "user",
229
+ "assistant_tag": "assistant",
230
+ "system_tag": "system"
231
+ }
232
+ }
233
+ ```
234
+
235
+ #### Training execution
236
+
237
+ 1. Copy all files from the `train/llama_factory_support/example_configs` directory to the `example/hunyuan` directory in `LLaMA-Factory`.
238
+ 2. Modify the model path and dataset name in the configuration file `hunyuan_full.yaml`. Adjust other configurations as needed:
239
+ ```
240
+ ### model
241
+ model_name_or_path: [!!!add the model path here!!!]
242
+
243
+ ### dataset
244
+ dataset: [!!!add the dataset name here!!!]
245
+ ```
246
+ 3. Execute training commands:
247
+ *​​Single-node training​​
248
+ Note: Set the environment variable DISABLE_VERSION_CHECK to 1 to avoid version conflicts.
249
+ ```
250
+ export DISABLE_VERSION_CHECK=1
251
+ llamafactory-cli train examples/hunyuan/hunyuan_full.yaml
252
+ ```
253
+ *Multi-node training​​
254
+ Execute the following command on each node. Configure NNODES, NODE_RANK, MASTER_ADDR, and MASTER_PORT according to your environment:
255
+ ```
256
+ export DISABLE_VERSION_CHECK=1
257
+ FORCE_TORCHRUN=1 NNODES=${NNODES} NODE_RANK=${NODE_RANK} MASTER_ADDR=${MASTER_ADDR} MASTER_PORT=${MASTER_PORT} \
258
+ llamafactory-cli train examples/hunyuan/hunyuan_full.yaml
259
+ ```
260
+
261
+ &nbsp;
262
+
263
+
264
+ ## Quantization Compression
265
+ We used our own [AngleSlim](https://github.com/tencent/AngelSlim) compression tool to produce FP8 and INT4 quantization models. `AngleSlim` is a toolset dedicated to creating a more user-friendly, comprehensive and efficient model compression solution.
266
+
267
+ ### FP8 Quantization
268
+ We use FP8-static quantization, FP8 quantization adopts 8-bit floating point format, through a small amount of calibration data (without training) to pre-determine the quantization scale, the model weights and activation values will be converted to FP8 format, to improve the inference efficiency and reduce the deployment threshold. We you can use AngleSlim quantization, you can also directly download our quantization completed open source model to use [LINK](https://huggingface.co/).
269
+
270
+ ### Int4 Quantization
271
+ We use the GPTQ and AWQ algorithm to achieve W4A16 quantization.
272
+
273
+ GPTQ processes the model weights layer by layer, uses a small amount of calibration data to minimize the reconfiguration error of the quantized weights, and adjusts the weights layer by layer by the optimization process of approximating the Hessian inverse matrix. The process eliminates the need to retrain the model and requires only a small amount of calibration data to quantize the weights, improving inference efficiency and lowering the deployment threshold.
274
+ AWQ using a small amount of calibration data (without the need for training), the amplitude of the activation values is statistically calculated. For each weight channel, a scaling coefficient s is computed to expand the numerical range of important weights, allowing more information to be retained during quantization.
275
+
276
+ You can use [AngleSlim](https://github.com/tencent/AngelSlim) quantization, you can also directly download our quantization completed open source model to use [LINK](https://huggingface.co/).
277
+
278
+
279
+
280
+ #### Quantization Benchmark
281
+ This subsection describes the Benchmark metrics for the Hunyuan quantitative model.
282
+
283
+ | Bench | Quantization | Hunyuan-0.5B-Instruct | Hunyuan-1.8B-Instruct | Hunyuan-4B-Instruct | Hunyuan-7B-Instruct |
284
+ |:-------------:|:---------------------------------:|:----------------------------:|:------------------------------:|:----------------------------:|:----------------------------:|
285
+ | DROP | B16<br>FP8<br>Int4GPTQ<br>Int4AWQ | 52.8<br>51.6<br>50.9<br>48.9 | 76.7<br>75.1<br>73.0<br>71.7 | 78.2<br>78.3<br>78.1<br>78.2 | 85.9<br>86.0<br>85.7<br>85.9 |
286
+ | GPQA-Diamond | B16<br>FP8<br>Int4GPTQ<br>Int4AWQ | 23.3<br>22.5<br>23.3<br>23.3 | 47.2<br>47.7<br>44.43<br>43.62 | 61.1<br>60.2<br>58.1<br>- | 60.1<br>60.1<br>60.0<br>60.1 |
287
+ | OlympiadBench | B16<br>FP8<br>Int4GPTQ<br>Int4AWQ | 29.6<br>29.6<br>26.8<br>26.3 | 63.4<br>62.5<br>60.9<br>61.7 | 73.1<br>73.1<br>71.1<br>71.2 | 76.5<br>76.6<br>76.2<br>76.4 |
288
+ | AIME 2024 | B16<br>FP8<br>Int4GPTQ<br>Int4AWQ | 17.2<br>17.2<br>-<br>- | 56.7<br>55.17<br>-<br>- | 78.3<br>76.6<br>-<br>- | 81.1<br>80.9<br>81.0<br>80.9 |
289
+
290
+
291
+ ## Deployment
292
+
293
+ For deployment, you can use frameworks such as **TensorRT-LLM**, **vLLM**, or **SGLang** to serve the model and create an OpenAI-compatible API endpoint.
294
+
295
+ image: https://hub.docker.com/r/hunyuaninfer/hunyuan-7B/tags
296
+
297
+
298
+ ### TensorRT-LLM
299
+
300
+ #### Docker Image
301
+
302
+ We provide a pre-built Docker image based on the latest version of TensorRT-LLM.
303
+
304
+ We use tencent/Hunyuan-7B-Instruct for example
305
+ - To get started:
306
+
307
+ https://hub.docker.com/r/hunyuaninfer/hunyuan-large/tags
308
+
309
+ ```
310
+ docker pull hunyuaninfer/hunyuan-7B:hunyuan-moe-7B-trtllm
311
+ ```
312
+ ```
313
+ docker run --privileged --user root --name hunyuanLLM_infer --rm -it --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --gpus=all hunyuaninfer/hunyuan-7B:hunyuan-moe-7B-trtllm
314
+ ```
315
+
316
+ - Prepare Configuration file:
317
+
318
+ ```
319
+ cat >/path/to/extra-llm-api-config.yml <<EOF
320
+ use_cuda_graph: true
321
+ cuda_graph_padding_enabled: true
322
+ cuda_graph_batch_sizes:
323
+ - 1
324
+ - 2
325
+ - 4
326
+ - 8
327
+ - 16
328
+ - 32
329
+ print_iter_log: true
330
+ EOF
331
+ ```
332
+
333
+
334
+ - Start the API server:
335
+
336
+
337
+ ```
338
+ trtllm-serve \
339
+ /path/to/HunYuan-moe-7B \
340
+ --host localhost \
341
+ --port 8000 \
342
+ --backend pytorch \
343
+ --max_batch_size 32 \
344
+ --max_num_tokens 16384 \
345
+ --tp_size 2 \
346
+ --kv_cache_free_gpu_memory_fraction 0.6 \
347
+ --trust_remote_code \
348
+ --extra_llm_api_options /path/to/extra-llm-api-config.yml
349
+ ```
350
+
351
+
352
+ ### vllm
353
+
354
+ #### Start
355
+ Please use vLLM version v0.10.0 or higher for inference.
356
+
357
+ We use tencent/Hunyuan-7B-Instruct for example
358
+ - Download Model file:
359
+ - Huggingface: will download automicly by vllm.
360
+ - ModelScope: `modelscope download --model Tencent-Hunyuan/Hunyuan-7B-Instruct`
361
+
362
+ - model download by huggingface:
363
+ ```shell
364
+ export MODEL_PATH=tencent/Hunyuan-7B-Instruct
365
+ ```
366
+
367
+ - model downloaded by modelscope:
368
+ ```shell
369
+ export MODEL_PATH=/root/.cache/modelscope/hub/models/Tencent-Hunyuan/Hunyuan-7B-Instruct/
370
+ ```
371
+
372
+ - Start the API server:
373
+
374
+ ```shell
375
+ python3 -m vllm.entrypoints.openai.api_server \
376
+ --host 0.0.0.0 \
377
+ --port 8000 \
378
+ --trust-remote-code \
379
+ --model ${MODEL_PATH} \
380
+ --tensor-parallel-size 1 \
381
+ --dtype bfloat16 \
382
+ --quantization experts_int8 \
383
+ --served-model-name hunyuan \
384
+ 2>&1 | tee log_server.txt
385
+ ```
386
+ - After running service script successfully, run the request script
387
+ ```shell
388
+ curl http://0.0.0.0:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
389
+ "model": "hunyuan",
390
+ "messages": [
391
+ {
392
+ "role": "system",
393
+ "content": [{"type": "text", "text": "You are a helpful assistant."}]
394
+ },
395
+ {
396
+ "role": "user",
397
+ "content": [{"type": "text", "text": "请按面积大小对四大洋进行排序,并给出面积最小的洋是哪一个?直接输出结果。"}]
398
+ }
399
+ ],
400
+ "max_tokens": 2048,
401
+ "temperature":0.7,
402
+ "top_p": 0.6,
403
+ "top_k": 20,
404
+ "repetition_penalty": 1.05,
405
+ "stop_token_ids": [127960]
406
+ }'
407
+ ```
408
+ #### Quantitative model deployment
409
+ This section describes the process of deploying a post-quantization model using vLLM.
410
+
411
+ Default server in BF16.
412
+
413
+ ##### Int8 quantitative model deployment
414
+ Deploying the Int8-weight-only version of the HunYuan-7B model only requires setting the environment variables
415
+
416
+ Next we start the Int8 service. Run:
417
+ ```shell
418
+ python3 -m vllm.entrypoints.openai.api_server \
419
+ --host 0.0.0.0 \
420
+ --port 8000 \
421
+ --trust-remote-code \
422
+ --model ${MODEL_PATH} \
423
+ --tensor-parallel-size 1 \
424
+ --dtype bfloat16 \
425
+ --served-model-name hunyuan \
426
+ --quantization experts_int8 \
427
+ 2>&1 | tee log_server.txt
428
+ ```
429
+
430
+
431
+ ##### Int4 quantitative model deployment
432
+ Deploying the Int4-weight-only version of the HunYuan-7B model only requires setting the environment variables , using the GPTQ method
433
+ ```shell
434
+ export MODEL_PATH=PATH_TO_INT4_MODEL
435
+ ```
436
+ Next we start the Int4 service. Run
437
+ ```shell
438
+ python3 -m vllm.entrypoints.openai.api_server \
439
+ --host 0.0.0.0 \
440
+ --port 8000 \
441
+ --trust-remote-code \
442
+ --model ${MODEL_PATH} \
443
+ --tensor-parallel-size 1 \
444
+ --dtype bfloat16 \
445
+ --served-model-name hunyuan \
446
+ --quantization gptq_marlin \
447
+ 2>&1 | tee log_server.txt
448
+ ```
449
+
450
+ ##### FP8 quantitative model deployment
451
+ Deploying the W8A8C8 version of the HunYuan-7B model only requires setting the environment variables
452
+
453
+
454
+ Next we start the FP8 service. Run
455
+ ```shell
456
+ python3 -m vllm.entrypoints.openai.api_server \
457
+ --host 0.0.0.0 \
458
+ --port 8000 \
459
+ --trust-remote-code \
460
+ --model ${MODEL_PATH} \
461
+ --tensor-parallel-size 1 \
462
+ --dtype bfloat16 \
463
+ --served-model-name hunyuan \
464
+ --kv-cache-dtype fp8 \
465
+ 2>&1 | tee log_server.txt
466
+ ```
467
+
468
+
469
+
470
+
471
+ ### SGLang
472
+
473
+ #### Docker Image
474
+
475
+ We also provide a pre-built Docker image based on the latest version of SGLang.
476
+
477
+ We use tencent/Hunyuan-7B-Instruct for example
478
+
479
+ To get started:
480
+
481
+ - Pull the Docker image
482
+
483
+ ```
484
+ docker pull lmsysorg/sglang:latest
485
+ ```
486
+
487
+ - Start the API server:
488
+
489
+ ```
490
+ docker run --entrypoint="python3" --gpus all \
491
+ --shm-size 32g \
492
+ -p 30000:30000 \
493
+ --ulimit nproc=10000 \
494
+ --privileged \
495
+ --ipc=host \
496
+ lmsysorg/sglang:latest \
497
+ -m sglang.launch_server --model-path hunyuan/huanyuan_7B --tp 4 --trust-remote-code --host 0.0.0.0 --port 30000
498
+ ```
499
+
500
+
501
+ ## Contact Us
502
+
503
+ If you would like to leave a message for our R&D and product teams, Welcome to contact our open-source team . You can also contact us via email ([email protected]).