本文档记录 jinaai/jina-reranker-m0 在 Ascend NPU 环境上的适配部署与验证验证结果。
模型说明:jina-reranker-m0 是 Jina AI 发布的一款轻量级高性能多模态 Reranker 模型,基于 Qwen2-VL 架构,支持文本和图像查询/文档的重排序任务。约 2.6B 参数。
模型类型:JinaVLForRanking (Reranker)
相关获取地址:
| 组件 | 版本 |
|---|---|
PyTorch | 2.9.0+cpu |
torch_npu | 2.9.0.post1+gitee7ba04 |
transformers | 4.57.6 |
| Python | 3.11.14 |
Ascend910 x 2 逻辑卡/opt/atomgit/jinaai/jina-reranker-m0/model/jinaai/jina-reranker-m0bfloat16from transformers import AutoModel, AutoProcessor
import torch
model_path = "/path/to/jinaai/jina-reranker-m0"
device = "npu"
model = AutoModel.from_pretrained(
model_path,
dtype=torch.bfloat16,
trust_remote_code=True,
)
processor = AutoProcessor.from_pretrained(
model_path,
max_pixels=602112,
min_pixels=3136,
trust_remote_code=True,
)
model = model.to(device)注意:模型注册在 AutoModel 下(非 AutoModelForCausalLM),需设置 trust_remote_code=True。
# 输入查询-文档对
pairs = [
("What is the capital of France?", "Paris is the capital of France and its largest city."),
("What is the capital of France?", "London is the capital of the United Kingdom."),
]
scores = model.compute_score(
pairs,
batch_size=2,
max_length=2048,
max_query_length=128,
max_doc_length=512,
normalize_scores=True,
show_progress=True,
)
for pair, score in zip(pairs, scores):
q, d = pair
print(f"Score {score:.4f} | {d}")| 指标 | 数值 |
|---|---|
| 平均推理时间 (batch=4) | 36.39 ms |
| 吞吐量 | 109.92 pairs/s |
| Batch Size | 4 |
| 测试数据集 | 4 组 query-document 对 |
| 运行次数 | 5 次取平均 |
AutoModel.from_pretrained 加载(不是 AutoModelForCausalLM)compute_score 方法的参数需满足约束:max_doc_length + max_query_length <= max_lengthjinaai/jina-reranker-m0/
├── inference.py # 推理脚本
├── eval/
│ ├── accuracy_eval.py # 精度评测源代码
│ ├── accuracy_eval.log # 精度评测运行日志
│ ├── accuracy.json # 精度评测结果
│ ├── perf_eval.py # 性能评测源代码
│ ├── perf_eval.log # 性能评测运行日志
│ └── performance.json # 性能评测结果
└── verify_results.json # 验证结果汇总NPU vs CPU 精度对比(CPU 为基线,NPU 为验证目标):
| 指标 | 数值 |
|---|---|
| 测试用例数 | 2 |
| 预测一致性 | 2/2 (100.0%) |
| 精度要求 | NPU vs CPU 最大 logits 误差 < 1.0% |
| 精度结论 | ✅ 通过 (准确率 100.0%) |
精度评测源代码和日志详见 eval/ 目录。