Open
Conversation
Summary: Add sign, expm1, log1p, and hyperbolic unary support to the generic, SIMD, and Vulkan UnaryOp backends. This keeps the new op_type values behaving consistently across CPU paths and shader execution. Also updates test_unaryop input domains for acosh, atanh, and log1p so the added operations are covered with valid regression inputs.
Summary: Map sign, sinh, asinh, cosh, acosh, and atanh to UnaryOp in onnx2ncnn and pnnx expression expansion. This lets the new unary family convert through the ONNX pipeline without falling back to unsupported expression handling. Also adds an ONNX regression that exercises the extended UnaryOp conversion path end to end.
Summary: Teach onnx2ncnn and pnnx to preserve expm1 and log1p as UnaryOp expressions during conversion. This keeps both operators aligned with the new backend support instead of dropping them during graph translation. Also fixes generated pnnx python to emit torch.expm1 and torch.log1p calls, and adds torch regressions for both operators.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6675 +/- ##
==========================================
+ Coverage 93.65% 94.01% +0.35%
==========================================
Files 930 930
Lines 296508 299383 +2875
==========================================
+ Hits 277688 281453 +3765
+ Misses 18820 17930 -890 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary: Add missing #include <math.h> to provide expm1f, log1pf and other float math function declarations. These functions are used in unary_op_expm1 and unary_op_log1p but were not explicitly included, causing build failures on some toolchains (e.g. musl-based systems).
Summary: Add missing expm1f declaration and implementation to simplemath.h/cpp. This fixes build failures when NCNN_SIMPLEMATH is enabled on platforms like aarch64-linux-gnu, where unary_op_expm1 directly calls expm1f without including system math.h (to avoid conflicting with simplemath declarations). Related to: 8bdc2f0 (add expm1 and log1p unary conversion coverage)
Summary: Tighten the atanh unary test input range so bf16 casting cannot round into the +/-1 singularity, relax the torch_expm1 pnnx comparison tolerance for fp16 execution, and export the ONNX unary-ops-ext test with dynamo disabled to keep it on a pnnx-compatible ONNX path.
Summary: Add expm1/log1p support to pnnx expression fusion so generated Python code no longer falls back to raw aten calls for these unary ops. Align the expm1 test input transform with the traced model and skip unary tests on torch versions where required ops are unavailable or the legacy ONNX exporter cannot emit aten::sinh to opset 19.
Summary: Drop the onnx_unary_ops_ext test because it primarily exercises PyTorch ONNX exporter compatibility instead of pnnx behavior, and it fails across multiple supported torch version ranges for reasons unrelated to the converter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends
UnaryOpwith additional unary operators and wires them through the conversion pipeline so the new ops behave consistently across backend execution and frontend import/export.The added operators are:
SIGNEXPM1SINHASINHCOSHACOSHATANHLOG1PThe main goal is to keep
UnaryOpcoverage aligned across the generic CPU path, SIMD-specialized backends, Vulkan shader execution, and model conversion tools.Implementation details are as follows:
UnaryOp::OperationTypevalues and implement them in the generic CPU pathUnaryOpsrc/layer/vulkan/shader/unaryop.compfor the new unary casesSign,Sinh,Asinh,Cosh,Acosh,Atanh,Expm1, andLog1ptoUnaryOpThis PR also adds regression coverage for both backend execution and conversion behavior:
tests/test_unaryop.cpptools/pnnx/tests/test_torch_expm1.pytools/pnnx/tests/test_torch_log1p.pytools/pnnx/tests/onnx/test_onnx_unary_ops_ext.pySome unary ops require tighter valid input domains during testing, so the
UnaryOpregression coverage also updates the randomized input range for:ACOSHwith input>= 1ATANHwith input in(-1, 1)LOG1Pwith input> -1Testing was performed locally with the following commands:
cmake -DNCNN_BUILD_TESTS=ON .. cmake --build . -j2 --target test_unaryop ./tests/test_unaryopThis keeps the new unary operators covered both as direct ncnn layer behavior and as end-to-end converted model expressions.