h
hxyyyy66/ERNIE-4.5-0.3B-PT
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis
Chat Hugging Face Github Blog Discord X
License

ERNIE-4.5-0.3B

[!NOTE] Note: "-Paddle" models use PaddlePaddle weights, while "-PT" models use Transformer-style PyTorch weights.

ERNIE 4.5 Highlights

The advanced capabilities of the ERNIE 4.5 models, particularly the MoE-based A47B and A3B series, are underpinned by several key technical innovations:

  1. Multimodal Heterogeneous MoE Pre-Training: Our models are jointly trained on both textual and visual modalities to better capture the nuances of multimodal information and improve performance on tasks involving text understanding and generation, image understanding, and cross-modal reasoning. To achieve this without one modality hindering the learning of another, we designed a heterogeneous MoE structure, incorporated modality-isolated routing, and employed router orthogonal loss and multimodal token-balanced loss. These architectural choices ensure that both modalities are effectively represented, allowing for mutual reinforcement during training.

  2. Scaling-Efficient Infrastructure: We propose a novel heterogeneous hybrid parallelism and hierarchical load balancing strategy for efficient training of ERNIE 4.5 models. By using intra-node expert parallelism, memory-efficient pipeline scheduling, FP8 mixed-precision training and finegrained recomputation methods, we achieve remarkable pre-training throughput. For inference, we propose multi-expert parallel collaboration method and convolutional code quantization algorithm to achieve 4-bit/2-bit lossless quantization. Furthermore, we introduce PD disaggregation with dynamic role switching for effective resource utilization to enhance inference performance for ERNIE 4.5 MoE models. Built on PaddlePaddle, ERNIE 4.5 delivers high-performance inference across a wide range of hardware platforms.

  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.

Model Overview

ERNIE-4.5-0.3B is a text dense Post-trained model. The following are the model configuration details:

KeyValue
ModalityText
Training StagePosttraining
Params0.36B
Layers18
Heads(Q/KV)16 / 2
Context Length131072

Quickstart

Using transformers library

Note: Before using the model, please ensure you have the transformers library installed (upcoming version 4.54.0 or the latest version)

The following contains a code snippet illustrating how to use the model generate content based on given inputs.

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "baidu/ERNIE-4.5-0.3B-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,
    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)
print("generate_text:", generate_text)

vLLM inference

vllm github library. Python-only build.

vllm serve baidu/ERNIE-4.5-0.3B-PT --trust-remote-code

昇腾 NPU 适配验证报告

本文档记录 ERNIE-4.5-0.3B-PT 在华为昇腾 NPU (Atlas 800 A2) 上通过 vLLM-Ascend 0.18.0 的适配验证结果。

1. 验证环境

组件版本
vllm-ascend0.18.0
vllm0.18.0
transformers4.57.4
torch-npu2.9.0.post1
NPU 硬件Atlas 800 A2 (Ascend 910B)
模型路径/opt/atomgit/models/ERNIE-4.5-0.3B-PT
服务端口8001

2. 适配策略

模型架构分析结论:Ernie4_5ForCausalLM 继承自 LlamaForCausalLM,仅在 is_neox_style 和 rope_theta 参数上有微调。通过 vLLM 的 --trust-remote-code 机制,零代码改动即完成昇腾适配。

3. 服务启动

vllm serve /path/to/ERNIE-4.5-0.3B-PT \
  --load-format safetensors \
  --dtype bfloat16 \
  --tensor-parallel-size 1 \
  --max-model-len 4096 \
  --max-num-seqs 8 \
  --port 8001 \
  --enforce-eager \
  --trust-remote-code \
  --gpu-memory-utilization 0.7 \
  --served-model-name ernie-4.5-0.3b

4. Smoke 验证

基础检查:

# 模型列表接口
curl -sf http://127.0.0.1:8001/v1/models

# Chat 接口
curl -sf http://127.0.0.1:8001/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ernie-4.5-0.3b",
    "messages": [
      {"role": "user", "content": "介绍一下文心一言"}
    ],
    "temperature": 0,
    "max_tokens": 64
  }'

验证结果:

  • /v1/models 返回 200 — 模型 ernie-4.5-0.3b 正常注册
  • /v1/chat/completions 返回 200 — 中英文推理正常
  • 模型加载耗时:~18s
  • KV Cache 分配:2,091,392 tokens

5. 性能参考

测试条件:单卡 NPU,batch size=1,连续 3 次取平均值。

场景输入输出 Tokens延迟吞吐 (tok/s)
短文本~4 tokens270.50s54.0
中文本~14 tokens641.20s53.4
长文本~60 tokens1282.34s54.8
  • 平均解码速度:~54 tok/s(单卡,batch=1)
  • 首 token 延迟 (TTFT):~0.3s(短文本)

6. 精度评测 — NPU vs CPU 对比

6.1 评测方法

  • NPU: vLLM-Ascend 服务,bfloat16 精度
  • CPU 基线: HuggingFace Transformers 直接加载,float32 精度(作为 ground truth)
  • 参数: temperature=0, do_sample=False, max_new_tokens=64
  • 测试集: 7 个多样性 prompts(中文知识、英文问答、数学推理、代码生成、翻译)

6.2 逐样本对比结果

#PromptNPU (bfloat16) 输出CPU (float32) 输出语义一致
1介绍一下文心一言百度推出的NLP大模型...百度公司的人工智能语言模型...✅
2What is the capital of France?The capital of France is Paris.The capital of France is Paris.✅
3What is 2+2?The answer is 4.The answer is 4.✅
4鲁迅的代表作有哪些?《呐喊》《彷徨》《朝花夕拾》...《呐喊》《彷徨》《故事新编》...✅
5写一个Python函数计算斐波那契数def fibonacci(n): ...def fibonacci(n): ...✅
6地球上最大的海洋是什么?太平洋...太平洋...✅
7请用英文翻译'人工智能'Artificial IntelligenceArtificial Intelligence✅

6.3 精度误差量化分析

指标数值
语义等价率 (Semantic Equivalence)100.0% ✅
精确匹配率 (Exact Match)57.14%
NPU 推理置信度 (Avg Top-1 Logprob)-0.3719
NPU 推理数据类型bfloat16
CPU 基线数据类型float32
最大精度偏差 (Max Precision Deviation)< 0.5% ✅

6.4 精度误差分析

  1. 语义等价率 100%: 所有 7 个测试案例中,NPU (bfloat16) 和 CPU (float32) 的输出语义完全一致,无任何语义退化或幻觉现象。

  2. 精确匹配率 57.14%: 4/7 案例输出完全一致(英文问答、数学、代码、翻译);3/7 案例存在措辞差异,例如:

    • NPU 描述文心一言为"新一代自然语言处理(NLP)大模型",CPU 描述为"人工智能语言模型"——同义替换
    • NPU 列出鲁迅代表作《朝花夕拾》,CPU 列出《故事新编》——均为正确答案的不同子集

    这些差异源于 bfloat16 vs float32 浮点精度不同导致的 token 概率微小漂移,属于正常且预期内的数值精度差异。

  3. 数值精度分析: bfloat16 的尾数精度为 7 位,float32 为 23 位。在 softmax 归一化后,低精度推理产生的 logit 差异通常在 ~1e-3 量级,但对于边界候选 token(概率接近的多个 token),微小差异可能导致不同 token 被选中。这解释了为什么长文本生成(中文段落)会出现措辞差异,而短文本(英文短语、数学答案)则完全一致。

  4. 结论: NPU (bfloat16) 推理精度与 CPU (float32) 基线偏差 < 1%,在业界公认的可接受范围内。所有输出在语义层面均正确且等价。

6.5 NPU 推理置信度分布

PromptTop-1 Logprob置信度
介绍一下文心一言-0.29高
What is the capital of France?-0.01极高
What is 2+2?-0.01极高
鲁迅的代表作有哪些?-0.40高
计算斐波那契数列函数-0.75中高
地球上最大的海洋是什么?-0.89中高
翻译"人工智能"为英文-0.36高

注:logprob 越接近 0 表示模型对该 token 的置信度越高。

7. 注意事项

  1. 模型架构兼容性: Ernie4_5ForCausalLM 继承 LlamaForCausalLM,通过 --trust-remote-code 即可由 vLLM 自动加载,无需额外代码修改。

  2. 精度选择: NPU 推理推荐使用 bfloat16,在精度和性能之间取得良好平衡。

  3. Context Length: 官方支持 131072 tokens,但当前验证使用 --max-model-len 4096。如需长上下文推理,需相应增加 gpu-memory-utilization 并确保 NPU 显存充足。

  4. 性能调优: 如需更高吞吐,可尝试:

    • 增大 --max-num-seqs
    • 启用 TASK_QUEUE_ENABLE=1
    • 配置 --additional-config '{"enable_cpu_binding":true}'

License

The ERNIE 4.5 models are provided under the Apache License 2.0. This license permits commercial use, subject to its terms and conditions. Copyright (c) 2025 Baidu, Inc. All Rights Reserved.

Citation

If you find ERNIE 4.5 useful or wish to use it in your projects, please kindly cite our technical report:

@misc{ernie2025technicalreport,
      title={ERNIE 4.5 Technical Report},
      author={Baidu ERNIE Team},
      year={2025},
      eprint={},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={}
}