Skip to content

Add ONNX Gelu operator support#12

Open
AdityaDRathore wants to merge 1 commit intoML4EP:devfrom
AdityaDRathore:feature/gelu-operator
Open

Add ONNX Gelu operator support#12
AdityaDRathore wants to merge 1 commit intoML4EP:devfrom
AdityaDRathore:feature/gelu-operator

Conversation

@AdityaDRathore
Copy link

Port of root-project/root#20876 to the standalone SOFIE repository, following the upstream-first development workflow.

What this adds

  • ROperator_GELU — Exact CDF-based GELU implementation (ONNX Opset 20)
  • ParseGelu.cxx — ONNX parser registration following the standalone parser file pattern
  • Rejects unsupported approximate="tanh" attribute with a clear error

Precision

Uses C++17 hexadecimal floating-point constants (0x1.6a09e667f3bcdp-1 for 1/√2) instead of runtime division to guarantee bit-exact reproducibility across platforms.

Formula

y = 0.5 * x * (1 + erf(x / sqrt(2)))

Testing

A comprehensive GTest validation suite (TestSofieGELU.cxx) exists in the ROOT PR (root-project/root#20876) covering:

  • Hexfloat constant presence in generated code
  • Generated code structure validation
  • Numeric correctness against SciPy reference values
  • std::cmath dependency check
  • Type and shape inference
  • Error handling (uninitialized Generate, missing tensor)

Tests can be adapted for the standalone SOFIE test infrastructure if needed.

Files changed

File Action
src/SOFIE_core/inc/SOFIE/ROperator_GELU.hxx New — operator header
src/SOFIE_parsers/src/ParseGelu.cxx New — ONNX parser
src/SOFIE_parsers/src/RModelParser_ONNX.cxx Modified — register operator
src/SOFIE_parsers/CMakeLists.txt Modified — add parser source
src/SOFIE_core/CMakeLists.txt Modified — add operator header

Implement the Gelu operator for the SOFIE inference engine with ONNX Opset 20 specifications.

Port of root-project/root#20876. The implementation uses the exact Gelu formula: y = 0.5 * x * (1+ erf( x / sqrt(2)))

Uses compile-time hexfloat constants for 1/sqrt(2) and 0.5 to ensure bit-exact reproducibility.

Updates RModelParser_ONNX to register the Gelu operator node. It explicitly rejects the approximate attribute (tanh approximation) as it is not yet supported.
@AdityaDRathore AdityaDRathore changed the title [tmva][sofie] Add ONNX Gelu operator support Add ONNX Gelu operator support Mar 9, 2026
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.

1 participant