liaojc commited on
Commit
0f21e2f
·
verified ·
1 Parent(s): 5c0cbc4

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +26 -176
README.md CHANGED
@@ -29,7 +29,7 @@ tags:
29
  </a>
30
  </div>
31
 
32
- # ERNIE-4.5-300B-A47B
33
 
34
  ## ERNIE 4.5 Highlights
35
 
@@ -41,20 +41,22 @@ The advanced capabilities of the ERNIE 4.5 models, particularly the MoE-based A4
41
 
42
  3. **Modality-Specific Post-Training:** To meet the diverse requirements of real-world applications, we fine-tuned variants of the pre-trained model for specific modalities. Our LLMs are optimized for general-purpose language understanding and generation. The VLMs focuses on visuallanguage understanding and supports both thinking and non-thinking modes. Each model employed a combination of *Supervised Fine-tuning (SFT)*, *Direct Preference Optimization (DPO)* or a modified reinforcement learning method named *Unified Preference Optimization (UPO)* for post-training.
43
 
 
 
44
  ## Model Overview
45
 
46
- ERNIE-4.5-300B-A47B is a text MoE Post-trained model, with 300B total parameters and 47B activated parameters for each token. The following are the model configuration details:
47
 
48
- |Key|Value|
49
- |-|-|
50
- |Modality|Text|
51
- |Training Stage|Pretraining|
52
- |Params(Total / Activated)|300B / 47B|
53
- |Layers|54|
54
- |Heads(Q/KV)|64 / 8|
55
- |Text Experts(Total / Activated)|64 / 8|
56
- |Vision Experts(Total / Activated)|64 / 8|
57
- |Context Length|131072|
58
 
59
  ## Quickstart
60
 
@@ -66,18 +68,15 @@ Usage Examples:
66
 
67
  ```bash
68
  # Download model
69
- huggingface-cli download baidu/ERNIE-4.5-300B-A47B-Paddle --local-dir baidu/ERNIE-4.5-300B-A47B-Paddle
70
  # SFT
71
- erniekit train examples/configs/ERNIE-4.5-300B-A47B/sft/run_sft_wint8mix_lora_8k.yaml
72
  # DPO
73
- erniekit train examples/configs/ERNIE-4.5-300B-A47B/dpo/run_dpo_wint8mix_lora_8k.yaml
74
  ```
75
 
76
  For more detailed examples, including SFT with LoRA, multi-GPU configurations, and advanced scripts, please refer to the examples folder within the [ERNIEKit](https://github.com/PaddlePaddle/ERNIE) repository.
77
 
78
-
79
-
80
-
81
  ### Using FastDeploy
82
 
83
  Service deployment can be quickly completed using FastDeploy in the following command. For more detailed usage instructions, please refer to the [FastDeploy Repository](https://github.com/PaddlePaddle/FastDeploy).
@@ -86,64 +85,16 @@ Service deployment can be quickly completed using FastDeploy in the following co
86
 
87
  ```bash
88
  python -m fastdeploy.entrypoints.openai.api_server \
89
- --model baidu/ERNIE-4.5-300B-A47B-Paddle \
90
  --port 8180 \
91
  --metrics-port 8181 \
 
92
  --quantization wint4 \
93
  --tensor-parallel-size 8 \
94
- --engine-worker-queue-port 8182 \
95
  --max-model-len 32768 \
96
  --max-num-seqs 32
97
  ```
98
 
99
- To deploy the W4A8C8 quantized version using FastDeploy, you can run the following command.
100
-
101
- ```bash
102
- python -m fastdeploy.entrypoints.openai.api_server \
103
- --model baidu/ERNIE-4.5-300B-A47B-W4A8C8-TP4-Paddle \
104
- --port 8180 \
105
- --metrics-port 8181 \
106
- --engine-worker-queue-port 8182 \
107
- --tensor-parallel-size 4 \
108
- --max-model-len 32768 \
109
- --max-num-seqs 32
110
- ```
111
-
112
- To deploy the WINT2 quantized version using FastDeploy on a single 141G GPU, you can run the following command.
113
-
114
- ```bash
115
- python -m fastdeploy.entrypoints.openai.api_server \
116
- --model "baidu/ERNIE-4.5-300B-A47B-2Bits-Paddle" \
117
- --port 8180 \
118
- --metrics-port 8181 \
119
- --engine-worker-queue-port 8182 \
120
- --tensor-parallel-size 1 \
121
- --max-model-len 32768 \
122
- --max-num-seqs 128
123
- ```
124
-
125
- The following contains a code snippet illustrating how to use ERNIE-4.5-300B-A47B-FP8 generate content based on given inputs.
126
-
127
- ```python
128
- from fastdeploy import LLM, SamplingParams
129
-
130
- prompts = [
131
- "Hello, my name is",
132
- ]
133
-
134
- sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=128)
135
-
136
- model = "baidu/ERNIE-4.5-300B-A47B-FP8-Paddle"
137
- llm = LLM(model=model, tensor_parallel_size=8, max_model_len=8192, num_gpu_blocks_override=1024, engine_worker_queue_port=9981)
138
-
139
- outputs = llm.generate(prompts, sampling_params)
140
-
141
- for output in outputs:
142
- prompt = output.prompt
143
- generated_text = output.outputs.text
144
- print("generated_text", generated_text)
145
- ```
146
-
147
  ### Using `transformers` library
148
 
149
  The following contains a code snippet illustrating how to use the model generate content based on given inputs.
@@ -151,34 +102,19 @@ The following contains a code snippet illustrating how to use the model generate
151
  ```python
152
  from transformers import AutoModelForCausalLM, AutoTokenizer
153
 
154
- model_name = "baidu/ERNIE-4.5-300B-A47B-PT"
155
-
156
- # load the tokenizer and the model
157
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
158
  model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
159
 
160
- # prepare the model input
161
- prompt = "Give me a short introduction to large language model."
162
- messages = [
163
- {"role": "user", "content": prompt}
164
- ]
165
- text = tokenizer.apply_chat_template(
166
- messages,
167
- tokenize=False,
168
- add_generation_prompt=True
169
- )
170
- model_inputs = tokenizer([text], add_special_tokens=False, return_tensors="pt").to(model.device)
171
 
172
- # conduct text completion
173
  generated_ids = model.generate(
174
  model_inputs.input_ids,
175
  max_new_tokens=1024
176
  )
177
- output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
178
-
179
- # decode the generated ids
180
- generate_text = tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n")
181
- print("generate_text:", generate_text)
182
  ```
183
 
184
  ### Using vLLM
@@ -187,98 +123,12 @@ vLLM is currently being adapted, priority can be given to using our forked repos
187
 
188
  ```bash
189
  # 80G * 16 GPU
190
- vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code
191
  ```
192
 
193
  ```bash
194
  # FP8 online quantification 80G * 8 GPU
195
- vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code --quantization fp8
196
- ```
197
-
198
- ## Best Practices
199
-
200
- ### **Sampling Parameters**
201
-
202
- To achieve optimal performance, we suggest using `Temperature=0.8`, `TopP=0.8`.
203
-
204
- ### Prompts for Web Search
205
-
206
- For Web Search, {references}, {date}, and {question} are arguments.
207
-
208
- For Chinese question, we use the prompt:
209
-
210
- ```python
211
- ernie_search_zh_prompt = \
212
- '''下面你会收到当前时间、多个不同来源的参考文章和一段对话。你的任务是阅读多个参考文章,并根据参考文章中的信息回答对话中的问题。
213
- 以下是当前时间和参考文章:
214
- ---------
215
- #当前时间
216
- {date}
217
-
218
- #参考文章
219
- {references}
220
-
221
- ---------
222
- 请注意:
223
- 1. 回答必须结合问题需求和当前时间,对参考文章的可用性进行判断,避免在回答中使用错误或过时的信息。
224
- 2. 当参考文章中的信息无法准确地回答问题时,你需要在回答中提供获取相应信息的建议,或承认无法提供相应信息。
225
- 3. 你需要优先根据百科、官网、权威机构、专业网站等高权威性来源的信息来回答问题。
226
- 4. 回复需要综合参考文章中的相关数字、案例、法律条文、公式等信息,使你的答案更专业。
227
- 5. 当问题属于创作类任务时,需注意以下维度:
228
- - 态度鲜明:观点、立场清晰明确,避免模棱两可,语言果断直接
229
- - 文采飞扬:用词精准生动,善用修辞手法,增强感染力
230
- - 有理有据:逻辑严密递进,结合权威数据/事实支撑论点
231
- ---------
232
- 下面请结合以上信息,回答问题,补全对话
233
- {question}'''
234
- ```
235
-
236
- For English question, we use the prompt:
237
-
238
- ```python
239
- ernie_search_en_prompt = \
240
- '''
241
- Below you will be given the current time, multiple references from different sources, and a conversation. Your task is to read the references and use the information in them to answer the question in the conversation.
242
- Here are the current time and the references:
243
- ---------
244
- #Current Time
245
- {date}
246
-
247
- #References
248
- {references}
249
-
250
- ---------
251
- Please note:
252
- 1. Based on the question’s requirements and the current time, assess the usefulness of the references to avoid using inaccurate or outdated information in the answer.
253
- 2. If the references do not provide enough information to accurately answer the question, you should suggest how to obtain the relevant information or acknowledge that you are unable to provide it.
254
- 3. Prioritize using information from highly authoritative sources such as encyclopedias, official websites, authoritative institutions, and professional websites when answering questions.
255
- 4. Incorporate relevant numbers, cases, legal provisions, formulas, and other details from the references to make your answer more professional.
256
- 5. For creative tasks, keep these dimensions in mind:
257
- - Clear attitude: Clear views and positions, avoid ambiguity, and use decisive and direct language
258
- - Brilliant writing: Precise and vivid words, good use of rhetoric, and enhance the appeal
259
- - Well-reasoned: Rigorous logic and progressive, combined with authoritative data/facts to support the argument
260
-
261
- ---------
262
- Now, using the information above, answer the question and complete the conversation:
263
- {question}'''
264
- ```
265
-
266
- Parameter notes:
267
-
268
- * {question} is the user’s question
269
- * {date} is the current time, and the recommended format is “YYYY-MM-DD HH:MM:SS, Day of the Week, Beijing/China.”
270
- * {references} is the references, and the recommended format is:
271
-
272
- ```text
273
- ##参考文章1
274
- 标题:周杰伦
275
- 文章发布时间:2025-04-20
276
- 内容:周杰伦(Jay Chou),1979年1月18日出生于台湾省新北市,祖籍福建省永春县,华语流行乐男歌手、音乐人、演员、导演、编剧,毕业于淡江中学。2000年,发行个人首张音乐专辑《Jay》。...
277
- 来源网站网址:baike.baidu.com
278
- 来源网站的网站名:百度百科
279
-
280
- ##参考文章2
281
- ...
282
  ```
283
 
284
  ## License
 
29
  </a>
30
  </div>
31
 
32
+ # ERNIE-4.5-300B-A47B-Base
33
 
34
  ## ERNIE 4.5 Highlights
35
 
 
41
 
42
  3. **Modality-Specific Post-Training:** To meet the diverse requirements of real-world applications, we fine-tuned variants of the pre-trained model for specific modalities. Our LLMs are optimized for general-purpose language understanding and generation. The VLMs focuses on visuallanguage understanding and supports both thinking and non-thinking modes. Each model employed a combination of *Supervised Fine-tuning (SFT)*, *Direct Preference Optimization (DPO)* or a modified reinforcement learning method named *Unified Preference Optimization (UPO)* for post-training.
43
 
44
+ To ensure the stability of multimodal joint training, we adopt a staged training strategy. In the first and second stage, we train only the text-related parameters, enabling the model to develop strong fundamental language understanding as well as long-text processing capabilities. The final multimodal stage extends capabilities to images and videos by introducing additional parameters including a ViT for image feature extraction, an adapter for feature transformation, and visual experts for multimodal understanding. At this stage, text and visual modalities mutually enhance each other. After pretraining trillions tokens, we extracted the text-related parameters and finally obtained ERNIE-4.5-300B-A47B-Base。
45
+
46
  ## Model Overview
47
 
48
+ ERNIE-4.5-300B-A47B-Base is a text MoE Base model, with 300B total parameters and 47B activated parameters for each token. The following are the model configuration details:
49
 
50
+ | Key | Value |
51
+ | --- | --- |
52
+ | Modality | Text |
53
+ | Training Stage | Pretraining |
54
+ | Params(Total / Activated) | 300B / 47B |
55
+ | Layers | 54 |
56
+ | Heads(Q/KV) | 64 / 8 |
57
+ | Text Experts(Total / Activated) | 64 / 8 |
58
+ | Vision Experts(Total / Activated) | 64 / 8 |
59
+ | Context Length | 131072 |
60
 
61
  ## Quickstart
62
 
 
68
 
69
  ```bash
70
  # Download model
71
+ huggingface-cli download baidu/ERNIE-4.5-300B-A47B-Base-Paddle --local-dir baidu/ERNIE-4.5-300B-A47B-Base-Paddle
72
  # SFT
73
+ erniekit train examples/configs/ERNIE-4.5-300B-A47B/sft/run_sft_wint8mix_lora_8k.yaml model_name_or_path=baidu/ERNIE-4.5-300B-A47B-Base-Paddle
74
  # DPO
75
+ erniekit train examples/configs/ERNIE-4.5-300B-A47B/dpo/run_dpo_wint8mix_lora_8k.yaml model_name_or_path=baidu/ERNIE-4.5-300B-A47B-Base-Paddle
76
  ```
77
 
78
  For more detailed examples, including SFT with LoRA, multi-GPU configurations, and advanced scripts, please refer to the examples folder within the [ERNIEKit](https://github.com/PaddlePaddle/ERNIE) repository.
79
 
 
 
 
80
  ### Using FastDeploy
81
 
82
  Service deployment can be quickly completed using FastDeploy in the following command. For more detailed usage instructions, please refer to the [FastDeploy Repository](https://github.com/PaddlePaddle/FastDeploy).
 
85
 
86
  ```bash
87
  python -m fastdeploy.entrypoints.openai.api_server \
88
+ --model baidu/ERNIE-4.5-300B-A47B-Base-Paddle \
89
  --port 8180 \
90
  --metrics-port 8181 \
91
+ --engine-worker-queue-port 8182 \
92
  --quantization wint4 \
93
  --tensor-parallel-size 8 \
 
94
  --max-model-len 32768 \
95
  --max-num-seqs 32
96
  ```
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ### Using `transformers` library
99
 
100
  The following contains a code snippet illustrating how to use the model generate content based on given inputs.
 
102
  ```python
103
  from transformers import AutoModelForCausalLM, AutoTokenizer
104
 
105
+ model_name = "baidu/ERNIE-4.5-300B-A47B-Base-PT"
 
 
106
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
107
  model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
108
 
109
+ prompt = "Large language model is"
110
+ model_inputs = tokenizer([prompt], add_special_tokens=False, return_tensors="pt").to(model.device)
 
 
 
 
 
 
 
 
 
111
 
 
112
  generated_ids = model.generate(
113
  model_inputs.input_ids,
114
  max_new_tokens=1024
115
  )
116
+ result = tokenizer.decode(generated_ids[0].tolist(), skip_special_tokens=True)
117
+ print("result:", result)
 
 
 
118
  ```
119
 
120
  ### Using vLLM
 
123
 
124
  ```bash
125
  # 80G * 16 GPU
126
+ vllm serve baidu/ERNIE-4.5-300B-A47B-Base-PT --trust-remote-code
127
  ```
128
 
129
  ```bash
130
  # FP8 online quantification 80G * 8 GPU
131
+ vllm serve baidu/ERNIE-4.5-300B-A47B-Base-PT --trust-remote-code --quantization fp8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  ```
133
 
134
  ## License