ERNIE 4.5 模型的先进能力,特别是基于 MoE 的 A47B 和 A3B 系列,得益于以下关键技术革新:
多模态异构 MoE 预训练: 我们的模型在文本和视觉模态上进行联合训练,以更好地捕捉多模态信息的细微差异,并提高涉及文本理解与生成、图像理解以及跨模态推理的任务性能。为了实现这一点,不让一个模态阻碍另一个模态的学习,我们设计了 异构 MoE 结构,引入了 模态隔离路由,并采用了 路由正交损失 和 多模态 Token 平衡损失。这些架构选择确保了两种模态的有效表示,并在训练过程中实现相互强化。
缩放效率化基础设施: 我们为 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 后训练模型,总参数量为 300B,每个 Token 激活的参数量为 47B。以下为模型的配置细节:
| 关键字 | 值 |
|---|---|
| 模态 | 文本 |
| 训练阶段 | 预训练 |
| 参数量(总/激活) | 300B / 47B |
| 层数 | 54 |
| 头数(Q/KV) | 64 / 8 |
| 文本专家数(总/激活) | 64 / 8 |
| 视觉专家数(总/激活) | 64 / 8 |
| 上下文长度 | 131072 |
ERNIEKit 是基于 PaddlePaddle 的训练工具包,专门为 ERNIE 系列开源大型模型设计。它为指令微调(SFT、LoRA)和排列训练(DPO)等场景提供全面支持,确保最优性能。
使用示例:
# Download model
huggingface-cli download baidu/ERNIE-4.5-300B-A47B-Paddle --local-dir baidu/ERNIE-4.5-300B-A47B-Paddle
# SFT
erniekit train examples/configs/ERNIE-4.5-300B-A47B/sft/run_sft_wint8mix_lora_8k.yaml
# DPO
erniekit train examples/configs/ERNIE-4.5-300B-A47B/dpo/run_dpo_wint8mix_lora_8k.yaml以下是更为详细的示例,包括带有 LoRA 的 SFT、多 GPU 配置以及高级脚本,请参考 ERNIEKit 存储库中的示例文件夹。
通过以下命令使用 FastDeploy 可以快速完成服务部署。关于更详细的用法说明,请参阅 FastDeploy 存储库。
注意:若要在配备至少 80G 内存、共 4 块 GPU 的配置上进行部署,请指定 --quantization wint4。如果您指定 --quantization wint8,则需要 8 块 GPU 的资源。
python -m fastdeploy.entrypoints.openai.api_server \
--model baidu/ERNIE-4.5-300B-A47B-Paddle \
--port 8180 \
--metrics-port 8181 \
--quantization wint4 \
--tensor-parallel-size 8 \
--engine-worker-queue-port 8182 \
--max-model-len 32768 \
--max-num-seqs 32要使用 FastDeploy 部署 W4A8C8 量化版本,您可以运行以下命令。
python -m fastdeploy.entrypoints.openai.api_server \
--model baidu/ERNIE-4.5-300B-A47B-W4A8C8-TP4-Paddle \
--port 8180 \
--metrics-port 8181 \
--engine-worker-queue-port 8182 \
--tensor-parallel-size 4 \
--max-model-len 32768 \
--max-num-seqs 32要在单块141G GPU上使用FastDeploy部署WINT2量化版本,您可以执行以下命令。
python -m fastdeploy.entrypoints.openai.api_server \
--model "baidu/ERNIE-4.5-300B-A47B-2Bits-Paddle" \
--port 8180 \
--metrics-port 8181 \
--engine-worker-queue-port 8182 \
--tensor-parallel-size 1 \
--max-model-len 32768 \
--max-num-seqs 128以下是一个代码片段,展示了如何使用 ERNIE-4.5-300B-A47B-FP8 根据给定输入生成内容。
from fastdeploy import LLM, SamplingParams
prompts = [
"Hello, my name is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=128)
model = "baidu/ERNIE-4.5-300B-A47B-FP8-Paddle"
llm = LLM(model=model, tensor_parallel_size=8, max_model_len=8192, num_gpu_blocks_override=1024, engine_worker_queue_port=9981)
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs.text
print("generated_text", generated_text)transformers 库以下是一个代码示例,展示了如何根据给定的输入使用模型生成内容。
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, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
# 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。我们正在与社区合作,全面支持 ERNIE4.5 模型,敬请期待。
# 80G * 16 GPU
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code# FP8 online quantification 80G * 8 GPU
vllm serve baidu/ERNIE-4.5-300B-A47B-PT --trust-remote-code --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}'''参数说明:
##参考文章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={}
}