🚀 ERNIE-4.5-300B-A47B
ERNIE-4.5-300B-A47B 是一款文本 MoE 后训练模型,拥有 3000 亿的总参数,每个标记有 470 亿的激活参数。该模型具备多模态异构 MoE 预训练、高效扩展基础设施和特定模态后训练等先进技术,能在文本理解与生成、图像理解及跨模态推理等任务中表现出色。
🚀 快速开始
使用 transformers
库
注意:在使用该模型之前,请确保你已安装 transformers
库(版本 4.50.0 或更高)。
以下代码片段展示了如何使用该模型根据给定输入生成内容:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "baidu/ERNIE-4.5-300B-A47B-PT"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
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)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=1024
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
generate_text = tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n")
print("generate_text:", generate_text)
使用 vLLM
vllm GitHub 库。仅支持 Python 的 构建。
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code --quantization fp8
✨ 主要特性
ERNIE 4.5 模型,特别是基于 MoE 的 A47B 和 A3B 系列,其先进能力得益于以下几项关键技术创新:
- 多模态异构 MoE 预训练:我们的模型在文本和视觉两种模态上进行联合训练,以更好地捕捉多模态信息的细微差别,并提高在涉及文本理解与生成、图像理解和跨模态推理等任务上的性能。为了避免一种模态阻碍另一种模态的学习,我们设计了一种异构 MoE 结构,引入了模态隔离路由,并采用了路由正交损失和多模态标记平衡损失。这些架构选择确保了两种模态都能得到有效表示,从而在训练过程中实现相互强化。
- 高效扩展基础设施:我们提出了一种新颖的异构混合并行和分层负载均衡策略,用于高效训练 ERNIE 4.5 模型。通过使用节点内专家并行、内存高效的流水线调度、FP8 混合精度训练和细粒度重计算方法,我们实现了显著的预训练吞吐量。在推理方面,我们提出了多专家并行协作方法和卷积代码量化算法,以实现 4 位/2 位无损量化。此外,我们引入了具有动态角色切换的 PD 分拆技术,以有效利用资源,提升 ERNIE 4.5 MoE 模型的推理性能。基于 PaddlePaddle 构建,ERNIE 4.5 能够在广泛的硬件平台上实现高性能推理。
- 特定模态后训练:为了满足现实应用的多样化需求,我们针对特定模态对预训练模型的变体进行了微调。我们的大语言模型(LLMs)针对通用语言理解和生成进行了优化。视觉语言模型(VLMs)专注于视觉语言理解,并支持思考和非思考两种模式。每个模型在后期训练中都采用了监督微调(SFT)、*直接偏好优化(DPO)或一种名为统一偏好优化(UPO)*的改进强化学习方法。
📚 详细文档
模型概述
ERNIE-4.5-300B-A47B 是一个文本 MoE 后训练模型,总参数为 3000 亿,每个标记的激活参数为 470 亿。以下是模型配置的详细信息:
属性 |
详情 |
模态 |
文本 |
训练阶段 |
预训练 |
参数(总参数 / 激活参数) |
3000 亿 / 470 亿 |
层数 |
54 |
头数(Q/KV) |
64 / 8 |
文本专家(总专家数 / 激活专家数) |
64 / 8 |
视觉专家(总专家数 / 激活专家数) |
64 / 8 |
上下文长度 |
131072 |
最佳实践
采样参数
为了达到最佳性能,我们建议使用 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, Day of the Week, Beijing/China”。
- {references} 是参考文章,推荐格式为:
##参考文章1
标题:周杰伦
文章发布时间:2025-04-20
内容:周杰伦(Jay Chou),1979年1月18日出生于台湾省新北市,祖籍福建省永春县,华语流行乐男歌手、音乐人、演员、导演、编剧,毕业于淡江中学。2000年,发行个人首张音乐专辑《Jay》。...
来源网站网址:baike.baidu.com
来源网站的网站名:百度百科
##参考文章2
...
📄 许可证
ERNIE 4.5 模型根据 Apache 许可证 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={}
}