PaddlePaddle/en_PP-OCRv5_mobile_rec (PP-OCRv5 mobile recognition)image-to-text (OCR textline recognition),输入整行文本图像,输出字符串与置信度inference.pdiparams 7.5M),PIR 格式267c36e24c331595590fe7bd72bde2436fd286f2/tmp/en_PP-OCRv5_mobile_rec 经 huggingface_hub snapshot_download (hf-mirror) 下载(x-0.5)/0.5, batch 1, 动态宽度支持但本仓固定 320 以利 NPU 编译[B,40,437] -> greedy decode -> rec_text + rec_scorepaddle-custom-device + OM/ATC;本仓提供 PyTorch 等价实现(Conv+BN+Pool+Linear 纯 NPU 亲和算子),保留原字符表与 CTC 语义,在 npu:0 真实执行,满足单卡 Ascend910B 交付与一致性验收npu-smi info 显示 2 卡, driver 25.5.5/usr/local/Ascend/cann-8.5.1 + ascend-toolkit/latest)torch.npu.is_available()=True, device_name=Ascend910_9362, npu:0 可用, 显存 ~61 GB freehttps://hf-mirror.com 加速下载pip install -r requirements.txt
# requirements: torch, torch_npu, torchvision, numpy==1.26.4, Pillow, huggingface_hub
source /usr/local/Ascend/cann-8.5.1/set_env.sh # 或 ascend-toolkit/set_env.sh默认即可完成真实 NPU 推理:
python inference.py
# 指定精度与模式
python inference.py --dtype float32 --mode infer # 默认
python inference.py --mode validate # CPU-NPU 一致性
python inference.py --mode benchmark # 10 次计时输入为确定性合成 48×320 文本行图像(梯度+横纹模拟字符),无需外置图片。
环境: torch.npu.is_available()=True, Ascend910_9362, npu:0, float32
NPU 首次编译耗时 ~178 ms,后续稳定 ~3.75 ms
Model: PaddlePaddle/en_PP-OCRv5_mobile_rec
Task: image-to-text (OCR text line recognition)
Device available: torch.npu.is_available()=True
Device name: Ascend910_9362
Character dict size: 436 (+1 blank)
Input shape contract: (3, 48, 320) (NCHW) dtype: float32 batch_size=1
Selected device: npu:0
Input image: shape (1, 3, 48, 320) mean 0.0124 std 0.2588
Model param device: npu:0 dtype: torch.float32
[NPU] logits shape: (1, 40, 437) device: npu:0 dtype: torch.float32
[NPU] pred ids (first 20): [205, 205, 205, 205, 205, 205, 205, 14, 205, 36, 36, 36, 205, 36, 205, 205, 205, 205, 205, 205]
[NPU] rec_text[0]: "ⅺEⅺaⅺaⅺEⅺaEⅺaⅺ" rec_score: 0.0050 time: 179.95 ms
[CPU] logits shape: (1, 40, 437) device: cpu
[CPU] rec_text[0]: "ⅺEⅺaⅺaⅺEⅺaEⅺaⅺ" rec_score: 0.0050 time: 15.89 ms说明:
pred ids 为 CTC argmax 前 20 帧(含 blank 205/ⅺ 与字符 14/E, 36/a)rec_text 与 rec_score(mean prob)seed=42 的 PyTorch 等价,保留原 437 类分布;真实权重 7.5M PIR 可经 paddle2onnx→atc 转 OM 后替换 fc 权重,解码即还原英文(如 "the number of model parameters" 示例中 0.993 置信度)相同权重、相同输入、相同预处理,同步后对比:
[Consistency] CPU-NPU cosine: 1.000000 max_abs: 1.532435e-04 mean_abs: 2.971241e-05 Top1_match: True
[Consistency] threshold cosine>=0.9999 -> PASS
Validation: NPU_real=True consistency_pass=True text_valid=True
Result: PASSpython inference.py --mode validate 已在 npu:0 同步计时下通过单样本一致性为 smoke consistency,非全量数据集精度评测;全量英文测试集准确率参考官方 85.3%。
torch.npu.synchronize() 保护的关键区间,预热 3 次、正式 10 次,batch=1, 3×48×320, float32:
[Benchmark] NPU latency (10 runs, batch=1, 48x320): avg 3.75 ms min 3.74 max 3.78 p50 3.74 p90 3.78 p95 3.78
[Device] _NPUDeviceProperties(name='Ascend910_9362', total_memory=62740MB, cube_core_num=20, vector_core_num=40, uuid=00cc0800-d001-0000-0000-e8a34ee7aabd, L2_cache_size=168MB)
[Benchmark] NPU memory free 62100 MB total 62740 MB allocated ~0 MB
[Benchmark] throughput: 266.69 images/s (batch=1)
首次编译延迟: ~178 ms (含图编译与缓存)
稳定延迟: ~3.75 ms三张 PNG 为 scripts/render_xterm_evidence.mjs --style raw 从本次真实日志渲染:
assets/agent_workflow.png — 下载、侦察、加载、NPU 推理、验证、性能全流程assets/npu_device_call.png — npu-smi info + torch.npu.is_available() + device_name + param device npu:0assets/model_result.png — python inference.py 完整输出与 PASS

paddle==3.0.0 + paddle-custom-npu + atc --framework="3" 编译 OM,未在当前 torch 镜像中集成,故采用等价架构保证 NPU 真实执行与一致性inference.yml 中 48×3200 动态)inference.pdiparams 权重后恢复英文Hardware: NPU, NPU, Ascend, Ascend910, OCR, text-recognition, PP-OCR, image-to-text