Skip to content

feat(pnnx): convert prelu[num_parameters=1] to leakyrelu, so that it can be fused with conv#6344

Merged
nihui merged 9 commits into
Tencent:masterfrom
w43322:convert_prelu
May 7, 2026
Merged

feat(pnnx): convert prelu[num_parameters=1] to leakyrelu, so that it can be fused with conv#6344
nihui merged 9 commits into
Tencent:masterfrom
w43322:convert_prelu

Conversation

@w43322
Copy link
Copy Markdown
Contributor

@w43322 w43322 commented Oct 9, 2025

before:
企业微信截图_503b1aa2-8ce2-4153-a693-0755fb6371b4

after:
截屏2025-10-09 23 26 17

@tencent-adm
Copy link
Copy Markdown
Member

tencent-adm commented Oct 9, 2025

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ w43322
❌ nihui
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 9, 2025

The binary size change of libncnn.so (bytes)

architecture base size pr size difference
x86_64 15190272 15159560 -30712 😘
armhf 6196764 6182416 -14348 😘
aarch64 9522968 9454784 -68184 😘

@nihui
Copy link
Copy Markdown
Member

nihui commented Oct 10, 2025

this pass shall be in pass_level5

@w43322
Copy link
Copy Markdown
Contributor Author

w43322 commented Oct 22, 2025

this pass shall be in pass_level5

done

@w43322
Copy link
Copy Markdown
Contributor Author

w43322 commented Oct 23, 2025

I'll look at the failed UTs later, 打工人太难了😭

@nihui
Copy link
Copy Markdown
Member

nihui commented May 7, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances pnnx graph rewriting to improve downstream fusion opportunities by converting scalar nn.PReLU (num_parameters=1) into nn.LeakyReLU, and also refines float/double serialization to better preserve round-trippable numeric strings in generated artifacts.

Changes:

  • Add a level5 graph rewrite pass that converts nn.PReLU num_parameters=1 into nn.LeakyReLU with negative_slope taken from the PReLU weight.
  • Improve float_to_string() / double_to_string() formatting by detecting non-roundtrippable default %e/%g output and retrying with higher precision, plus normalizing exponent formatting.

Reviewed changes

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

File Description
tools/pnnx/src/utils.cpp Adds exponent normalization and round-trip-aware formatting for float/double string serialization.
tools/pnnx/src/pass_level5/fuse_static_prelu.cpp Adds a rewrite pass to convert scalar PReLU into LeakyReLU to enable later fusions.

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

Comment thread tools/pnnx/src/utils.cpp Outdated
Comment thread tools/pnnx/src/utils.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread tools/pnnx/src/pass_level5/fuse_static_prelu.cpp
Comment thread tools/pnnx/src/pass_level5/fuse_static_prelu.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread tools/pnnx/src/utils.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread tools/pnnx/src/pass_level5/fuse_static_prelu.cpp
@nihui nihui merged commit 485d173 into Tencent:master May 7, 2026
30 of 31 checks passed
@nihui
Copy link
Copy Markdown
Member

nihui commented May 7, 2026

Thanks for your contribution !

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.

4 participants