TCFY7/BitCPM4-0.5B
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

GitHub Repo | Technical Report

👋 Join us on Discord and WeChat

What's New

  • [2025.06.06] MiniCPM4 series are released! This model achieves ultimate efficiency improvements while maintaining optimal performance at the same scale!
  • [2025.06] Ascend NPU Adaptation — BitCPM4-0.5B validated on Huawei Ascend 910B2 NPU via vLLM-Ascend, achieving 100% top-1 token accuracy and <1% probability error vs CPU reference.

MiniCPM4 Series

MiniCPM4 series are highly efficient large language models (LLMs) designed explicitly for end-side devices, which achieves this efficiency through systematic innovation in four key dimensions: model architecture, training data, training algorithms, and inference systems.

  • MiniCPM4-8B: The flagship of MiniCPM4, with 8B parameters, trained on 8T tokens.
  • MiniCPM4-0.5B: The small version of MiniCPM4, with 0.5B parameters, trained on 1T tokens.
  • MiniCPM4-8B-Eagle-FRSpec: Eagle head for FRSpec, accelerating speculative inference for MiniCPM4-8B.
  • MiniCPM4-8B-Eagle-FRSpec-QAT-cpmcu: Eagle head trained with QAT for FRSpec, efficiently integrate speculation and quantization to achieve ultra acceleration for MiniCPM4-8B.
  • MiniCPM4-8B-Eagle-vLLM: Eagle head in vLLM format, accelerating speculative inference for MiniCPM4-8B.
  • MiniCPM4-8B-marlin-Eagle-vLLM: Quantized Eagle head for vLLM format, accelerating speculative inference for MiniCPM4-8B.
  • BitCPM4-0.5B: Extreme ternary quantization applied to MiniCPM4-0.5B compresses model parameters into ternary values. (⬅ you are here)
  • BitCPM4-1B: Extreme ternary quantization applied to MiniCPM3-1B.
  • MiniCPM4-Survey: Based on MiniCPM4-8B, autonomously generates trustworthy, long-form survey papers.
  • MiniCPM4-MCP: Based on MiniCPM4-8B, autonomously calls relevant MCP tools.

Introduction

BitCPM4 are ternary quantized models derived from the MiniCPM series models through quantization-aware training (QAT), achieving significant improvements in both training efficiency and model parameter efficiency.

  • Improvements of the training method
    • Searching hyperparameters with a wind-tunnel on a small model.
    • Using a two-stage training method: training in high-precision first and then QAT.
  • High parameter efficiency
    • Achieving comparable performance to full-precision models of similar parameter models with a bit width of only 1.58 bits.

Usage

Inference with Transformers

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

path = "openbmb/BitCPM4-0.5B"
device = "cuda"

tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)

messages = [
    {"role": "user", "content": "推荐5个北京的景点。"},
]
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)

model_outputs = model.generate(
    model_inputs,
    max_new_tokens=1024,
    top_p=0.7,
    temperature=0.7
)

output_token_ids = [
    model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))
]

responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
print(responses)

Inference with vLLM-Ascend (Huawei Ascend NPU)

from vllm import LLM, SamplingParams

llm = LLM(
    model="openbmb/BitCPM4-0.5B",  # or local path
    max_model_len=1024,
    gpu_memory_utilization=0.7,
    enforce_eager=True,
    trust_remote_code=True,
)

sampling_params = SamplingParams(max_tokens=128, temperature=0.7)
outputs = llm.generate(["What is artificial intelligence?"], sampling_params)
print(outputs[0].outputs[0].text)

Evaluation Results (Original)

BitCPM4's performance is comparable with other full-precision models in same model size. Benchmark of BitCPM


Ascend NPU 适配与评测报告

本部分针对 BitCPM4-0.5B 在华为昇腾 Ascend 910B2 NPU 上通过 vLLM-Ascend 进行推理的适配验证与性能评估。

环境信息

项目规格
硬件
NPU 型号Ascend910_9362
NPU 数量2
NPU 显存61.3 GiB/卡
CPUaarch64, 40 核
系统内存229.4 GiB
软件
OSLinux 5.10.0 (HCE 2.0)
Python3.11.14
PyTorch2.9.0+cpu
torch_npu2.9.0.post1
vLLM0.18.0
vLLM-Ascend0.18.0rc1
CANN8.5.1
transformers4.57.6

模型配置

参数值说明
架构MiniCPMForCausalLMvLLM 原生支持
参数量433.9M (0.5B)
hidden_size1024
num_hidden_layers24
num_attention_heads16
num_key_value_heads2GQA (压缩比 8:1)
intermediate_size4096
max_position_embeddings32768LongRoPE 缩放
vocab_size73448
torch_dtypebfloat16
权重精度BF16
权重文件大小867 MB1 个 safetensors 分片

适配结论

✅ 零代码修改,完全适配成功

BitCPM4-0.5B 使用 MiniCPMForCausalLM 架构,该架构已被 vLLM 和 vLLM-Ascend 原生支持。所有 MiniCPM 特有参数(scale_emb、scale_depth、dim_model_base、longrope RoPE 缩放等)均被正确解析。

精度评测

评测方法

以 CPU (PyTorch transformers + float32) 推理结果为参考基线,对比 NPU (vLLM-Ascend + bfloat16) 推理结果的 top-k token 预测概率。使用 7 组不同主题的测试 prompt,分别采集 CPU 和 NPU 的 next-token 预测分布进行逐项比对。

精度对比表

PromptCPU Top-1 TokenCPU ProbNPU Top-1 TokenNPU ProbTop-1 概率误差Top-10 重合度
The capital of France isa0.3537a0.35240.38%10/10 ✅
Einstein is known forhis0.7679his0.76410.49%10/10 ✅
Quantum computing isa0.7091a0.70510.57%10/10 ✅
The meaning of life isa0.9718a0.97220.04%10/10 ✅
Machine learning is asubset0.4118subset0.39633.76%10/10 ✅
Python is a programminglanguage0.9973language0.99700.03%10/10 ✅
Natural language processing(0.6236(0.62710.57%10/10 ✅

精度评测汇总

指标值
Top-1 Token 匹配率100% (7/7) ✅
Top-5 Token 包含率100% (7/7) ✅
Top-10 Token 重合度100% (平均 10.0/10) ✅
Top-1 概率平均相对误差0.84% ✅ (< 1%)
Top-1 概率最大相对误差3.76% (Prompt: "Machine learning is a")
Top-10 概率平均绝对误差 (MAE)0.00114
Top-10 概率最大绝对误差0.01550
Top-10 概率均方根误差 (RMSE)0.00283

结论: NPU (bfloat16) 输出与 CPU (float32) 参考的 Top-1 预测完全一致,概率平均误差 0.84%,远低于 1% 的精度偏差阈值。极个别 prompt 的 top-1 概率误差达到 3.76%,但这是因为 CPU top-1 概率本身较低(subset 0.41 vs NPU 0.40),绝对差值仅 0.0155,不影响最终 token 选择。整体精度完全满足生产部署要求。

Top-10 概率分布对比 (CPU vs NPU)

Prompt: "The capital of France is"
Rank | CPU Token   | CPU Prob | NPU Token   | NPU Prob | Match
-----|-------------|----------|-------------|----------|------
1    | 'a'         | 0.353706 | 'a'         | 0.352359 | ✅
2    | 'Paris'     | 0.275060 | 'Paris'     | 0.274417 | ✅
3    | 'known'     | 0.052770 | 'known'     | 0.054036 | ✅
4    | 'the'       | 0.034749 | 'the'       | 0.032774 | ✅
5    | 'not'       | 0.021897 | 'not'       | 0.022526 | ✅
6    | 'named'     | 0.018752 | 'located'   | 0.018674 | 
7    | 'located'   | 0.018359 | 'named'     | 0.018674 | 
8    | 'widely'    | 0.014278 | 'widely'    | 0.014544 | ✅
9    | 'an'        | 0.013214 | 'an'        | 0.013662 | ✅
10   | 'held'      | 0.012054 | 'held'      | 0.012835 | ✅

性能评测

吞吐量测试 (Batch=10)

max_tokens总耗时Input 吞吐Output 吞吐
321.07s59.6 tok/s298.2 tok/s
641.95s32.8 tok/s316.3 tok/s
1283.81s16.8 tok/s336.4 tok/s

单请求延迟 (max_tokens=128)

指标值
Input tokens11
Output tokens128
总耗时3.67s
生成吞吐34.8 tok/s

长上下文测试 (252 input tokens)

指标值
Prefill 吞吐~4273 tok/s
Decode 延迟~59ms/token

显存使用

指标值
模型加载时间0.33s
模型权重显存0.82 GiB
KV Cache 容量41.78 GiB
最大并发 (1024 tokens/req)3565×
Engine 初始化时间3.67s
总 NPU 显存占用43.29 GiB / 61.27 GiB

典型生成示例

示例 1

Input: "What is artificial intelligence?" Output:

Artificial intelligence (AI) is the simulation of human intelligence processes by computer systems. These processes include learning (the acquisition of information and rules for using the information), reasoning (using rules to reach approximate or definite conclusions) and self-correction.

示例 2

Input: "请用中文简单介绍一下你自己。" Output:

我是 MiniCPM4,一个高效的语言模型,可以在各种设备上...


Statement

  • As a language model, MiniCPM generates content by learning from a vast amount of text.
  • However, it does not possess the ability to comprehend or express personal opinions or value judgments.
  • Any content generated by MiniCPM does not represent the viewpoints or positions of the model developers.
  • Therefore, when using content generated by MiniCPM, users should take full responsibility for evaluating and verifying it on their own.

LICENSE

  • This repository and MiniCPM models are released under the Apache-2.0 License.

Citation

  • Please cite our paper if you find our work valuable.
@article{minicpm4,
  title={{MiniCPM4}: Ultra-Efficient LLMs on End Devices},
  author={MiniCPM Team},
  year={2025}
}