ERNIE 4.5系列文本MoE模型,300B总参数,47B激活参数,采用异构MoE结构与高效并行策略,支持长文本生成,适配多硬件平台,适合通用语言理解与生成任务。【此简介由AI生成】
license: apache-2.0 language:
- en
- zh pipeline_tag: text-generation tags:
- ERNIE4.5 library_name: transformers
ERNIE-4.5-300B-A47B
Note
注意:“-Paddle”模型使用 PaddlePaddle 权重,而“-PT”模型使用 Transformer 风格的 PyTorch 权重。
ERNIE 4.5 亮点特性
ERNIE 4.5 模型(尤其是基于 MoE 的 A47B 和 A3B 系列)的卓越性能得益于多项关键技术创新:
-
多模态异构 MoE 预训练:我们的模型在文本和视觉两种模态上进行联合训练,以更好地捕捉多模态信息的细微差别,并提升在文本理解与生成、图像理解以及跨模态推理等任务上的性能。为实现这一目标,同时避免一种模态对另一种模态的学习造成干扰,我们设计了异构 MoE 结构,融入了模态隔离路由机制,并采用了路由正交损失函数与多模态令牌平衡损失函数。这些架构设计确保两种模态都能得到有效表征,从而在训练过程中实现相互增强。
-
高效扩展基础设施:我们提出了一种新颖的异构混合并行与分层负载均衡策略,用于 ERNIE 4.5 模型的高效训练。通过采用节点内专家并行、内存高效的流水线调度、FP8 混合精度训练以及细粒度重计算方法,我们实现了显著的预训练吞吐量。在推理方面,我们提出了多专家并行协作方法和卷积码量化算法,以实现 4 位/2 位无损量化。此外,我们引入了具有动态角色切换的 PD 解耦技术,以实现有效的资源利用,从而提升 ERNIE 4.5 MoE 模型的推理性能。ERNIE 4.5 构建于 PaddlePaddle 之上,能够在广泛的硬件平台上提供高性能推理。
-
特定模态后训练:为满足实际应用中的多样化需求,我们针对特定模态对预训练模型的变体进行了微调。我们的 LLM 针对通用语言理解和生成进行了优化。VLM 则专注于视觉-语言理解,并支持思考模式与非思考模式。每个模型在后续训练中均采用了监督微调(SFT)、直接偏好优化(DPO) 或一种名为统一偏好优化(UPO) 的改进型强化学习方法的组合。
模型概述
ERNIE-4.5-300B-A47B 是一个文本 MoE 后训练模型,总参数为 3000 亿,每个token的激活参数为 470 亿。以下是模型配置详情:
| 键 | 值 |
|---|---|
| 模态 | 文本 |
| 训练阶段 | 预训练 |
| 参数(总/激活) | 300B / 47B |
| 层数 | 54 |
| 头数(Q/KV) | 64 / 8 |
| 文本专家(总/激活) | 64 / 8 |
| 视觉专家(总/激活) | 64 / 8 |
| 上下文长度 | 131072 |
快速开始
使用 transformers 库
注意:在使用模型前,请确保已安装 transformers 库(即将发布的 4.54.0 版本或 最新版本)
以下代码片段展示了如何使用模型根据给定输入生成内容。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "baidu/ERNIE-4.5-300B-A47B-PT"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
torch_dtype=torch.bfloat16
)
# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], add_special_tokens=False, return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=1024
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# decode the generated ids
generate_text = tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n")
print("generate_text:", generate_text)
使用 vLLM
VLLM>=0.10.2(不包含 0.11.0)
# 80G * 16 GPU
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --tensor-parallel-size 16
# FP8 online quantification 80G * 8 GPU
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --tensor-parallel-size 8 --quantization fp8
最佳实践
采样参数
为获得最佳性能,建议使用 Temperature=0.8、TopP=0.8。
网络搜索提示词
对于网络搜索,{references}、{date} 和 {question} 为参数。
针对中文问题,我们使用以下提示词:
ernie_search_zh_prompt = \
'''下面你会收到当前时间、多个不同来源的参考文章和一段对话。你的任务是阅读多个参考文章,并根据参考文章中的信息回答对话中的问题。
以下是当前时间和参考文章:
---------
#当前时间
{date}
#参考文章
{references}
---------
请注意:
1. 回答必须结合问题需求和当前时间,对参考文章的可用性进行判断,避免在回答中使用错误或过时的信息。
2. 当参考文章中的信息无法准确地回答问题时,你需要在回答中提供获取相应信息的建议,或承认无法提供相应信息。
3. 你需要优先根据百科、官网、权威机构、专业网站等高权威性来源的信息来回答问题。
4. 回复需要综合参考文章中的相关数字、案例、法律条文、公式等信息,使你的答案更专业。
5. 当问题属于创作类任务时,需注意以下维度:
- 态度鲜明:观点、立场清晰明确,避免模棱两可,语言果断直接
- 文采飞扬:用词精准生动,善用修辞手法,增强感染力
- 有理有据:逻辑严密递进,结合权威数据/事实支撑论点
---------
下面请结合以上信息,回答问题,补全对话
{question}'''
对于英文问题,我们使用以下提示词:
ernie_search_en_prompt = \
'''
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.
Here are the current time and the references:
---------
#Current Time
{date}
#References
{references}
---------
Please note:
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.
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.
3. Prioritize using information from highly authoritative sources such as encyclopedias, official websites, authoritative institutions, and professional websites when answering questions.
4. Incorporate relevant numbers, cases, legal provisions, formulas, and other details from the references to make your answer more professional.
5. For creative tasks, keep these dimensions in mind:
- Clear attitude: Clear views and positions, avoid ambiguity, and use decisive and direct language
- Brilliant writing: Precise and vivid words, good use of rhetoric, and enhance the appeal
- Well-reasoned: Rigorous logic and progressive, combined with authoritative data/facts to support the argument
---------
Now, using the information above, answer the question and complete the conversation:
{question}'''
参数说明:
- {question} 为用户的问题
- {date} 为当前时间,推荐格式为“YYYY-MM-DD HH:MM:SS,星期X,中国北京”
- {references} 为参考资料,推荐格式为:
##参考文章1
标题:周杰伦
文章发布时间:2025-04-20
内容:周杰伦(Jay Chou),1979年1月18日出生于台湾省新北市,祖籍福建省永春县,华语流行乐男歌手、音乐人、演员、导演、编剧,毕业于淡江中学。2000年,发行个人首张音乐专辑《Jay》。...
来源网站网址:baike.baidu.com
来源网站的网站名:百度百科
##参考文章2
...
许可协议
ERNIE 4.5 模型基于 Apache License 2.0 许可协议提供。本许可协议允许商业使用,但需遵守其条款和条件。版权所有 (c) 2025 百度公司。保留所有权利。
引用说明
如果您认为 ERNIE 4.5 模型对您有所帮助,或希望在您的项目中使用该模型,请引用我们的技术报告:
@misc{ernie2025technicalreport,
title={ERNIE 4.5 Technical Report},
author={Baidu ERNIE Team},
year={2025},
eprint={},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={}
}