Skip to content

fix&more fuse activate function - #6582

Open
futz12 wants to merge 5 commits into
Tencent:masterfrom
futz12:fuse_actfunc
Open

futz12 wants to merge 5 commits into
Tencent:masterfrom
futz12:fuse_actfunc

Conversation

@futz12

@futz12 futz12 commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor
  1. conv1d/2d/3d
  2. dwconv1d/2d/3d
  3. deconv1d/2d/3d
  4. dedwconv1d/2d/3d
  5. deformerconv2d

activate function fused

@futz12 futz12 changed the title more fuse activate function and erf for simd [WIP]more fuse activate function and erf for simd Mar 7, 2026
@nihui nihui closed this Mar 7, 2026
@nihui nihui reopened this Mar 7, 2026
@futz12 futz12 changed the title [WIP]more fuse activate function and erf for simd more fuse activate function and erf for simd Mar 7, 2026
@codecov-commenter

codecov-commenter commented Mar 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.96940% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.00%. Comparing base (f698111) to head (adb267c).
⚠️ Report is 33 commits behind head on master.

Files with missing lines Patch % Lines
src/layer/x86/x86_activation.h 61.29% 36 Missing ⚠️
src/layer/loongarch/loongarch_activation.h 70.00% 12 Missing ⚠️
src/layer/mips/mips_activation.h 72.50% 11 Missing ⚠️
src/layer/arm/arm_activation.h 82.05% 7 Missing ⚠️
src/layer/fused_activation.h 97.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6582      +/-   ##
==========================================
+ Coverage   93.19%   94.00%   +0.80%     
==========================================
  Files         832      684     -148     
  Lines      267728   219179   -48549     
==========================================
- Hits       249520   206046   -43474     
+ Misses      18208    13133    -5075     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@futz12 futz12 changed the title more fuse activate function and erf for simd [WIP]more fuse activate function and erf for simd Mar 10, 2026
7 gelu (erf exact or tanh fast selected by activation_params[0]), 8 silu, 9 elu, 10 selu, following the existing standalone gelu/swish/elu/selu layers.

extend fused_activation.h, the arm/x86/riscv/mips/loongarch activation dispatch (arm and x86 reuse the mathfun and *_fp32 helpers already in tree), the vulkan activation shader and the per-layer load_param validation. based on the wip work of Tencent#6582.
bump the random activation range and the deterministic activation sweeps to 0-10 for convolution, convolutiondepthwise, deconvolution, deconvolutiondepthwise, deformableconv2d, innerproduct and requantize, and cover the new types in the load_param validation tests.
add hardswish, gelu (exact and tanh), silu, elu and selu fusion to the existing convolution family passes, and add passes for convolution3d, convolutiondepthwise3d, deconvolution1d/3d, deconvolutiondepthwise1d/3d and deformableconv2d.

the innerproduct pass now covers the same activation set. vulkan keeps the tanh gelu approximation.
one test per layer type running all ten activations through pnnx and comparing with ncnn inference, plus innerproduct and deformableconv2d.
hardswish/hardsigmoid: use x*clamp(alpha*x+beta,0,1) in the scalar reference, every per-arch scalar tail and the riscv vector bodies, so alpha<=0 no longer diverges from the vectorized kernels (test_deconvolutiondepthwise_1 failed deterministically before); add alpha<0 regression cases to test_hardswish/test_hardsigmoid.

vulkan: fused activation type 7 honors the fast_gelu flag again (erfc branch via the Abramowitz-Stegun 7.1.26 erf approximation, max deviation 4.8e-7 vs the cpu reference) and clamps the tanh argument to +-10 like gelu.comp.

pnnx: replace the copy-pasted relu match() bodies in the deformableconv2d mask variants, reviving 5 dead fusions and relaxing 4 over-restrictive ones; strip the stray CR bytes that made the hardswish pattern lines look malformed.
@futz12 futz12 changed the title [WIP]more fuse activate function and erf for simd fix&more fuse activate function Oct 16, 2026
@futz12

futz12 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@nihui

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants