← Back to Pull requests

[tmva][sofie] Add support for the ONNX Mish operator #24340

Open
souravkr114 opened this pull request with 57 lines diff across 4 files
View on GitHub
souravkr114 souravkr114 commented on Nov 25, 2026 11:47 UTC
Author

Description


Adds support for the ONNX Mish activation operator ($y = x \cdot \tanh(\text{softplus}(x))$) in TMVA SOFIE.

Summary


  • Added kMish to EBasicUnaryOperator and specialized UnaryOpTraits in ROperator_BasicUnary.hxx, reusing UnaryOpTraits<T, EBasicUnaryOperator::kSoftplus>::Op(X).

  • Registered "Mish" in RegisterBasicUnaryParsers (ParseBasicUnary.cxx).

  • Added make_Mish (ONNX opset 18) and TEST_INPUTS["Mish"] (spanning [-5.0, -0.2, 0.0, 1.0, 50.0, 100.0]) in generate_input_models.py.

  • Added TEST(ONNX, Mish) in TestCustomModelsFromONNX.cxx comparing against the ONNX ReferenceEvaluator output via readReference("Mish").
  • Diff: 57 lines (+56 / -1) across 4 files Reviewer: guitargeek Review duration: 10649m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.32) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.32 · 57 lines diff across 4 files
    0.32
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 2 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.243
    Real PR Conversation Timeline
    4 items
    guitargeek guitargeek requested changes on Nov 29, 2026 11:12 UTC
    Changes Requested Reviewer

    Thanks for the PR! The operator itself is correct. I compared the generated code against the onnx ReferenceEvaluator and a float64 computation on a dense sweep over [-100, 100], around the threshold, in the expf overflow region and for ±inf/NaN. It is within 2 ULP for x ≥ -87, and inf/NaN behave like the reference. Before merging, I'd like the test changed, plus a few smaller things.

    1. The test should check against an independent reference

    TEST(ONNX, Mish) compares against the same expression that the operator emits. That catches typos, but not a misreading of the ONNX definition. Also, the comment promises coverage that the inputs don't give: nothing is near the threshold of 20, and 50 doesn't overflow expf (that happens above ~88.7). The Softplus test has 89 and 100 for this reason. The >= 20 special case in the test is redundant too.

    Please use the reference files that generate_input_models.py produces with the onnx ReferenceEvaluator, like the ThresholdedRelu, Swish and HardSwish tests do:

    # in TEST_INPUTS
    "Mish": [f32([-5.0, -0.2, 0.0, 1.0, 50.0, 100.0], (2, 3))],
    

    TEST(ONNX, Mish)
    {
       SofieReference ref = readReference("Mish");
    
       ASSERT_INCLUDE_AND_RUN(std::vector<float>, "Mish", ref.f32("input0"));
    
       expectNear(output, ref.f32("output0"), DEFAULT_TOLERANCE);
    }
    

    2. Reuse the Softplus expression

    Mish is x * tanh(softplus(x)), so there's no need to copy the overflow guard. This generates exactly the same code:

    static std::string Op(const std::string &X)
    {
       return X + " * std::tanh(" + UnaryOpTraits<T, EBasicUnaryOperator::kSoftplus>::Op(X) + ")";
    }
    

    3. Please revert the unrelated formatting changes

    In generate_input_models.py, the quote changes in make_MinMultidirectionalBroadcast and make_Mod_ConstantFolding aren't part of this change.

    4. Commit message

    The subject line is too long and gets truncated. Something like [tmva][sofie] Add support for the ONNX Mish operator would match the other operator commits (e.g. PRelu). The body can be much shorter too: the diff already shows the enum value, the parser registration and the test.

    github-actions[bot] github-actions[bot] commented on Nov 29, 2026 12:40 UTC
    Bot

    Test Results


        22 files      22 suites   3d 9h 26m 31s ⏱️
     3 940 tests  3 940 ✅ 0 💤 0 ❌
    77 247 runs  77 247 ✅ 0 💤 0 ❌

    Results for commit e61403e7.

    [test-results]:data:application/gzip;base64,H4sIACQdDGsC/2WMyQqDMBRFf0Wy7iJTfU1/pmSEUDUlw0r6701EidLlOfdyVuT8ZBN6DpTeBpSKz51MiTL7sDQWjAhSXZ1zOzDB8YGvVLT+c2//qa4LJ/10ETbGEHcTy9KqAJTDjkf16np141N043NTh3n2uQKyI+GYWXCPURqnOANtQCoFSmBwWHBKJbkrib4//31unRABAAA=

    souravkr114 souravkr114 commented on Dec 02, 2026 17:18 UTC
    Author

    Thanks for the thorough review, @guitargeek! I've updated the PR to address all four points:

    1. Reference-based test: Added "Mish" to TEST_INPUTS with [-5.0, -0.2, 0.0, 1.0, 50.0, 100.0] (including the expf overflow regime at 100.0) and updated TEST(ONNX, Mish) to read and compare against the ReferenceEvaluator output via readReference("Mish").
    2. Reuse Softplus expression: Updated UnaryOpTraits<T, EBasicUnaryOperator::kMish>::Op to call UnaryOpTraits<T, EBasicUnaryOperator::kSoftplus>::Op(X).
    3. Clean diff: Reverted the unrelated formatting/quote changes in generate_input_models.py and ROperator_BasicUnary.hxx.
    4. Commit message: Amended the commit message to [tmva][sofie] Add support for the ONNX Mish operator with a concise body.

    Reviewers
    Assignees
    souravkr114 souravkr114
    Labels
    risk: low confidence: 89.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.7% (LOW) · Higher = larger blast radius
    31.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.9% · Lower = rushed or shallow review
    89.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.2% · Safe to merge
    3.2%