Skip to content

[InferMeta] Fix SplitInferMeta error message crash for >9 sections - #79941

Open
omoYang wants to merge 2 commits into
PaddlePaddle:developfrom
omoYang:fix-split-infermeta-sections-overflow
Open

omoYang wants to merge 2 commits into
PaddlePaddle:developfrom
omoYang:fix-split-infermeta-sections-overflow

Conversation

@omoYang

@omoYang omoYang commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

SplitInferMeta 在三处校验(num_or_sections 含多个 -1、unknown 段求和、普通段求和)的报错信息里,用 make_ddim(sections_data) 把 num_or_sections 列表格式化成 [...]。make_ddim 返回的是表示张量 shape 的 DDim,而 DDim 的 rank 上限是 9(DDim::kMaxRank)。

当 num_or_sections 的元素个数超过 9 且对应校验失败时,构造报错信息本身会抛出一个不相关的错误:
Unimplemented error. Invalid dimension to be accessed. Now only supports access to dimension 0 to 9, but received dimension is N.

真实的 "Sum of Attr(num_or_sections) must be equal..." 原因反而被这条二次崩溃掩盖。num_or_sections 的长度语义是“切分段数”,可以远超 9,不应借用只为张量 shape 设计的 DDim。

本 PR 将三处 make_ddim(sections_data) 替换为 paddle::string::join_strings(sections_data, ", "),把段列表作为普通整数列表打印,不受 rank ≤ 9 限制。校验逻辑完全不变,仅改报错信息的格式化方式。

复现配置(修复后给出正确的 sum 不匹配报错,而非 ddim 崩溃):
paddle.split(paddle.zeros([512, 0], "float32"), [192, 256] * 32, axis=1)

是否引起精度变化

否

SplitInferMeta formatted the num_or_sections list for its error messages
via make_ddim(sections_data), which builds a DDim. DDim is meant for a
tensor shape and caps rank at 9 (DDim::kMaxRank). When num_or_sections
has more than 9 entries and a validation check fails, constructing the
error message itself throws an unrelated "Invalid dimension to be
accessed ... received dimension is N" error, masking the real cause.

Replace make_ddim(sections_data) with paddle::string::join_strings(
sections_data, ", ") in the three enforce messages so the sections list
is printed as a plain integer list with no rank limit. Validation logic
is unchanged; only the error text formatting differs.
@Paddle-Review-Bot

Paddle-Review-Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Paddle-Bot Review Board (review完成)

序号 位置 优先级 规则来源 状态
1 切分段数超过 9 的报错缺少回归测试 P2 仓库规则:测试质量与验证 ✅

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

序号 位置 维度 状态
1 含 -1 的段数超限报错未覆盖 测试策略 💡
各维度得分(仅评本 PR 改动,点击展开)
86 测试策略
1
90 约定偏离
90 逻辑清晰度
90 类型安全
90 中层优雅度
92 API 表面一致性
92 高层优雅度
93 错误处理一致性
93 底层优雅度
95 跨模块架构
95 设计一致性
95 命名质量
95 契约一致性
96 AI 生成债务
96 依赖健康度
97 抽象适配度
100 未完成迁移
100 包组织结构
— 鉴权一致性
— 初始化耦合

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

"along the split dimension. But received Attr(num_or_sections)"
" = [%s], input(X)'s shape = [%s], Attr(dim) = %d.",
make_ddim(sections_data),
paddle::string::join_strings(sections_data, ", "),

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 修复本身正确(num_or_sections 长度 ≤ 9 时 join_strings(..., ", ") 与 DDim 的输出格式一致,长度 > 9 时不再在构造报错信息时触发 paddle/common/ddim.h 中 rank 0~9 的 PD_THROW),但 PR 没有附带回归测试。test/legacy_test/test_split_op.py 现有的错误用例(如 API_TestSplitZeroSizeInvalidSections 用 [1, 1])段数都 ≤ 9,旧实现也能通过,以后改回 make_ddim 不会被发现。

建议在 test/legacy_test/test_split_op.py 加一个段数 > 9 的动态图用例,并断言真实报错内容而不只是断言抛异常,例如:

x = paddle.zeros([5], dtype='float32')
with self.assertRaisesRegex(ValueError, r"Sum of Attr\(num_or_sections\) must be equal"):
    paddle.split(x, [1] * 10)
with self.assertRaisesRegex(ValueError, r"Only one dimension value of Attr\(num_or_sections\)"):
    paddle.split(x, [-1, -1] + [1] * 8)

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.

已在 test_many_sections_error_message 中补充超过 9 段的回归测试,并断言了真实报错内容,此问题已解决。

…sage

Guards against reverting to make_ddim(sections_data), whose DDim rank<=9
limit crashed error formatting when num_or_sections has more than 9
entries. Asserts the real messages (sum mismatch, multiple -1) in dygraph
mode, which the old implementation could not produce.
ValueError,
r"Only one dimension value of Attr\(num_or_sections\)",
):
paddle.split(x, [-1, -1] + [1] * 8)

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.

💡 可维护性建议(测试策略,不阻塞合入):本 PR 改了 SplitInferMeta 的三处报错格式化,这个用例覆盖了 PADDLE_ENFORCE_LE(多个 -1)和 PADDLE_ENFORCE_EQ(求和不等)两处,含 -1 时的 PADDLE_ENFORCE_LT(unary.cc:5074)还没有覆盖。可以再加一条超过 9 段的断言,例如:

with self.assertRaisesRegex(
    ValueError, r"other than unknown section must be less than"
):
    paddle.split(x, [-1] + [1] * 9)

"along the split dimension. But received Attr(num_or_sections)"
" = [%s], input(X)'s shape = [%s], Attr(dim) = %d.",
make_ddim(sections_data),
paddle::string::join_strings(sections_data, ", "),

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.

已在 test_many_sections_error_message 中补充超过 9 段的回归测试,并断言了真实报错内容,此问题已解决。

@omoYang

omoYang commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

2 similar comments
@omoYang

omoYang commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@omoYang

omoYang commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants