本文档记录 deepset/tinyroberta-squad2 在 Ascend 910B3 NPU 环境下的适配与验证结果。该模型是一个基于 RoBERTa 的问答模型,在 SQuAD 2.0 数据集上微调,支持抽取式问答任务。
本仓库提供:
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.8.0 |
torch_npu | 2.8.0.post4 |
transformers | 4.57.6 |
Ascend 910B3,1 逻辑卡RobertaForQuestionAnswering(6 层,768 隐藏维,12 注意力头)384pip install torch torch_npu transformers
export ASCEND_RT_VISIBLE_DEVICES=0python inference.py \
--context "Einstein developed the theory of relativity." \
--question "What did Einstein develop?"# JSONL 格式: {"context": "...", "question": "..."}
python inference.py --input-file qa_pairs.jsonl{
"model": "tinyroberta-squad2",
"device": "npu:0",
"num_questions": 1,
"results": [
{
"question": "What did Einstein develop?",
"context": "Einstein developed the theory of relativity...",
"answer": "theory of relativity",
"confidence": 0.9542
}
]
}python inference.py --context "Python was created by Guido van Rossum." --question "Who created Python?"| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 0.9597 s | 0.0130 s |
| 吞吐量 | 8.34 q/s | 616.88 q/s |
| 加速比 | - | 73.82x |
精度评测采用答案区间(answer span)一致性和 logits 误差双指标。
| 指标 | 数值 |
|---|---|
| 测试问题数 | 8 |
| Max start abs error | 8.7323e-03 |
| Max end abs error | 1.0587e-02 |
| 答案区间一致率 | 8/8 (100.00%) |
| 错误率 | 0.00% |
| 精度要求(错误率 < 1%) | 通过 |
结论:NPU 与 CPU 的答案预测完全一致(100%),logits 误差极小,精度通过验证。