gabriellarson commited on
Commit
60e762f
·
verified ·
1 Parent(s): 6c4e586

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +478 -0
README.md ADDED
@@ -0,0 +1,478 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - tencent/Hunyuan-1.8B-Instruct
4
+ library_name: transformers
5
+ ---
6
+ <p align="left">
7
+ <a href="README_CN.md">中文</a>&nbsp | English</a>
8
+ </p>
9
+ <br><br>
10
+ <p align="center">
11
+ <img src="https://dscache.tencent-cloud.cn/upload/uploader/hunyuan-64b418fd052c033b228e04bc77bbc4b54fd7f5bc.png" width="400"/> <br>
12
+ </p><p></p>
13
+
14
+
15
+ <p align="center">
16
+ 🤗&nbsp;<a href="https://huggingface.co/tencent/"><b>Hugging Face</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
17
+ <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;
18
+ <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>
19
+ </p>
20
+ <p align="center">
21
+ 🖥️&nbsp;<a href="https://hunyuan.tencent.com" style="color: red;"><b>Official Website</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
22
+ 🕖&nbsp;<a href="https://cloud.tencent.com/product/hunyuan"><b>HunyuanAPI</b></a>&nbsp;&nbsp;|&nbsp;&nbsp;
23
+ 🕹️&nbsp;<a href="https://hunyuan.tencent.com/"><b>Demo</b></a>&nbsp;&nbsp;&nbsp;&nbsp;
24
+ </p>
25
+ <p align="center">
26
+ <a href="https://github.com/Tencent-Hunyuan/Hunyuan-7B"><b>GITHUB</b></a> |
27
+ <a href="https://cnb.cool/tencent/hunyuan/Hunyuan-7B"><b>cnb.cool</b></a> |
28
+ <a href="https://github.com/Tencent-Hunyuan/Hunyuan-7B/blob/main/LICENSE"><b>LICENSE</b></a>
29
+ </p>
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
+ model_name_or_path = "tencent/Hunyuan-7B-Instruct"
102
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
103
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map="auto") # You may want to use bfloat16 and/or move to GPU here
104
+ messages = [
105
+ {"role": "user", "content": "Write a short summary of the benefits of regular exercise"},
106
+ ]
107
+ tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True,return_tensors="pt",
108
+ enable_thinking=True # Toggle thinking mode (default: True)
109
+ )
110
+
111
+ outputs = model.generate(tokenized_chat.to(model.device), max_new_tokens=2048)
112
+ output_text = tokenizer.decode(outputs[0])
113
+ print("output_text=",output_text)
114
+ think_pattern = r'<think>(.*?)</think>'
115
+ think_matches = re.findall(think_pattern, output_text, re.DOTALL)
116
+ answer_pattern = r'<answer>(.*?)</answer>'
117
+ answer_matches = re.findall(answer_pattern, output_text, re.DOTALL)
118
+ think_content = [match.strip() for match in think_matches][0]
119
+ answer_content = [match.strip() for match in answer_matches][0]
120
+ print(f"thinking_content:{think_content}\n\n")
121
+ print(f"answer_content:{answer_content}\n\n")
122
+ ```
123
+
124
+ We recommend using the following set of parameters for inference. Note that our model does not have the default system_prompt.
125
+ ```json
126
+ {
127
+ "do_sample": true,
128
+ "top_k": 20,
129
+ "top_p": 0.8,
130
+ "repetition_penalty": 1.05,
131
+ "temperature": 0.7
132
+ }
133
+ ```
134
+ &nbsp;
135
+ ### Training Data Format
136
+ 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.
137
+ ```python
138
+ # think_pattern
139
+ think = ""
140
+ answer = ""
141
+ think_pattern = f"<think>\n{think}\n</think>\n<answer>\n{answer}\n</answer>"
142
+ # fast think pattern
143
+ messages = [
144
+ {"role": "system", "content": "You are a helpful assistant."},
145
+ {"role": "user", "content": "/no_think海水为什么是咸的" },
146
+ {"role": "assistant", "content": "<think>\n\n</think>\n<answer>\n海水是咸的主要是因为其中含有许多溶解在水中的盐类和矿物质。这些盐类和矿物质来自于地球表面的岩石和土壤中的化学物质,随着时间的推移,它们被带到了海洋中。当海水蒸发时,水分蒸发掉了,但盐类和矿物质仍然留在水中,导致海水变得更加咸味。因此,海水的咸度是由其中的盐类和矿物质的含量决定的。\n</answer>"}
147
+ ]
148
+ # slow think pattern
149
+ messages = [
150
+ {"role": "system", "content": "You are a helpful assistant."},
151
+ {"role": "user", "content": "1+1=" },
152
+ {"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>"}
153
+ ]
154
+ from transformers import AutoTokenizer
155
+ tokenizer = AutoTokenizer.from_pretrained("your_tokenizer_path", trust_remote_code=True)
156
+ train_ids = tokenizer.apply_chat_template(messages)
157
+ ```
158
+ &nbsp;
159
+ ### Train with LLaMA-Factory
160
+ In the following chapter, we will introduce how to use `LLaMA-Factory` to fine-tune the `Hunyuan` model.
161
+ #### Prerequisites
162
+ Verify installation of the following dependencies:
163
+ - **LLaMA-Factory**: Follow [official installation guide](https://github.com/hiyouga/LLaMA-Factory)
164
+ - **DeepSpeed** (optional): Follow [official installation guide](https://github.com/deepspeedai/DeepSpeed#installation)
165
+ - **Transformer Library**: Use the companion branch (Hunyuan-submitted code is pending review)
166
+ ```
167
+ pip install git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca
168
+ ```
169
+ #### Data preparation
170
+
171
+ We need to prepare a custom dataset:
172
+ 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:
173
+ ```
174
+ [
175
+ {
176
+ "messages": [
177
+ {
178
+ "role": "system",
179
+ "content": "System prompt (optional)"
180
+ },
181
+ {
182
+ "role": "user",
183
+ "content": "Human instruction"
184
+ },
185
+ {
186
+ "role": "assistant",
187
+ "content": "Model response"
188
+ }
189
+ ]
190
+ }
191
+ ]
192
+ ```
193
+ Refer to the [Data Format](#training-data-format) section mentioned earlier for details.
194
+
195
+ 2. Define your dataset in the data/dataset_info.json file using the following format:
196
+ ```
197
+ "dataset_name": {
198
+ "file_name": "dataset.json",
199
+ "formatting": "sharegpt",
200
+ "columns": {
201
+ "messages": "messages"
202
+ },
203
+ "tags": {
204
+ "role_tag": "role",
205
+ "content_tag": "content",
206
+ "user_tag": "user",
207
+ "assistant_tag": "assistant",
208
+ "system_tag": "system"
209
+ }
210
+ }
211
+ ```
212
+ #### Training execution
213
+
214
+ 1. Copy all files from the `train/llama_factory_support/example_configs` directory to the `example/hunyuan` directory in `LLaMA-Factory`.
215
+ 2. Modify the model path and dataset name in the configuration file `hunyuan_full.yaml`. Adjust other configurations as needed:
216
+ ```
217
+ ### model
218
+ model_name_or_path: [!!!add the model path here!!!]
219
+ ### dataset
220
+ dataset: [!!!add the dataset name here!!!]
221
+ ```
222
+ 3. Execute training commands:
223
+ *​​Single-node training​​
224
+ Note: Set the environment variable DISABLE_VERSION_CHECK to 1 to avoid version conflicts.
225
+ ```
226
+ export DISABLE_VERSION_CHECK=1
227
+ llamafactory-cli train examples/hunyuan/hunyuan_full.yaml
228
+ ```
229
+ *Multi-node training​​
230
+ Execute the following command on each node. Configure NNODES, NODE_RANK, MASTER_ADDR, and MASTER_PORT according to your environment:
231
+ ```
232
+ export DISABLE_VERSION_CHECK=1
233
+ FORCE_TORCHRUN=1 NNODES=${NNODES} NODE_RANK=${NODE_RANK} MASTER_ADDR=${MASTER_ADDR} MASTER_PORT=${MASTER_PORT} \
234
+ llamafactory-cli train examples/hunyuan/hunyuan_full.yaml
235
+ ```
236
+ &nbsp;
237
+
238
+
239
+ ## Quantization Compression
240
+ 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.
241
+
242
+ ### FP8 Quantization
243
+ 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/).
244
+
245
+ ### Int4 Quantization
246
+ We use the GPTQ and AWQ algorithm to achieve W4A16 quantization.
247
+
248
+ 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.
249
+ 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.
250
+
251
+ 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/).
252
+
253
+
254
+
255
+ #### Quantization Benchmark
256
+ This subsection describes the Benchmark metrics for the Hunyuan quantitative model.
257
+
258
+ | Bench | Quantization | Hunyuan-0.5B-Instruct | Hunyuan-1.8B-Instruct | Hunyuan-4B-Instruct | Hunyuan-7B-Instruct |
259
+ |:-------------:|:---------------------------------:|:----------------------------:|:------------------------------:|:----------------------------:|:----------------------------:|
260
+ | 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 |
261
+ | 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 |
262
+ | 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 |
263
+ | 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 |
264
+
265
+
266
+ ## Deployment
267
+
268
+ For deployment, you can use frameworks such as **TensorRT-LLM**, **vLLM**, or **SGLang** to serve the model and create an OpenAI-compatible API endpoint.
269
+
270
+ image: https://hub.docker.com/r/hunyuaninfer/hunyuan-7B/tags
271
+
272
+
273
+ ### TensorRT-LLM
274
+
275
+ #### Docker Image
276
+
277
+ We provide a pre-built Docker image based on the latest version of TensorRT-LLM.
278
+
279
+ We use tencent/Hunyuan-7B-Instruct for example
280
+ - To get started:
281
+
282
+ https://hub.docker.com/r/hunyuaninfer/hunyuan-large/tags
283
+
284
+ ```
285
+ docker pull hunyuaninfer/hunyuan-7B:hunyuan-moe-7B-trtllm
286
+ ```
287
+ ```
288
+ 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
289
+ ```
290
+
291
+ - Prepare Configuration file:
292
+
293
+ ```
294
+ cat >/path/to/extra-llm-api-config.yml <<EOF
295
+ use_cuda_graph: true
296
+ cuda_graph_padding_enabled: true
297
+ cuda_graph_batch_sizes:
298
+ - 1
299
+ - 2
300
+ - 4
301
+ - 8
302
+ - 16
303
+ - 32
304
+ print_iter_log: true
305
+ EOF
306
+ ```
307
+
308
+
309
+ - Start the API server:
310
+
311
+
312
+ ```
313
+ trtllm-serve \
314
+ /path/to/HunYuan-moe-7B \
315
+ --host localhost \
316
+ --port 8000 \
317
+ --backend pytorch \
318
+ --max_batch_size 32 \
319
+ --max_num_tokens 16384 \
320
+ --tp_size 2 \
321
+ --kv_cache_free_gpu_memory_fraction 0.6 \
322
+ --trust_remote_code \
323
+ --extra_llm_api_options /path/to/extra-llm-api-config.yml
324
+ ```
325
+
326
+
327
+ ### vllm
328
+
329
+ #### Start
330
+ Please use vLLM version v0.10.0 or higher for inference.
331
+
332
+ We use tencent/Hunyuan-7B-Instruct for example
333
+ - Download Model file:
334
+ - Huggingface: will download automicly by vllm.
335
+ - ModelScope: `modelscope download --model Tencent-Hunyuan/Hunyuan-7B-Instruct`
336
+
337
+ - model download by huggingface:
338
+ ```shell
339
+ export MODEL_PATH=tencent/Hunyuan-7B-Instruct
340
+ ```
341
+
342
+ - model downloaded by modelscope:
343
+ ```shell
344
+ export MODEL_PATH=/root/.cache/modelscope/hub/models/Tencent-Hunyuan/Hunyuan-7B-Instruct/
345
+ ```
346
+
347
+ - Start the API server:
348
+
349
+ ```shell
350
+ python3 -m vllm.entrypoints.openai.api_server \
351
+ --host 0.0.0.0 \
352
+ --port 8000 \
353
+ --trust-remote-code \
354
+ --model ${MODEL_PATH} \
355
+ --tensor-parallel-size 1 \
356
+ --dtype bfloat16 \
357
+ --quantization experts_int8 \
358
+ --served-model-name hunyuan \
359
+ 2>&1 | tee log_server.txt
360
+ ```
361
+ - After running service script successfully, run the request script
362
+ ```shell
363
+ curl http://0.0.0.0:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
364
+ "model": "hunyuan",
365
+ "messages": [
366
+ {
367
+ "role": "system",
368
+ "content": [{"type": "text", "text": "You are a helpful assistant."}]
369
+ },
370
+ {
371
+ "role": "user",
372
+ "content": [{"type": "text", "text": "请按面积大小对四大洋进行排序,并给出面积最小的洋是哪一个?直接输出结果。"}]
373
+ }
374
+ ],
375
+ "max_tokens": 2048,
376
+ "temperature":0.7,
377
+ "top_p": 0.6,
378
+ "top_k": 20,
379
+ "repetition_penalty": 1.05,
380
+ "stop_token_ids": [127960]
381
+ }'
382
+ ```
383
+ #### Quantitative model deployment
384
+ This section describes the process of deploying a post-quantization model using vLLM.
385
+
386
+ Default server in BF16.
387
+
388
+ ##### Int8 quantitative model deployment
389
+ Deploying the Int8-weight-only version of the HunYuan-7B model only requires setting the environment variables
390
+
391
+ Next we start the Int8 service. Run:
392
+ ```shell
393
+ python3 -m vllm.entrypoints.openai.api_server \
394
+ --host 0.0.0.0 \
395
+ --port 8000 \
396
+ --trust-remote-code \
397
+ --model ${MODEL_PATH} \
398
+ --tensor-parallel-size 1 \
399
+ --dtype bfloat16 \
400
+ --served-model-name hunyuan \
401
+ --quantization experts_int8 \
402
+ 2>&1 | tee log_server.txt
403
+ ```
404
+
405
+
406
+ ##### Int4 quantitative model deployment
407
+ Deploying the Int4-weight-only version of the HunYuan-7B model only requires setting the environment variables , using the GPTQ method
408
+ ```shell
409
+ export MODEL_PATH=PATH_TO_INT4_MODEL
410
+ ```
411
+ Next we start the Int4 service. Run
412
+ ```shell
413
+ python3 -m vllm.entrypoints.openai.api_server \
414
+ --host 0.0.0.0 \
415
+ --port 8000 \
416
+ --trust-remote-code \
417
+ --model ${MODEL_PATH} \
418
+ --tensor-parallel-size 1 \
419
+ --dtype bfloat16 \
420
+ --served-model-name hunyuan \
421
+ --quantization gptq_marlin \
422
+ 2>&1 | tee log_server.txt
423
+ ```
424
+
425
+ ##### FP8 quantitative model deployment
426
+ Deploying the W8A8C8 version of the HunYuan-7B model only requires setting the environment variables
427
+
428
+
429
+ Next we start the FP8 service. Run
430
+ ```shell
431
+ python3 -m vllm.entrypoints.openai.api_server \
432
+ --host 0.0.0.0 \
433
+ --port 8000 \
434
+ --trust-remote-code \
435
+ --model ${MODEL_PATH} \
436
+ --tensor-parallel-size 1 \
437
+ --dtype bfloat16 \
438
+ --served-model-name hunyuan \
439
+ --kv-cache-dtype fp8 \
440
+ 2>&1 | tee log_server.txt
441
+ ```
442
+
443
+
444
+
445
+
446
+ ### SGLang
447
+
448
+ #### Docker Image
449
+
450
+ We also provide a pre-built Docker image based on the latest version of SGLang.
451
+
452
+ We use tencent/Hunyuan-7B-Instruct for example
453
+
454
+ To get started:
455
+
456
+ - Pull the Docker image
457
+
458
+ ```
459
+ docker pull lmsysorg/sglang:latest
460
+ ```
461
+
462
+ - Start the API server:
463
+
464
+ ```
465
+ docker run --entrypoint="python3" --gpus all \
466
+ --shm-size 32g \
467
+ -p 30000:30000 \
468
+ --ulimit nproc=10000 \
469
+ --privileged \
470
+ --ipc=host \
471
+ lmsysorg/sglang:latest \
472
+ -m sglang.launch_server --model-path hunyuan/huanyuan_7B --tp 4 --trust-remote-code --host 0.0.0.0 --port 30000
473
+ ```
474
+
475
+
476
+ ## Contact Us
477
+
478
+ 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]).