飞桨PaddlePaddle/ERNIE-4.5-300B-A47B-Paddle
模型介绍文件和版本Pull Requests讨论分析
下载使用量0
Chat Hugging Face Github Blog
License

ERNIE-4.5-300B-A47B

ERNIE 4.5 亮点

ERNIE 4.5 模型的先进能力,特别是基于 MoE 的 A47B 和 A3B 系列模型,得益于以下关键技术创新:

  1. 多模态异构 MoE 预训练: 我们的模型在文本和视觉两种模态上联合训练,更好地捕捉多模态信息的细微差异,并提升在涉及文本理解与生成、图像理解以及跨模态推理的任务上的性能。为此,我们设计了 异构 MoE 结构,引入了 模态隔离路由 并应用了 路由正交损失 和 多模态 Token 平衡损失。这些架构选择确保了两种模态都得到有效表征,使得在训练过程中能够相互增强。

  2. 扩展效率化基础设施: 我们提出了用于 ERNIE 4.5 模型高效训练的新型异构混合并行和分层负载平衡策略。通过使用节点内专家并行、内存高效管道调度、FP8 混合精度训练和细粒度重计算方法,我们实现了显著的预训练吞吐量。在推理方面,我们提出了 多专家并行协作 方法和 卷积码量化 算法以实现 4 位/2 位无损量化。此外,我们引入了基于动态角色切换的 PD 解聚,有效利用资源来增强 ERNIE 4.5 MoE 模型的推理性能。建立在 PaddlePaddle 之上的 ERNIE 4.5 在多种硬件平台上提供高性能推理。

  3. 模态特定后训练: 为了满足实际应用的多样化需求,我们对预训练模型的不同模态变体进行了微调。我们的 LLM 模型针对通用语言理解和生成进行了优化,而 VLM 模型则专注于视觉语言理解,并支持思考和和非思考模式。每个模型在后续训练中采用了 监督微调(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 进行模型微调

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 快速完成服务部署。关于更详细的用法说明,请参考 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 正在适配中,建议优先使用我们分叉的仓库 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}'''

参数说明:

  • {question} 是用户的提问
  • {date} 为当前时间,建议格式为“YYYY-MM-DD HH:MM:SS,星期几,北京/中国。”
  • {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={}
}