Skip to content

fix(onednn): accept promoted scalar types in double array attributes - #79916

Open
alfonsodg wants to merge 1 commit into
PaddlePaddle:developfrom
alfonsodg:fix/onednn-double-array-attribute
Open

alfonsodg wants to merge 1 commit into
PaddlePaddle:developfrom
alfonsodg:fix/onednn-double-array-attribute

Conversation

@alfonsodg

Copy link
Copy Markdown

Problem

ConvertPirAttribute2RuntimeAttribute throws when an op schema declares
pir::ArrayAttribute<pir::DoubleAttribute> but the concrete elements are
FloatAttribute, Int32Attribute or Int64Attribute:

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

The double-array branch validates only the first element and only accepts a
literal pir::DoubleAttribute, then raises. The values are losslessly
promotable to double, so the guard is a false negative.

This breaks PaddleX PP-StructureV3 (layout detection → table/formula
recognition) on PaddlePaddle 3.x. On 3.0.0b1 the same pipeline aborts even
earlier with a SIGSEGV in AnalysisPredictor::PrepareProgram.

Fixes #79749 (related: #77340).

Change

  • Accept DoubleAttribute directly.
  • Promote FloatAttribute, Int32Attribute, Int64Attribute to double.
  • Keep throwing Unimplemented for genuinely unsupported element types.

No behavior change for well-typed double arrays; only previously-rejected
numeric inputs now succeed.

Verification

Built PaddlePaddle from this branch (CPU-only, -DWITH_GPU=OFF; the GPU build
forces FlashAttention and fails compiling flash_attn_with_bias_and_mask.cu)
and ran the previously crashing pipeline:

  • PPStructureV3 constructs and returns results (no exception, no segfault).
  • Table structure recovered as HTML with merged-cell colspan on a real
    economic-offer page.
  • Formula recognition returns LaTeX: R_{n}=F_{y}A_{g},
    \phi M_{n}=\phi F_{y}Z_{x}\geq M_{u}.
  • 5 wrapper unit tests pass.

Happy to add a C++ unit test for the attribute conversion if you point me to the
preferred location (test/cpp/fluid/framework/new_executor/…?).

…lePaddle#79749)

ConvertPirAttribute2RuntimeAttribute rejected pir::ArrayAttribute values whose
elements were FloatAttribute, Int32Attribute or Int64Attribute when the op
schema declared pir::ArrayAttribute<pir::DoubleAttribute>. The values are
losslessly promotable to double, so the guard produced a false negative and
aborted inference with:

  ConvertPirAttribute2RuntimeAttribute not support
  [pir::ArrayAttribute<pir::DoubleAttribute>]

This breaks PaddleX PP-StructureV3 (layout detection, table and formula
recognition) on PaddlePaddle 3.x.

Accept DoubleAttribute directly and promote Float/Int32/Int64; keep throwing
for genuinely unsupported element types.

Ref PaddlePaddle#79749
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 00:41
@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Paddle-Review-Bot

Paddle-Review-Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Paddle-Bot Review Board (review完成)

序号 位置 优先级 规则来源 状态
1 BuildPhiContext 先于此处拒绝提升元素 P1 默认规则 🚧
2 double 数组提升缺少回归测试 P2 默认规则 🚧

可维护性建议(总分 88.5 / 100,只给建议,不影响评审结论)

序号 位置 维度 状态
1 不支持元素时的报错信息 错误处理一致性 💡
2 冗余的空数组判断 逻辑清晰度 💡
各维度得分(仅评本 PR 改动,点击展开)
84 错误处理一致性
1
84 测试策略
85 契约一致性
85 跨模块架构
85 高层优雅度
86 逻辑清晰度
2
86 中层优雅度
87 AI 生成债务
87 API 表面一致性
87 设计一致性
88 未完成迁移
89 底层优雅度
90 抽象适配度
90 约定偏离
90 类型安全
95 命名质量
95 包组织结构
100 依赖健康度
— 鉴权一致性
— 初始化耦合

Powered by Nyanpasu claude with Opus 5.5 默认推理级别, please check the suggestions carefully.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Kernel attribute arrays beginning with Float, Int32, or Int64 still throw in BuildPhiContext before reaching the converter because the shared double-array path requires a DoubleAttribute first element.

1 open issue
What changed in this PR

This PR broadens oneDNN’s PIR-to-runtime double-array conversion to address numeric attribute failures reported in #79749 and #77340.

Changes:

  • Validates each array element rather than only the first.
  • Converts Float, Int32, and Int64 attributes to double, while retaining Double support.
  • Preserves Unimplemented errors for unsupported element types.
File Description
paddle/​fluid/​framework/​new_executor/​instruction/​onednn/​onednn_instruction.cc Adds per-element numeric conversion for double-array attributes.

Review effort: Balanced

Comment on lines +113 to +116
} else if (array_list[i].isa<pir::FloatAttribute>()) {
vec_res.push_back(
static_cast<double>(
array_list[i].dyn_cast<pir::FloatAttribute>().data()));
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>()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 按当前构造顺序,这里放宽的元素类型很可能执行不到。OneDNNPhiKernelInstruction 构造函数先在 L283/L305 调用 BuildPhiContext,它遍历的是同一组 AttrParams(true) 属性;而 pir_adaptor_util.h:378-390 中 pir::ArrayAttribute<pir::DoubleAttribute> 分支仍要求首元素是 DoubleAttribute,否则抛 attr type not support。本函数要到 L396 才转换 ctx_attr_,并且只在 op 带 extra_args 时执行。

结果有两种:

  • 首元素为 Float/Int32/Int64:在 BuildPhiContext 就失败,不会走到这里;
  • 首元素为 Double、后续元素不是:BuildPhiContext 会对这些元素直接 dyn_cast<pir::DoubleAttribute>().data()。

建议把数值提升抽成一个共享 helper,BuildPhiContext 和这里都调用它。另请补充触发问题的具体 op 和属性名,确认修复后的路径确实生效。

if (array_list.size() > 0) {
if (array_list[0].isa<pir::DoubleAttribute>()) {
for (size_t i = 0; i < array_list.size(); ++i) {
for (size_t i = 0; i < array_list.size(); ++i) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 这次改变了 pir::ArrayAttribute<pir::DoubleAttribute> 的接受规则,但 PR 没有回归测试。建议补充:

  • 正向用例:double 数组属性中混合 Double/Float/Int32/Int64 元素,断言转换后的值和顺序正确;
  • 负向用例:包含不支持的元素类型(如 StrAttribute),断言抛出 Unimplemented。

该函数是 static,不方便直接单测,可以执行一个带 double[] 属性的 oneDNN 算子来覆盖(参考 test/cpp/new_executor/ 或现有 oneDNN PIR 测试),同时覆盖上一条提到的 BuildPhiContext 路径。

array_list[i].dyn_cast<pir::Int64Attribute>().data()));
} else {
PADDLE_THROW(common::errors::Unimplemented(
"ConvertPirAttribute2RuntimeAttribute not support [%s] ",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 可维护性建议(错误处理一致性,不阻塞合入):进入该分支时 attr_type_name 恒为 pir::ArrayAttribute<pir::DoubleAttribute>,而这个类型本身是支持的,报“不支持该类型”与实际原因不符。建议在消息中带上属性名和出错元素下标,例如 "ConvertPirAttribute2RuntimeAttribute: element %d of attr [%s] (%s) must be Double/Float/Int32/Int64",参数为 i, attr_name, attr_type_name。

@@ -106,15 +106,27 @@ static phi::Attribute ConvertPirAttribute2RuntimeAttribute(
auto array_list = attr.dyn_cast<pir::ArrayAttribute>().AsVector();
std::vector<double> vec_res;
if (array_list.size() > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 可维护性建议(逻辑清晰度,不阻塞合入):改成逐元素循环后,外层 if (array_list.size() > 0) 已不再保护任何 array_list[0] 访问。可以删除这一层判断及 L131 对应的 },减少一级嵌套。

@paddle-bot paddle-bot Bot added the contributor External developers label Nov 3, 2026

This branch has not been deployed

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

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants