Skip to content

[tmva][sofie] Add Softplus operator for ONNX Inference#21023

Closed
AdityaDRathore wants to merge 1 commit intoroot-project:masterfrom
AdityaDRathore:feature/sofie-softplus
Closed

[tmva][sofie] Add Softplus operator for ONNX Inference#21023
AdityaDRathore wants to merge 1 commit intoroot-project:masterfrom
AdityaDRathore:feature/sofie-softplus

Conversation

@AdityaDRathore
Copy link

This Pull Request

This PR implements the Softplus operator for the SOFIE engine. This operator is required for ensuring compliance with ONNX Opset specifications and supporting modern neural network architectures that utilize smooth approximations of ReLU.

Changes or fixes:

  • New Operator: Implemented TMVA::Experimental::SOFIE::ROperator_Softplus.

    • Implementation Strategy: Inline code generation focusing on numerical stability and instruction efficiency.
    • Optimization: Uses std::log1p for precision near zero and implements a hard threshold for overflow protection:
      • Threshold: 0x1.4p+4f (20.0f) Inputs above this bypass exp() to prevent overflow.
      • Stability: Uses std::log1p(std::exp(x)) instead of log(1+exp(x)) to preserve precision for negative inputs.
    • Parsing: Updated RModelParser_ONNX to register Softplus.
  • Validation: Added TestSofieSoftplus GTest suite.

    • Verified bit-exact hexfloat emission in generated C++ code.
    • Verified numerical correctness against std::log1p reference values.
    • Verified threshold behavior (Identity return) for large inputs ($x \ge 20.0$).

Checklist:

  • tested changes locally (TestSofieSoftplus passing )
  • updated the docs ( not necessary for internal operator )

This PR fixes # (No specific issue linked, strictly feature addition)

cc: @guitargeek @moneta @devajithvs @bellenot

Implement the Softplus operator (y = ln(1 + exp(x))) for the SOFIE
inference engine to support ONNX Opset compliance.

technical details:

-  Adopt std::log1p(std::exp(x)) to preserve
  precision for small or negative inputs.

- Implement a threshold check. For x >= 20.0, the function returns x directly to avoid std::exp() overflow.

- Optimization: Generated code utilizes a local variable to minimize
  redundant memory loads and instruction cache pressure.

- Validation: Add GTest suite TestSofieSoftplus verifying hexfloat
  constants and numerical correctness limits.
@AdityaDRathore
Copy link
Author

Superseded by merged PR #21050. Closing this to avoid redundancy.

However, I have opened issue #21071 to track the numerical stability improvements (thresholding and log1p) that were developed in this PR. I will submit a follow-up PR to apply these fixes to the new ROperator_BasicUnary implementation and port the validation suite.

@AdityaDRathore
Copy link
Author

Superseded by PR #21092 to accommodate the rebase and architecture changes requested.

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