Skip to content

Fix: add PIR operator mappers for linear_v2, group_norm, layer_norm - #1645

Closed
PlumBlossomMaid wants to merge 4 commits into
PaddlePaddle:developfrom
PlumBlossomMaid:fix/pir-op-mappers
Closed

Fix: add PIR operator mappers for linear_v2, group_norm, layer_norm#1645
PlumBlossomMaid wants to merge 4 commits into
PaddlePaddle:developfrom
PlumBlossomMaid:fix/pir-op-mappers

Conversation

@PlumBlossomMaid

Copy link
Copy Markdown

PIR format uses positional input indices instead of named inputs. Add linear_v2 mapper from scratch, fix group_norm/layer_norm PIR mode.

Verified: NN.Linear/GroupNorm/LayerNorm all export correctly, diff < 1e-6

Fix #1644

@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

PIR format uses positional input indices instead of named inputs.
Add linear_v2 mapper from scratch, fix group_norm/layer_norm PIR mode.

Verified: nn.Linear/GroupNorm/LayerNorm all export correctly, diff < 1e-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds missing/incorrect PIR-mode operator mappers so Paddle models using linear_v2, group_norm, and layer_norm export correctly to ONNX when PIR uses positional IO instead of named IO.

Changes:

  • Added a new linear_v2 mapper and registered it for both legacy IR and PIR.
  • Updated layer_norm and group_norm mappers to handle PIR positional inputs/outputs.
  • Added an auto-scan test to validate nn.Linear export in PIR mode.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/test_auto_scan_linear.py Adds PIR export coverage for nn.Linear / linear_v2.
paddle2onnx/mappers_registry.h.in Registers LinearV2Mapper for linear_v2.
paddle2onnx/mapper/nn/linear_v2.h Declares the new LinearV2Mapper with PIR + legacy constructors.
paddle2onnx/mapper/nn/linear_v2.cc Implements ONNX lowering for linear_v2 including PIR positional IO.
paddle2onnx/mapper/nn/layer_norm.cc Adds PIR positional IO handling for layer_norm.
paddle2onnx/mapper/nn/group_norm.h Removes manual in_pir_mode override in PIR constructor.
paddle2onnx/mapper/nn/group_norm.cc Reworks group_norm Opset7 path to support PIR positional IO and 3D input handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread paddle2onnx/mapper/nn/layer_norm.cc Outdated
Comment on lines 56 to 58
if (has_input_Bias && has_input_Scale) {
auto scale_info = GetInput("Scale");
auto scale_name = scale_info[0].name;
Comment thread paddle2onnx/mapper/nn/layer_norm.cc Outdated
Comment on lines 197 to 198
if (has_input_Bias && has_input_Scale) {
auto scale_info = GetInput("Scale");
Comment thread paddle2onnx/mapper/nn/group_norm.cc Outdated
Comment on lines +70 to +78
// Fallback: create dummy scale/bias if not provided
if (!has_scale) {
scale_name = helper_->Constant(GetOnnxDtype(P2ODataType::FP32),
std::vector<float>(groups_, 1.0));
}
if (!has_bias) {
bias_name = helper_->Constant(GetOnnxDtype(P2ODataType::FP32),
std::vector<float>(groups_, 0.0));
}
Comment thread paddle2onnx/mapper/nn/group_norm.cc Outdated
Comment on lines +92 to +95
std::string dummy_scale = helper_->Constant(
GetOnnxDtype(P2ODataType::FP32), std::vector<float>(groups_, 1.0));
std::string dummy_bias = helper_->Constant(
GetOnnxDtype(P2ODataType::FP32), std::vector<float>(groups_, 0.0));
Comment on lines +79 to +81
} else {
helper_->MakeNode("Identity", {matmul->output(0)}, {output_name});
}
Comment on lines +40 to +42
if (in_pir_mode) {
auto x_info = GetInput(0);
input_name = x_info[0].name;
@PlumBlossomMaid

Copy link
Copy Markdown
Author

这个PR被我整的开不开了 #1652 用这个吧

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PIR] linear_v2 / group_norm / layer_norm 算子导出失败 — PIR 位置索引无命名映射

6 participants