kha-white/manga-ocr-basefacebook/deit-base-patch16-224 + Bert Japanese decoder cl-tohoku/bert-base-japanese-char-v2)torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362, 验证设备 npu:0model_cache/kha-white-manga-ocr-base (本地已缓存,未依赖运行时隐式下载)pip install torch torch_npu transformers Pillow fugashi unidic_lite numpy
# 或
pip install -r requirements.txt# 默认推理 (NPU:0, float32, 单图 224x224)
python inference.py
# CPU-NPU 一致性验证
python inference.py --mode validate
# 性能测试 (warmup 3 + 10次同步计时)
python inference.py --mode benchmark默认输入为代码内合成的确定性 224x224 图像 (白色背景 + 黑色边框 + "test 123" 文字 + 斜线纹理),保证无外部文件依赖且可复现。
以下为本次在 npu:0 上的真实输出 (来自 python inference.py, logs/inference.log):
model_name: kha-white/manga-ocr-base
model_dir: /opt/.../workspace/model_cache/kha-white-manga-ocr-base
task_type: image-to-text (OCR)
architecture: VisionEncoderDecoderModel (ViT + BertJapanese)
device: npu:0 (npu_available=True, device_name=Ascend910_9362)
requested_dtype: float32
loading_backend: transformers VisionEncoderDecoderModel
processor: ViTImageProcessor size=224x224
tokenizer: BertJapaneseTokenizer vocab=6144
model param device: npu:0 dtype: torch.float32
input_contract: PIL RGB (224,224) -> pixel_values [1,3,224,224] float32 normalized(mean=0.5,std=0.5)
pixel_values shape: (1, 3, 224, 224) device: npu:0 dtype: torch.float32
generated_ids: [2, 2, 28, 28, 28, 3]
generated_text: '. . .'
output_contract: ids (1, 6) -> text string length 5
inference latency: 292.37 ms (synchronized, 首次含编译)
Final status: PASSmodel param device: npu:0, pixel_values device: npu:0, generate ids device: npu:0, torch.npu.synchronize() 前后计时python inference.py 默认即完成 NPU 推理并打印上述信息,退出码 0执行 python inference.py --mode validate:
CPU generated_ids: [2, 2, 28, 28, 28, 3]
CPU text: '. . .'
NPU generated_ids: [2, 2, 28, 28, 28, 3]
NPU text: '. . .'
ids_match: True
text_match: True
CPU-NPU consistency: PASS (ids identical)
[VALIDATE] PASS执行 python inference.py --mode benchmark (warmup 3次 + 正式10次, 每次前后 torch.npu.synchronize()):
benchmark results (10 runs, batch=1, 224x224, float32, npu:0):
avg=23.06 ms min=22.61 ms max=23.99 ms p50=22.79 ms p90=23.92 ms p95=23.96 ms
NPU memory free/total: 64801976320/65787658240 (if available)
throughput: 43.36 images/s (single stream)
首次延迟 (含图编译): ~292 ms
稳态延迟 (warmup后): 23.06 ms avgassets/agent_workflow.png: 下载/侦察/加载/NPU推理/验证/性能全流程日志assets/npu_device_call.png: npu-smi info + torch.npu.is_available() + 设备名 + 模型参数device/dtype + pixel_values/generate deviceassets/model_result.png: python inference.py 完整输出 (任务结果 + 计时 + PASS/FAIL)三图由 scripts/render_xterm_evidence.mjs 从本次真实日志渲染 (raw模式),显示原始命令、退出码、UTC时间与日志SHA256。
fugashi + unidic_lite 以支持 BertJapaneseTokenizer 的 Mecab 分词,缺失时会报错model.half() 但需重新验证一致性Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, VisionEncoderDecoder, OCR, manga-ocr, Japanese, image-to-text