[tmva][sofie] Add support for the ONNX Mish operator #24340
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.
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=
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.
guitargeek
souravkr114
Description
Adds support for the ONNX
Mishactivation operator ($y = x \cdot \tanh(\text{softplus}(x))$) in TMVA SOFIE.Summary
kMishtoEBasicUnaryOperatorand specializedUnaryOpTraitsinROperator_BasicUnary.hxx, reusingUnaryOpTraits<T, EBasicUnaryOperator::kSoftplus>::Op(X)."Mish"inRegisterBasicUnaryParsers(ParseBasicUnary.cxx).make_Mish(ONNX opset 18) andTEST_INPUTS["Mish"](spanning[-5.0, -0.2, 0.0, 1.0, 50.0, 100.0]) ingenerate_input_models.py.TEST(ONNX, Mish)inTestCustomModelsFromONNX.cxxcomparing against the ONNXReferenceEvaluatoroutput viareadReference("Mish").