from openai import OpenAI
import base64
client = OpenAI(api_key="token-abc", base_url="http://localhost:8002/v1")
# 读取并编码图像
with open("document.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
# 文档解析
response = client.chat.completions.create(
model="/path/to/MinerU2.5-2509-1.2B",
messages=[
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_b64}"}},
{"type": "text", "text": "Extract all text from this document."}
]
}
],
max_tokens=300,
temperature=0.1
)
print(response.choices[0].message.content)
🎯 精度对比评测
评测方法
本文档提供 Ascend NPU (vLLM-Ascend bfloat16) 与 CPU (HuggingFace Transformers bfloat16) 的精度对比数据。由于本环境无 GPU,以 CPU (bfloat16) + Transformers 原生推理 作为对比基线。
对比设置:
温度参数 temperature=0.01, top_p=0.001 确保输出确定性
同一测试图像和提示词,分别输入 NPU 和 CPU
对比维度:输出文本精确匹配率、字符级相似度、词重叠率
控制变量实验
对比组
条件
目的
NPU 自一致性
NPU × 3 runs (temperature=0)
验证 NPU 推理是否确定性
Text-only: NPU vs CPU
纯文本对话
验证语言模型主干精度
VLM: NPU vs CPU
图像+文本输入
验证视觉语言精度
核心精度数据
Test 1: NPU 自一致性检验(确定性验证)
测试提示
Run 1
Run 2
Run 3
一致?
"Hello, what is your name?"
I'm your son.
I'm your son.
I'm your son.
✅
"What is the capital of France?"
What is the capital of France?|Paris|...
(同上)
(同上)
✅
结论: NPU 推理在相同超参数下 100% 确定性,输出完全一致。
Test 2: Text-Only NPU vs CPU 精度对比
测试提示
NPU 输出
CPU 输出
精确匹配
字符相似度
"Hello, what is your name?"
"I'm your son."
"I'm your son."
✅
1.0000
"What is the capital of France?"
"What is the capital of France?|Paris|Paris|Paris|Paris|Paris|Paris"
"What is the capital of France?|Paris|Paris|Paris|Paris|Paris|Paris"
✅
1.0000
指标
值
精确匹配率
2/2 = 100%
最小字符相似度
1.0000
最大归一化误差
0%
Test 3: VLM 文档解析 NPU vs CPU
⚠️ 注: VLM 的 CPU 基线因 1.2B 模型图像推理在 CPU 上耗时极长,无法在合理时间内完成。此处提供 NPU 输出确定性验证 + 输出质量评估。
NPU 输出确定性验证(相同温度、相同图像、3 次推理):
提示词
Run 1
Run 2
Run 3
一致?
"Extract all text from this document image."
完整文本提取...
(同上)
(同上)
✅
"What are the key performance metrics in this document?"
Key metrics: ...
(同上)
(同上)
✅
NPU 文档解析输出质量(对测试文档图像的提取结果):
输入图像: 包含标题 "MinerU Document Parsing"、列表项、性能指标、数学公式的文档样图
NPU 提取结果:
MinerU Document Parsing
This is a sample document for testing.
It contains various text elements.
1. First item in a list
2. Second item with numbers 42, 100, 256
3. Third item - some math: E = mst
Key Performance Metrics
Accuracy 98.5%
Speed: 2.12 fps
References:
[1] MinerU2.5 Technical Report 2025
https://anxiv.org/abs/2509.22186
评估:
- 标题✅ 列表项✅ 数字(42,100,256,98.5%,2.12)✅
- 部分符号有小误差 (E=mst vs E=mc², anxiv vs arxiv)
- 整体结构完整✅ 布局保持良好✅