Skip to content

[tmva][sofie] register Swish operator in the ONNX parser - #22564

Merged
guitargeek merged 2 commits into
root-project:masterfrom
harz05:fix/sofie-swish-parser
Jul 9, 2026
Merged

guitargeek merged 2 commits into
root-project:masterfrom
harz05:fix/sofie-swish-parser

Conversation

@harz05

@harz05 harz05 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Changes or fixes:

This PR registers the existing Swish operator in the ONNX parser. ROperator_Swish was implemented but never registered, so a model with the standard ONNX Swish op (opset 24) failed with "Operator type Swish is not yet supported".

I've added ParseSwish and it also reads the optional alpha attribute and rejectes when alpha!=1, since right now the op only implements alpha=1. Correspondingly "Swish" has been registered in RModelParser_ONNX.

Also added a Swish test model with reference and a test patch/

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #22552

@harz05
harz05 requested review from bellenot and lmoneta as code owners June 10, 2026 18:22
@harz05

harz05 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

kindly review, thanks.

On a side note, I had a doubt whether we would need a clean build for this as well? Since for the last 2 PR there was some caching issue where simple build was failing. @guitargeek

@guitargeek guitargeek added clean build Ask CI to do non-incremental build on PR in:SOFIE labels Jun 11, 2026

@lmoneta lmoneta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Interesting we add the suppot in the ROPerator but missed the parser.
Nice you included also the test.
We can maybe simplify the code, removing the template parameter in ROperator_Swish

Comment thread tmva/sofie_parsers/src/ParseSwish.cxx Resolved
@github-actions

github-actions Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 14h 42m 29s ⏱️
 3 872 tests  3 872 ✅ 0 💤 0 ❌
78 787 runs  78 787 ✅ 0 💤 0 ❌

Results for commit eb39001.

♻️ This comment has been updated with latest results.

@harz05

harz05 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

i've updated the PR with the requested changes, kindly review, thanks

@ferdymercury
ferdymercury requested a review from guitargeek June 17, 2026 12:54
@harz05

harz05 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

the build is currently failing on several platforms, CI logs doesn't seeem to show any issues related to swish tho, I'll try and take a look to see what could be the issue
@guitargeek

@guitargeek

Copy link
Copy Markdown
Contributor

the build is currently failing on several platforms, CI logs doesn't seeem to show any issues related to swish tho, I'll try and take a look to see what could be the issue @guitargeek

I don't know how you get to that conclusion, you can see it clearly in the log that the failure is related to the ROperator_Swish, and that we just have to drop the template parameter also on the Python side:

======================================================================
ERROR: test_functional (sofie_keras_parser.SOFIE_Keras_Parser.test_functional) [Functional Activation layer Swish test]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/github/home/ROOT-CI/src/bindings/pyroot/pythonizations/test/sofie_keras_parser.py", line 72, in run_model_tests
    generate_and_test_inference(keras_model_path, f"{model_type}/generated_header_files_dir")
  File "/github/home/ROOT-CI/src/bindings/pyroot/pythonizations/test/parser_test_function.py", line 55, in generate_and_test_inference
    rmodel = ROOT.TMVA.Experimental.SOFIE.PyKeras.Parse(model_file_path, batch_size)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/github/home/ROOT-CI/build/lib/ROOT/_pythonization/_tmva/_sofie/_parser/_keras/parser.py", line 432, in Parse
    rmodel = add_layer_into_RModel(rmodel, layer_data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/github/home/ROOT-CI/build/lib/ROOT/_pythonization/_tmva/_sofie/_parser/_keras/parser.py", line 211, in add_layer_into_RModel
    rmodel.AddOperator(move_operator(mapKerasLayer[fLayerType](layer_data)))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/github/home/ROOT-CI/build/lib/ROOT/_pythonization/_tmva/_sofie/_parser/_keras/parser.py", line 31, in MakeKerasActivation
    return mapKerasLayer[fLayerActivation](layer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/github/home/ROOT-CI/build/lib/ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/swish.py", line 25, in MakeKerasSwish
    op = SOFIE.ROperator_Swish("float")(fLayerInputName, fLayerOutputName)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: none of the 4 overloaded methods succeeded. Full details:
  ROperator_Swish::ROperator_Swish(TMVA::Experimental::SOFIE::ROperator_Swish&&) =>
    TypeError: could not convert argument 1
  ROperator_Swish::ROperator_Swish(const TMVA::Experimental::SOFIE::ROperator_Swish&) =>
    TypeError: could not convert argument 1
  ROperator_Swish::ROperator_Swish() =>
    TypeError: takes at most 0 arguments (1 given)
  ROperator_Swish::ROperator_Swish(string nameX, string nameY) =>
    TypeError: takes at least 2 arguments (1 given)

======================================================================

I'll update the PR with the simple fix, approve and merge.

harz05 added 2 commits July 9, 2026 07:41
This PR registers the existing Swish operator in the ONNX parser.
`ROperator_Swish` was implemented but never registered, so a model with
the standard ONNX `Swish` op (opset 24) failed with "Operator type Swish
is not yet supported".

I've added `ParseSwish` and it also reads the optional `alpha` attribute
and rejectes when alpha!=1, since right now the op only implements
alpha=1. Correspondingly "Swish" has been registered in
`RModelParser_ONNX`.

Also added a `Swish` test model with reference and a test patch/

Closes root-project#22552.
@guitargeek
guitargeek force-pushed the fix/sofie-swish-parser branch from 0ac5a25 to eb39001 Compare July 9, 2026 05:42
@guitargeek
guitargeek requested a review from vepadulano as a code owner July 9, 2026 05:42

@guitargeek guitargeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much for the fixes!

@harz05

harz05 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

apologies for not correctly noticing the error in the logs, thank you for the changes

@guitargeek
guitargeek merged commit 004bdb6 into root-project:master Jul 9, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clean build Ask CI to do non-incremental build on PR in:SOFIE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tmva][sofie] Register the existing Swish operator in the ONNX parser

3 participants