Skip to content

Paddle Inference 3.3.1 OneDNN 执行时 ConvertPirAttribute2RuntimeAttribute 不支持 ArrayAttribute<DoubleAttribute> #79749

Open

Description

@jsmike9527-coder

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)

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

复现步骤

  1. 下载 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
  2. 加载 PP-OCRv6 系列模型(或其他使用 PIR 格式的模型),启用 MKLDNN(OneDNN)
  3. 执行推理,即触发该错误

关键代码:

│ // 启用 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

  1. davidhaas6 commented on Sep 28, 2026

    @davidhaas6

    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 with NotImplementedError: ConvertPirAttribute2RuntimeAttribute not support [pir::ArrayAttribute<pir::DoubleAttribute>]. The same detector runs with enable_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.

  2. Anthony-Maxwell-Franklin commented on Oct 22, 2026

    @Anthony-Maxwell-Franklin

    补充一条Linux独立复现,用的Python(不含 paddleocr,纯 paddlex),触发模型是和PP-OCRv6完全不同的一族 —— 说明这不是某个模型的问题。以下内容包含AI生成内容,但是经过生产环境检验

    Environment

    paddlepaddle 3.3.1, CPU build, Linux x86_64
    paddlex 3.7.2
    paddleocr 3.7.0
    Python 3.11.11
    CUDA none (CPU only)

    Minimal reproduction (no paddleocr needed)

    from paddlex import create_model
    model = create_model(model_name="PP-DocLayout_plus-L")
    list(model.predict("any_screenshot.png"))

    create_model() succeeds; the abort is on the first predict():

    NotImplementedError: (Unimplemented) ConvertPirAttribute2RuntimeAttribute
    not support [pir::ArrayAttribute<pir::DoubleAttribute>]
      (at /paddle/paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc:116)
    

    (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 even
    PP-DocLayoutV2/V3), so it silently routes these four to plain CPU — see the PaddleX issue I filed
    for the blocklist gap. This comment is about the underlying converter behaviour: PADDLE_THROW
    for an attribute type that appears in more than one shipped model family means every new
    model with a float64 attribute 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 explicit run_mode="paddle".

  3. alfonsodg commented on Nov 3, 2026

    @alfonsodg

    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. On 3.0.0b1 it does not even reach the exception: raw SIGSEGV in AnalysisPredictor::PrepareProgram.

    NotImplementedError: (Unimplemented) ConvertPirAttribute2RuntimeAttribute not support
    [pir::ArrayAttribute<pir::DoubleAttribute>]
      (at paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc:116)
    

    Root cause

    paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc,
    ConvertPirAttribute2RuntimeAttribute. The double-array branch validates only the
    first element and only accepts literal pir::DoubleAttribute, then throws:

    } else if (attr_type_name == "pir::ArrayAttribute<pir::DoubleAttribute>") {
      auto array_list = attr.dyn_cast<pir::ArrayAttribute>().AsVector();
      std::vector<double> vec_res;
      if (array_list.size() > 0) {
        if (array_list[0].isa<pir::DoubleAttribute>()) {      // too strict
          ...
        } else {
          PADDLE_THROW(... "not support [%s]");
        }
      }

    The schema declares a double array, but the concrete elements may be
    FloatAttribute / Int32Attribute / Int64Attribute. They are losslessly
    promotable, so the throw is a false negative.

    Proposed patch

    } else if (attr_type_name == "pir::ArrayAttribute<pir::DoubleAttribute>") {
      auto array_list = attr.dyn_cast<pir::ArrayAttribute>().AsVector();
      std::vector<double> vec_res;
      for (size_t i = 0; i < array_list.size(); ++i) {
        if (array_list[i].isa<pir::DoubleAttribute>()) {
          vec_res.push_back(array_list[i].dyn_cast<pir::DoubleAttribute>().data());
        } else if (array_list[i].isa<pir::FloatAttribute>()) {
          vec_res.push_back(static_cast<double>(
              array_list[i].dyn_cast<pir::FloatAttribute>().data()));
        } else if (array_list[i].isa<pir::Int32Attribute>()) {
          vec_res.push_back(static_cast<double>(
              array_list[i].dyn_cast<pir::Int32Attribute>().data()));
        } else if (array_list[i].isa<pir::Int64Attribute>()) {
          vec_res.push_back(static_cast<double>(
              array_list[i].dyn_cast<pir::Int64Attribute>().data()));
        } else {
          PADDLE_THROW(common::errors::Unimplemented(
              "ConvertPirAttribute2RuntimeAttribute not support [%s] ", attr_type_name));
        }
      }
      return vec_res;

    Verification with the patched build

    • PPStructureV3 constructs and runs; no exception, no segfault.
    • Table structure recovered as HTML with merged-cell colspan from a real document.
    • Formula recognition returns LaTeX (R_{n}=F_{y}A_{g}, \phi M_{n}=\phi F_{y}Z_{x}\geq M_{u}).
    • 5 unit tests for the parsing wrapper pass.

    Build note

    With -DWITH_GPU=ON and CUDA >= 11.4 / compute capability >= 80, cmake forces
    WITH_FLASHATTN=ON and the build dies compiling
    flash_attn_with_bias_and_mask.cu; a CPU-only build (-DWITH_GPU=OFF) is enough
    to validate this path.

    Tracking issue with full details in our fork: alfonsodg/RapidOCR#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions