Repository navigation
Description
bug描述 Describe the Bug
Paddle Inference 3.3.1 OneDNN 执行时 ConvertPirAttribute2RuntimeAttribute 不支持 ArrayAttribute
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
基本信息
• PaddlePaddle 版本: 3.3.1(预编译 Windows x64 CPU 推理库)
• 操作系统: Windows 10/11
• 编译环境: MSVC 2019/2022
• 硬件: x86-64 CPU
• 问题类型: 推理运行时错误
• 模型格式: PIR (Paddle IR) v3
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
错误信息
│ C++ Traceback (most recent call last):
│ --------------------------------------
│ Not support stack backtrace yet.
│
│ Error Message Summary:
│ ----------------------
│ UnimplementedError: ConvertPirAttribute2RuntimeAttribute not support [pir::ArrayAttributepir::DoubleAttribute]
│ (at paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc:118)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
复现步骤
- 下载 Paddle Inference 3.3.1 Windows CPU 版本: https://paddle-inference-lib.bj.bcebos.com/3.3.1/cxx_c/Windows/CPU/x86-64_avx-mkl-vs2019/paddle_inference.zip
- 加载 PP-OCRv6 系列模型(或其他使用 PIR 格式的模型),启用 MKLDNN(OneDNN)
- 执行推理,即触发该错误
关键代码:
│ // 启用 MKLDNN 时触发
│ config.EnableMKLDNN();
│ config.EnableMkldnnBfloat16(); // 或仅 EnableMKLDNN()
│
│ // 执行推理时抛出异常
│ predictor_->Run();
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
根因分析
在 paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc 的 ConvertPirAttribute2RuntimeAttribute 函数中,switch
分支完整地处理了以下数组类型:
• ArrayAttribute ✅
• ArrayAttribute ✅
• ArrayAttribute ✅
但缺少 ArrayAttribute 的处理分支(第 105 行附近),导致当模型算子中包含 DoubleAttribute 类型的数组属性时,直接抛出 UnimplementedError。
具体触发场景: PP-OCRv6 等 PIR 格式模型的 full 算子(创建常量张量)使用了 f64 类型的属性值 1.0,在 OneDNN 执行路径中,该属性被封装为
ArrayAttribute 传递给转换函数,未被识别。
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
修复建议
在 onednn_instruction.cc 的 ArrayAttribute 分支之后,IntArrayAttribute 分支之前,添加以下代码:
│ } else if (attr_type_name == "pir::ArrayAttributepir::DoubleAttribute") {
│ auto array_list = attr.dyn_castpir::ArrayAttribute().AsVector();
│ std::vector vec_res;
│ if (array_list.size() > 0) {
│ if (array_list[0].isapir::DoubleAttribute()) {
│ for (size_t i = 0; i < array_list.size(); ++i) {
│ vec_res.push_back(
│ array_list[i].dyn_castpir::DoubleAttribute().data());
│ }
│ } else {
│ PADDLE_THROW(common::errors::Unimplemented(
│ "ConvertPirAttribute2RuntimeAttribute not support [%s] ",
│ attr_type_name));
│ }
│ }
│ return vec_res;
修复后在 v3.1.0 源码基础上测试,关闭 MKLDNN 时推理正常,开启 MKLDNN 时因故未能完成编译验证。
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
临时绕过方案
│ // 关闭 MKLDNN,使用纯 CPU 原生执行
│ config.DisableMKLDNN();
│ // 或
│ config.EnableMKLDNN(); // 改为不启用
关闭 MKLDNN 后推理正常,但性能下降约 10 倍(以 PP-OCRv6 为例,开启 MKLDNN 预期 3-5 秒,关闭后约 38 秒)。
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
环境补充
• CMake 版本: 4.3.0-rc1(编译 3.1.0 源码时,第三方库的 cmake_minimum_required 版本过低导致兼容性问题,需逐一手动修复)
• OneDNN 版本: v3.6.2(Paddle 3.3.1 自带)
• 模型版本: PP-OCRv6_medium_det_infer / PP-OCRv6_medium_rec_infer
其他补充信息 Additional Supplementary Information
No response
Activity
davidhaas6 commentedon Sep 28, 2026
I can reproduce this on Windows build 26200 with the Python packages paddleocr==3.7.0, paddlex==3.7.2, and paddlepaddle==3.3.1 (Python 3.10.11, AMD64 Family 25 Model 33 CPU). Using
TextDetection(model_name="PP-OCRv6_small_det", device="cpu", enable_mkldnn=True), inference fails on the first frame withNotImplementedError: ConvertPirAttribute2RuntimeAttribute not support [pir::ArrayAttribute<pir::DoubleAttribute>]. The same detector runs withenable_mkldnn=False. In the same application,TextRecognition(model_name="PP-OCRv6_small_rec", device="cpu", enable_mkldnn=True)completes inference. This seems to affect the small detection model specifically, in addition to the medium models and C++ path reported above.Anthony-Maxwell-Franklin commentedon Oct 22, 2026
补充一条Linux独立复现,用的Python(不含 paddleocr,纯 paddlex),触发模型是和PP-OCRv6完全不同的一族 —— 说明这不是某个模型的问题。以下内容包含AI生成内容,但是经过生产环境检验
Environment
Minimal reproduction (no paddleocr needed)
create_model()succeeds; the abort is on the firstpredict():(Line 116 in the Linux py3.11 build vs 118 in the Windows build reported above — same function.)
Affected models — the whole layout-detection family, all of them abort on the same input:
PP-DocLayout-L,PP-DocLayout-M,PP-DocLayout-S,PP-DocLayout_plus-L.Related but separate: PaddleX already blocklists the sibling DETR models
(
Mask-RT-DETR-M/S,Co-Deformable-DETR-Swin-T,Co-DINO-Swin-L, and evenPP-DocLayoutV2/V3), so it silently routes these four to plain CPU — see the PaddleX issue I filedfor the blocklist gap. This comment is about the underlying converter behaviour:
PADDLE_THROWfor an attribute type that appears in more than one shipped model family means every new
model with a
float64attribute array hits this wall until Paddle learns to convert it.Also note these do not help as workarounds (they are Paddle flags; PaddleX decides the
backend itself):
FLAGS_use_mkldnn=0,FLAGS_enable_pir_api=0. What does work:PADDLE_PDX_ENABLE_MKLDNN_BYDEFAULT=False, or explicitrun_mode="paddle".alfonsodg commentedon Nov 3, 2026
Confirming this on PaddlePaddle 3.5.0-dev (Linux, CPU-only build) and adding a root-cause analysis + patch.
Repro
PPStructureV3(PaddleX layout detection → table/formula) aborts before producing output. On3.0.0b1it does not even reach the exception: rawSIGSEGVinAnalysisPredictor::PrepareProgram.Root cause
paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc,ConvertPirAttribute2RuntimeAttribute. The double-array branch validates only thefirst element and only accepts literal
pir::DoubleAttribute, then throws:The schema declares a double array, but the concrete elements may be
FloatAttribute/Int32Attribute/Int64Attribute. They are losslesslypromotable, so the throw is a false negative.
Proposed patch
Verification with the patched build
PPStructureV3constructs and runs; no exception, no segfault.colspanfrom a real document.R_{n}=F_{y}A_{g},\phi M_{n}=\phi F_{y}Z_{x}\geq M_{u}).Build note
With
-DWITH_GPU=ONand CUDA >= 11.4 / compute capability >= 80, cmake forcesWITH_FLASHATTN=ONand the build dies compilingflash_attn_with_bias_and_mask.cu; a CPU-only build (-DWITH_GPU=OFF) is enoughto validate this path.
Tracking issue with full details in our fork: alfonsodg/RapidOCR#8
fix(onednn): accept promoted scalars in double array attributes (Padd…