Skip to content

[tmva][sofie] Remove protobuf dependency from ONNX parser - #22936

Merged
guitargeek merged 4 commits into
root-project:masterfrom
guitargeek:sofie_protobuf
Aug 13, 2026
Merged

[tmva][sofie] Remove protobuf dependency from ONNX parser#22936
guitargeek merged 4 commits into
root-project:masterfrom
guitargeek:sofie_protobuf

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

SOFIE's ONNX importer was the only part of TMVA-SOFIE that depended on protobuf: it linked libprotobuf and ran protoc on onnx_proto3 at build time to read ONNX model files (which are protobuf messages). Core SOFIE never used protobuf.

Replace this with a small self-contained protobuf wire-format decoder in tmva/sofie_parsers/src/onnx.hxx. It provides the subset of the onnx:: message API that the parser actually uses (7 message types), with the same accessor signatures as the protoc-generated code, so the operator parsers (Parse*.cxx) are unchanged apart from the include.

With this, TMVA-SOFIE has no external dependencies and the tmva-sofie build option no longer requires protobuf 3.

Details:

  • onnx.hxx: hand-written wire reader (varint / 32- / 64-bit / length delimited), handling packed and unpacked repeated fields. Fixed-width fields are read byte-wise little-endian so the result is correct on big-endian hosts too. Unknown/future fields are skipped by wire type.
  • RModelParser_ONNX.cxx: ExtractDataFromTP now copies from the typed data vectors instead of RepeatedField::ExtractSubrange; dropped the GOOGLE_PROTOBUF_VERIFY_VERSION / ShutdownProtobufLibrary calls.
  • CMake: drop protobuf_generate_cpp, protobuf::libprotobuf and the Protobuf discovery/version checks; remove the generated onnx_proto3 schema.

The C++ ONNX binary format is the only ONNX serialization SOFIE ever read; text/JSON ONNX and unused messages (sparse tensor, training info) are intentionally not handled.

🤖 Done with the help of AI.

@guitargeek guitargeek self-assigned this Jul 27, 2026
@guitargeek
guitargeek requested a review from bellenot as a code owner July 27, 2026 13:58
@guitargeek
guitargeek requested a review from lmoneta as a code owner July 27, 2026 13:58
@guitargeek guitargeek changed the title [tmva-sofie] Remove protobuf dependency from ONNX parser [tmva][sofie] Remove protobuf dependency from ONNX parser Jul 27, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 15h 27m 51s ⏱️
 3 854 tests  3 854 ✅ 0 💤 0 ❌
79 439 runs  79 439 ✅ 0 💤 0 ❌

Results for commit 2e49387.

♻️ This comment has been updated with latest results.

@guitargeek
guitargeek force-pushed the sofie_protobuf branch 2 times, most recently from 6d1211f to 9dc8669 Compare July 28, 2026 14:48
SOFIE's ONNX importer was the only part of TMVA-SOFIE that depended on
protobuf: it linked libprotobuf and ran protoc on onnx_proto3 at build
time to read ONNX model files (which are protobuf messages). Core SOFIE
never used protobuf.

Replace this with a small self-contained protobuf wire-format decoder in
tmva/sofie_parsers/src/onnx.hxx. It provides the subset of the onnx::
message API that the parser actually uses (7 message types), with the
same accessor signatures as the protoc-generated code, so the operator
parsers (Parse*.cxx) are unchanged apart from the include.

With this, TMVA-SOFIE has no external dependencies and the tmva-sofie
build option no longer requires protobuf 3.

Details:
- onnx.hxx: hand-written wire reader (varint / 32- / 64-bit / length
  delimited), handling packed and unpacked repeated fields. Fixed-width
  fields are read byte-wise little-endian so the result is correct on
  big-endian hosts too. Unknown/future fields are skipped by wire type.
- RModelParser_ONNX.cxx: ExtractDataFromTP now copies from the typed
  data vectors instead of RepeatedField::ExtractSubrange; dropped the
  GOOGLE_PROTOBUF_VERIFY_VERSION / ShutdownProtobufLibrary calls.
- CMake: drop protobuf_generate_cpp, protobuf::libprotobuf and the
  Protobuf discovery/version checks; remove the generated onnx_proto3
  schema.

The C++ ONNX binary format is the only ONNX serialization SOFIE ever
read; text/JSON ONNX and unused messages (sparse tensor, training info)
are intentionally not handled.

🤖 Done with the help of AI.
Now that SOFIE no longer depends on protobuf (the ONNX parser uses a
self-contained wire-format decoder), it has no special dependency and
there is no reason to keep it behind a separate build option. Make all
of SOFIE - the ROOTTMVASofie library, the ONNX parser, the tests, and
the R__HAS_TMVASOFIE-guarded Clad derivatives - conditional on the
existing tmva flag instead.

The sofie_parsers subdirectory and the SOFIE test subdirectory are now
built unconditionally within the tmva-gated tree, hastmvasofie follows
tmva in the generated RConfigure.h, and the tmva-sofie=... lines are
dropped from the CI build configs (SOFIE is now built wherever tmva is
on).
Most of the SOFIE tests require BLAS as a runtime dependency. We need to
make it possible to toggle the TMVA SOFIE tests, so you can switch them
off on platforms where no BLAS is installed or available.

@lmoneta lmoneta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!
Thank you Jonas for this improvement!

@ferdymercury

Copy link
Copy Markdown
Collaborator

Thanks!! After merging one should remove protobuf from root-ci-images

@guitargeek

Copy link
Copy Markdown
Contributor Author

Thanks!! After merging one should remove protobuf from root-ci-images

That's something we can't do: the older release branches still rely on it.

@guitargeek
guitargeek merged commit 34f12c3 into root-project:master Aug 13, 2026
34 checks passed
@guitargeek
guitargeek deleted the sofie_protobuf branch August 13, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants