diff --git a/.github/workflows/root-ci-config/buildconfig/global.txt b/.github/workflows/root-ci-config/buildconfig/global.txt index eafb656ada6f7..60dcc005927a5 100644 --- a/.github/workflows/root-ci-config/buildconfig/global.txt +++ b/.github/workflows/root-ci-config/buildconfig/global.txt @@ -68,7 +68,6 @@ roofit_multiprocess=OFF root7=ON rootbench=OFF roottest=ON -test_roofit_hs3testsuite=ON runtime_cxxmodules=ON shadowpw=OFF shared=ON @@ -78,12 +77,13 @@ sqlite=ON ssl=ON test_distrdf_dask=ON test_distrdf_pyspark=ON +test_roofit_hs3testsuite=ON +test_tmva_sofie=ON testing=ON tmva-cpu=ON tmva-gpu=OFF tmva-cudnn=OFF tmva-pymva=OFF -tmva-sofie=ON tmva=ON unfold=ON unuran=ON diff --git a/.github/workflows/root-ci-config/buildconfig/mac-beta.txt b/.github/workflows/root-ci-config/buildconfig/mac-beta.txt index 9b29374d539eb..677c0a3eb3964 100644 --- a/.github/workflows/root-ci-config/buildconfig/mac-beta.txt +++ b/.github/workflows/root-ci-config/buildconfig/mac-beta.txt @@ -22,5 +22,4 @@ check_connection=ON cocoa=ON davix=OFF minuit2_omp=OFF -tmva-sofie=OFF x11=OFF diff --git a/.github/workflows/root-ci-config/buildconfig/mac26.txt b/.github/workflows/root-ci-config/buildconfig/mac26.txt index 9b29374d539eb..677c0a3eb3964 100644 --- a/.github/workflows/root-ci-config/buildconfig/mac26.txt +++ b/.github/workflows/root-ci-config/buildconfig/mac26.txt @@ -22,5 +22,4 @@ check_connection=ON cocoa=ON davix=OFF minuit2_omp=OFF -tmva-sofie=OFF x11=OFF diff --git a/.github/workflows/root-ci-config/buildconfig/opensuse16-march_native.txt b/.github/workflows/root-ci-config/buildconfig/opensuse16-march_native.txt index bd84268f2d64b..bed7a5e1b73c6 100644 --- a/.github/workflows/root-ci-config/buildconfig/opensuse16-march_native.txt +++ b/.github/workflows/root-ci-config/buildconfig/opensuse16-march_native.txt @@ -8,6 +8,5 @@ builtin_unuran=ON test_distrdf_dask=OFF test_distrdf_pyspark=OFF tmva-pymva=ON -tmva-sofie=ON pythia8=OFF cefweb=ON diff --git a/.github/workflows/root-ci-config/buildconfig/rawhide.txt b/.github/workflows/root-ci-config/buildconfig/rawhide.txt index 393a11a08eaf8..b1bbbc370e7b7 100644 --- a/.github/workflows/root-ci-config/buildconfig/rawhide.txt +++ b/.github/workflows/root-ci-config/buildconfig/rawhide.txt @@ -1,6 +1,5 @@ pythia8=ON test_distrdf_dask=OFF test_distrdf_pyspark=OFF -tmva-sofie=OFF vdt=OFF roofit_multiprocess=ON diff --git a/.github/workflows/root-ci-config/buildconfig/ubuntu2404-cuda.txt b/.github/workflows/root-ci-config/buildconfig/ubuntu2404-cuda.txt index 1f5d7b09db156..1bf4f5dfd4484 100644 --- a/.github/workflows/root-ci-config/buildconfig/ubuntu2404-cuda.txt +++ b/.github/workflows/root-ci-config/buildconfig/ubuntu2404-cuda.txt @@ -11,7 +11,6 @@ tmva-cpu=ON tmva-cudnn=ON tmva-gpu=ON tmva-pymva=OFF -tmva-sofie=OFF tmva=ON unfold=OFF webgui=ON diff --git a/.github/workflows/root-ci-config/buildconfig/windows10.txt b/.github/workflows/root-ci-config/buildconfig/windows10.txt index f0e25365d4838..2c5d109c19561 100644 --- a/.github/workflows/root-ci-config/buildconfig/windows10.txt +++ b/.github/workflows/root-ci-config/buildconfig/windows10.txt @@ -29,7 +29,7 @@ runtime_cxxmodules=OFF ssl=OFF test_distrdf_dask=OFF test_distrdf_pyspark=OFF -tmva-sofie=OFF +test_tmva_sofie=OFF use_gsl_cblas=ON vdt=OFF x11=OFF diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake index 72b5a8f434618..ad368e3718874 100644 --- a/cmake/modules/RootBuildOptions.cmake +++ b/cmake/modules/RootBuildOptions.cmake @@ -169,7 +169,6 @@ ROOT_BUILD_OPTION(tmva-cpu ON "Build TMVA with CPU support for deep learning (re ROOT_BUILD_OPTION(tmva-cudnn ON "Enable support for cuDNN (default when CUDA is enabled)") ROOT_BUILD_OPTION(tmva-gpu OFF "Build TMVA with GPU support for deep learning (requires CUDA)") ROOT_BUILD_OPTION(tmva-pymva OFF "Enable usage of Python ML libraries in TMVA (requires NumPy, works only with TensorFlow<=2.15)") -ROOT_BUILD_OPTION(tmva-sofie OFF "Build TMVA with support for sofie - fast inference code generation (requires protobuf 3)") ROOT_BUILD_OPTION(tpython ON "Build the TPython class that allows you to run Python code from C++") ROOT_BUILD_OPTION(unfold OFF "Enable the unfold package [GPL]") ROOT_BUILD_OPTION(unuran OFF "Enable support for UNURAN (package for generating non-uniform random numbers) [GPL]") @@ -192,6 +191,7 @@ option(minimal "Enable only required options by default" OFF) option(rootbench "Build rootbench if rootbench exists in root or if it is a sibling directory (implies testing=ON)" OFF) option(roottest "Build roottest (implies testing=ON)" OFF) option(test_roofit_hs3testsuite "Setup and use the HS3 conformance test suite (requires network)" OFF) +option(test_tmva_sofie "Enable SOFIE tests (requires BLAS library that can be found with CMake's FindBLAS)" ON) option(testing "Enable testing with CTest" OFF) option(asan "Build ROOT with address sanitizer instrumentation (see core/sanitizer for details)" OFF) option(_wheel_build "ROOT is being packaged as a wheel, do not install .dist-info metadata" OFF) diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake index 387b722115b21..7055457189e9d 100644 --- a/cmake/modules/RootConfiguration.cmake +++ b/cmake/modules/RootConfiguration.cmake @@ -454,11 +454,6 @@ if (tmva-pymva) else() set(haspymva undef) endif() -if (tmva-sofie) - set(hastmvasofie define) -else() - set(hastmvasofie undef) -endif() if (uring) set(hasuring define) else() diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake index 0452a9d7a4dd7..0154bcbc6314b 100644 --- a/cmake/modules/SearchInstalledSoftware.cmake +++ b/cmake/modules/SearchInstalledSoftware.cmake @@ -1009,50 +1009,18 @@ if(experimental_adaptivecpp) endif() endif() -#---Check for protobuf------------------------------------------------------------------- - -if(tmva-sofie) - if(testing) - message(STATUS "Looking for BLAS as an optional testing dependency of TMVA-SOFIE") - find_package(BLAS) - if(NOT BLAS_FOUND) - if(fail-on-missing) - message(FATAL_ERROR "BLAS not found, but it's required for TMVA-SOFIE testing") - else() - message(WARNING "BLAS not found: TMVA-SOFIE will not be fully tested") - endif() - endif() - endif() - message(STATUS "Looking for Protobuf") - set(protobuf_MODULE_COMPATIBLE TRUE) - find_package(Protobuf CONFIG) - if(NOT Protobuf_FOUND) - find_package(Protobuf MODULE) - endif() - if(NOT Protobuf_FOUND) +#---Check for optional TMVA-SOFIE testing dependency (BLAS)------------------------------- +# SOFIE itself has no external dependencies: ONNX models are read with a small +# self-contained protobuf wire-format decoder (tmva/sofie_parsers/src/onnx.hxx). + +if(tmva AND testing AND test_tmva_sofie) + message(STATUS "Looking for BLAS as an optional testing dependency of TMVA-SOFIE") + find_package(BLAS) + if(NOT BLAS_FOUND) if(fail-on-missing) - message(SEND_ERROR "Protobuf libraries not found and they are required (tmva-sofie option enabled)") + message(FATAL_ERROR "BLAS not found, but it's required for TMVA-SOFIE testing") else() - message(STATUS "Protobuf not found. Switching off tmva-sofie option") - set(tmva-sofie OFF CACHE BOOL "Disabled because Protobuf not found" FORCE) - endif() - else() - if(Protobuf_VERSION LESS 3.0) - if(fail-on-missing) - message(SEND_ERROR "Protobuf libraries found but is less than the version required (3.0) (tmva-sofie option enabled)") - else() - message(STATUS "Protobuf found but its version is not high enough (>3.0). Switching off tmva-sofie option") - set(tmva-sofie OFF CACHE BOOL "Disabled because found Protobuf version is not enough" FORCE) - endif() - else() - if(NOT TARGET protobuf::protoc) - if(fail-on-missing) - message(SEND_ERROR "Protobuf compiler not found (tmva-sofie option enabled)") - else() - message(STATUS "Protobuf compiler not found. Switching off tmva-sofie option") - set(tmva-sofie OFF CACHE BOOL "Disabled because Protobuf compiler not found" FORCE) - endif() - endif() + message(WARNING "BLAS not found: TMVA-SOFIE will not be fully tested") endif() endif() endif() diff --git a/config/RConfigure.in b/config/RConfigure.in index a15e94a8262e3..2b2370256b4ed 100644 --- a/config/RConfigure.in +++ b/config/RConfigure.in @@ -60,7 +60,6 @@ #@hastmvagpu@ R__HAS_TMVAGPU /**/ #@hastmvacudnn@ R__HAS_CUDNN /**/ #@haspymva@ R__HAS_PYMVA /**/ -#@hastmvasofie@ R__HAS_TMVASOFIE /*SOFIE is enabled*/ #@hasuring@ R__HAS_URING /**/ diff --git a/roofit/roofit/src/RooONNXFunc.cxx b/roofit/roofit/src/RooONNXFunc.cxx index cdc6d4ac35bd8..b3f9e86506948 100644 --- a/roofit/roofit/src/RooONNXFunc.cxx +++ b/roofit/roofit/src/RooONNXFunc.cxx @@ -259,7 +259,7 @@ void RooONNXFunc::initialize() // link-time dependency to the SOFIE parser library. if (gSystem->Load("libROOTTMVASofieParser") < 0) { throw std::runtime_error("RooONNXFunc: cannot load ONNX file since SOFIE ONNX parser is missing." - " Please build ROOT with tmva-sofie=ON."); + " Please build ROOT with tmva=ON."); } using OnnxToCpp = std::string (*)(std::uint8_t const *, std::size_t, const char *); auto onnxToCppWithSofie = resolveLazy("_RooONNXFunc_onnxToCppWithSofie", diff --git a/roofit/roofit/test/CMakeLists.txt b/roofit/roofit/test/CMakeLists.txt index e366faa6f0b9c..a66d1da193856 100644 --- a/roofit/roofit/test/CMakeLists.txt +++ b/roofit/roofit/test/CMakeLists.txt @@ -40,7 +40,7 @@ endif() add_subdirectory(vectorisedPDFs) -if(tmva-sofie) +if(tmva) ROOT_FIND_PYTHON_MODULE(torch) ROOT_FIND_PYTHON_MODULE(onnx) diff --git a/tmva/CMakeLists.txt b/tmva/CMakeLists.txt index 52ebfc37749a9..9e6f1564cdfeb 100644 --- a/tmva/CMakeLists.txt +++ b/tmva/CMakeLists.txt @@ -15,8 +15,4 @@ if(tmva-pymva) endif() add_subdirectory(sofie) -#parser depends on protobuf -#found if flag tmva-sofie is on -if (tmva-sofie) - add_subdirectory(sofie_parsers) -endif() +add_subdirectory(sofie_parsers) diff --git a/tmva/sofie/CMakeLists.txt b/tmva/sofie/CMakeLists.txt index b23733ce87319..47891b8fed315 100644 --- a/tmva/sofie/CMakeLists.txt +++ b/tmva/sofie/CMakeLists.txt @@ -9,7 +9,6 @@ ############################################################################ #Author: Sitong An, Lorenzo Moneta 10/03/2021 -#sofie is built only if protobuf is found set(sofie_root_support ON CACHE BOOL "" FORCE) @@ -110,7 +109,7 @@ if(sofie_root_support) target_compile_definitions(ROOTTMVASofie PRIVATE SOFIE_SUPPORT_ROOT_BINARY) endif() -# The building of the tests requires protobuf (available only when tmva-sofie is ON) -if (tmva-sofie) - ROOT_ADD_TEST_SUBDIRECTORY(test) +# Tests are not enabled unconditionally because they require BLAS +if(test_tmva_sofie) + ROOT_ADD_TEST_SUBDIRECTORY(test) endif() diff --git a/tmva/sofie/README.md b/tmva/sofie/README.md index f84653a257b85..a9b0bfed90528 100644 --- a/tmva/sofie/README.md +++ b/tmva/sofie/README.md @@ -7,15 +7,15 @@ This is a new development in TMVA and is currently in early experimental stage. ## Prerequisite -- Protobuf 3.0 or higher (for input of ONNX model files) - BLAS or Eigen (for execution of the generated code for inference) ## Installation -Build ROOT with the cmake option tmva-sofie enabled. +SOFIE is built as part of TMVA, so it is enabled whenever ROOT is built with +the `tmva` cmake option (which is ON by default). ```bash -cmake ../root -Dtmva-sofie=ON +cmake ../root -Dtmva=ON make -j8 ``` diff --git a/tmva/sofie/test/CMakeLists.txt b/tmva/sofie/test/CMakeLists.txt index 6d26ffe1e7ad2..7b2d27855f7db 100644 --- a/tmva/sofie/test/CMakeLists.txt +++ b/tmva/sofie/test/CMakeLists.txt @@ -73,12 +73,9 @@ if (ONNX_MODELS_DIR) configure_file(EmitFromONNX.cxx.in EmitFromONNX_all.cxx @ONLY) ROOTTEST_GENERATE_EXECUTABLE(emitFromONNX EmitFromONNX_all.cxx - LIBRARIES protobuf::libprotobuf ROOTTMVASofie ROOTTMVASofieParser + LIBRARIES ROOTTMVASofie ROOTTMVASofieParser FIXTURES_SETUP sofie-compile-models-onnx-build) - # silence protobuf warnings seen in version 3.0 and 3.6. Not needed from protobuf version 3.17 - target_compile_options(emitFromONNX PRIVATE -Wno-unused-parameter -Wno-array-bounds) - set(compile_models_fixtures sofie-compile-models-onnx-build) if (generate_onnx_models) ROOTTEST_ADD_TEST(SofieGenerateModels_ONNX diff --git a/tmva/sofie/test/EmitFromONNX.cxx.in b/tmva/sofie/test/EmitFromONNX.cxx.in index 00f0523300fff..15bd82eb86e17 100644 --- a/tmva/sofie/test/EmitFromONNX.cxx.in +++ b/tmva/sofie/test/EmitFromONNX.cxx.in @@ -52,7 +52,7 @@ int EmitModel(std::string filename, std::string outname) return 0; } -int main(int argc, char *argv[]) +int main(int /*argc*/, char * /*argv*/[]) { // clang-format off @EMIT_CAPTURES@; diff --git a/tmva/sofie_parsers/CMakeLists.txt b/tmva/sofie_parsers/CMakeLists.txt index a21c43ec2a18d..fabdc59362097 100644 --- a/tmva/sofie_parsers/CMakeLists.txt +++ b/tmva/sofie_parsers/CMakeLists.txt @@ -9,14 +9,9 @@ ############################################################################ #Author: Sitong An, Lorenzo Moneta 10/03/2021 -#sofie is built only if protobuf is found - -protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS "onnx_proto3") -set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE) -## silence protobuf warnings for version 3.6. Not needed from protobuf version 3.17 -set_source_files_properties(${PROTO_SRCS} PROPERTIES COMPILE_FLAGS -Wno-array-bounds) -## silence protobuf warnings for version 3.0. Not needed from protobuf version 3.6 -set_source_files_properties(${PROTO_SRCS} PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) +# The ONNX model files are read with a small self-contained protobuf +# wire-format decoder (src/onnx.hxx), so this package has no external +# dependency on protobuf / libprotobuf / protoc. ROOT_STANDARD_LIBRARY_PACKAGE(ROOTTMVASofieParser HEADERS @@ -83,17 +78,10 @@ ROOT_STANDARD_LIBRARY_PACKAGE(ROOTTMVASofieParser src/ParseGelu.cxx src/ParseHardSigmoid.cxx src/ParseHardSwish.cxx - ${PROTO_SRCS} - LIBRARIES PUBLIC - protobuf::libprotobuf DEPENDENCIES TMVA ROOTTMVASofie ) -target_include_directories(ROOTTMVASofieParser PUBLIC - $) -target_include_directories(ROOTTMVASofieParser BEFORE PUBLIC - ${Protobuf_INCLUDE_DIRS}) set_target_properties(ROOTTMVASofieParser PROPERTIES POSITION_INDEPENDENT_CODE TRUE) diff --git a/tmva/sofie_parsers/onnx_proto3 b/tmva/sofie_parsers/onnx_proto3 deleted file mode 100644 index d0c67cf465d93..0000000000000 --- a/tmva/sofie_parsers/onnx_proto3 +++ /dev/null @@ -1,717 +0,0 @@ -// -// WARNING: This file is automatically generated! Please edit onnx.in.proto. -// - - -// Copyright (c) ONNX Project Contributors. -// Licensed under the MIT license. - -syntax = "proto3"; - -package onnx; - -// Overview -// -// ONNX is an open specification that is comprised of the following components: -// -// 1) A definition of an extensible computation graph model. -// 2) Definitions of standard data types. -// 3) Definitions of built-in operators. -// -// This document describes the syntax of models and their computation graphs, -// as well as the standard data types. Together, they are referred to as the ONNX -// Intermediate Representation, or 'IR' for short. -// -// The normative semantic specification of the ONNX IR is found in docs/IR.md. -// Definitions of the built-in neural network operators may be found in docs/Operators.md. - -// Notes -// -// Release -// -// We are still in the very early stage of defining ONNX. The current -// version of ONNX is a starting point. While we are actively working -// towards a complete spec, we would like to get the community involved -// by sharing our working version of ONNX. -// -// Protobuf compatibility -// -// To simplify framework compatibility, ONNX is defined using the subset of protobuf -// that is compatible with both protobuf v2 and v3. This means that we do not use any -// protobuf features that are only available in one of the two versions. -// -// Here are the most notable contortions we have to carry out to work around -// these limitations: -// -// - No 'map' (added protobuf 3.0). We instead represent mappings as lists -// of key-value pairs, where order does not matter and duplicates -// are not allowed. - - -// Versioning -// -// ONNX versioning is specified in docs/IR.md and elaborated on in docs/Versioning.md -// -// To be compatible with both proto2 and proto3, we will use a version number -// that is not defined by the default value but an explicit enum number. -enum Version { - // proto3 requires the first enum value to be zero. - // We add this just to appease the compiler. - _START_VERSION = 0; - // The version field is always serialized and we will use it to store the - // version that the graph is generated from. This helps us set up version - // control. - // For the IR, we are using simple numbers starting with 0x00000001, - // which was the version we published on Oct 10, 2017. - IR_VERSION_2017_10_10 = 0x0000000000000001; - - // IR_VERSION 2 published on Oct 30, 2017 - // - Added type discriminator to AttributeProto to support proto3 users - IR_VERSION_2017_10_30 = 0x0000000000000002; - - // IR VERSION 3 published on Nov 3, 2017 - // - For operator versioning: - // - Added new message OperatorSetIdProto - // - Added opset_import in ModelProto - // - For vendor extensions, added domain in NodeProto - IR_VERSION_2017_11_3 = 0x0000000000000003; - - // IR VERSION 4 published on Jan 22, 2019 - // - Relax constraint that initializers should be a subset of graph inputs - // - Add type BFLOAT16 - IR_VERSION_2019_1_22 = 0x0000000000000004; - - // IR VERSION 5 published on March 18, 2019 - // - Add message TensorAnnotation. - // - Add quantization annotation in GraphProto to map tensor with its scale and zero point quantization parameters. - IR_VERSION_2019_3_18 = 0x0000000000000005; - - // IR VERSION 6 published on Sep 19, 2019 - // - Add support for sparse tensor constants stored in model. - // - Add message SparseTensorProto - // - Add sparse initializers - IR_VERSION_2019_9_19 = 0x0000000000000006; - - // IR VERSION 7 published on - // - Add support to allow function body graph to rely on multiple external opreator sets. - // - Add a list to promote inference graph's initializers to global and - // mutable variables. Global variables are visible in all graphs of the - // stored models. - // - Add message TrainingInfoProto to store initialization - // method and training algorithm. The execution of TrainingInfoProto - // can modify the values of mutable variables. - // - Implicitly add inference graph into each TrainingInfoProto's algorithm. - IR_VERSION = 0x0000000000000007; -} - -// Attributes -// -// A named attribute containing either singular float, integer, string, graph, -// and tensor values, or repeated float, integer, string, graph, and tensor values. -// An AttributeProto MUST contain the name field, and *only one* of the -// following content fields, effectively enforcing a C/C++ union equivalent. -message AttributeProto { - - // Note: this enum is structurally identical to the OpSchema::AttrType - // enum defined in schema.h. If you rev one, you likely need to rev the other. - enum AttributeType { - UNDEFINED = 0; - FLOAT = 1; - INT = 2; - STRING = 3; - TENSOR = 4; - GRAPH = 5; - SPARSE_TENSOR = 11; - - FLOATS = 6; - INTS = 7; - STRINGS = 8; - TENSORS = 9; - GRAPHS = 10; - SPARSE_TENSORS = 12; - } - - // The name field MUST be present for this version of the IR. - string name = 1; // namespace Attribute - - // if ref_attr_name is not empty, ref_attr_name is the attribute name in parent function. - // In this case, this AttributeProto does not contain data, and it's a reference of attribute - // in parent scope. - // NOTE: This should ONLY be used in function (sub-graph). It's invalid to be used in main graph. - string ref_attr_name = 21; - - // A human-readable documentation for this attribute. Markdown is allowed. - string doc_string = 13; - - // The type field MUST be present for this version of the IR. - // For 0.0.1 versions of the IR, this field was not defined, and - // implementations needed to use has_field heuristics to determine - // which value field was in use. For IR_VERSION 0.0.2 or later, this - // field MUST be set and match the f|i|s|t|... field in use. This - // change was made to accommodate proto3 implementations. - AttributeType type = 20; // discriminator that indicates which field below is in use - - // Exactly ONE of the following fields must be present for this version of the IR - float f = 2; // float - int64 i = 3; // int - bytes s = 4; // UTF-8 string - TensorProto t = 5; // tensor value - GraphProto g = 6; // graph - SparseTensorProto sparse_tensor = 22; // sparse tensor value - // Do not use field below, it's deprecated. - // optional ValueProto v = 12; // value - subsumes everything but graph - - repeated float floats = 7; // list of floats - repeated int64 ints = 8; // list of ints - repeated bytes strings = 9; // list of UTF-8 strings - repeated TensorProto tensors = 10; // list of tensors - repeated GraphProto graphs = 11; // list of graph - repeated SparseTensorProto sparse_tensors = 23; // list of sparse tensors -} - -// Defines information on value, including the name, the type, and -// the shape of the value. -message ValueInfoProto { - // This field MUST be present in this version of the IR. - string name = 1; // namespace Value - // This field MUST be present in this version of the IR for - // inputs and outputs of the top-level graph. - TypeProto type = 2; - // A human-readable documentation for this value. Markdown is allowed. - string doc_string = 3; -} - -// Nodes -// -// Computation graphs are made up of a DAG of nodes, which represent what is -// commonly called a "layer" or "pipeline stage" in machine learning frameworks. -// -// For example, it can be a node of type "Conv" that takes in an image, a filter -// tensor and a bias tensor, and produces the convolved output. -message NodeProto { - repeated string input = 1; // namespace Value - repeated string output = 2; // namespace Value - - // An optional identifier for this node in a graph. - // This field MAY be absent in ths version of the IR. - string name = 3; // namespace Node - - // The symbolic identifier of the Operator to execute. - string op_type = 4; // namespace Operator - // The domain of the OperatorSet that specifies the operator named by op_type. - string domain = 7; // namespace Domain - - // Additional named attributes. - repeated AttributeProto attribute = 5; - - // A human-readable documentation for this node. Markdown is allowed. - string doc_string = 6; -} - -// Training information -// TrainingInfoProto stores information for training a model. -// In particular, this defines two functionalities: an initialization-step -// and a training-algorithm-step. Initialization resets the model -// back to its original state as if no training has been performed. -// Training algorithm improves the model based on input data. -// -// The semantics of the initialization-step is that the initializers -// in ModelProto.graph and in TrainingInfoProto.algorithm are first -// initialized as specified by the initializers in the graph, and then -// updated by the "initialization_binding" in every instance in -// ModelProto.training_info. -// -// The field "algorithm" defines a computation graph which represents a -// training algorithm's step. After the execution of a -// TrainingInfoProto.algorithm, the initializers specified by "update_binding" -// may be immediately updated. If the targeted training algorithm contains -// consecutive update steps (such as block coordinate descent methods), -// the user needs to create a TrainingInfoProto for each step. -message TrainingInfoProto { - // This field describes a graph to compute the initial tensors - // upon starting the training process. Initialization graph has no input - // and can have multiple outputs. Usually, trainable tensors in neural - // networks are randomly initialized. To achieve that, for each tensor, - // the user can put a random number operator such as RandomNormal or - // RandomUniform in TrainingInfoProto.initialization.node and assign its - // random output to the specific tensor using "initialization_binding". - // This graph can also set the initializers in "algorithm" in the same - // TrainingInfoProto; a use case is resetting the number of training - // iteration to zero. - // - // By default, this field is an empty graph and its evaluation does not - // produce any output. Thus, no initializer would be changed by default. - GraphProto initialization = 1; - - // This field represents a training algorithm step. Given required inputs, - // it computes outputs to update initializers in its own or inference graph's - // initializer lists. In general, this field contains loss node, gradient node, - // optimizer node, increment of iteration count. - // - // An execution of the training algorithm step is performed by executing the - // graph obtained by combining the inference graph (namely "ModelProto.graph") - // and the "algorithm" graph. That is, the actual the actual - // input/initializer/output/node/value_info/sparse_initializer list of - // the training graph is the concatenation of - // "ModelProto.graph.input/initializer/output/node/value_info/sparse_initializer" - // and "algorithm.input/initializer/output/node/value_info/sparse_initializer" - // in that order. This combined graph must satisfy the normal ONNX conditions. - // Now, let's provide a visualization of graph combination for clarity. - // Let the inference graph (i.e., "ModelProto.graph") be - // tensor_a, tensor_b -> MatMul -> tensor_c -> Sigmoid -> tensor_d - // and the "algorithm" graph be - // tensor_d -> Add -> tensor_e - // The combination process results - // tensor_a, tensor_b -> MatMul -> tensor_c -> Sigmoid -> tensor_d -> Add -> tensor_e - // - // Notice that an input of a node in the "algorithm" graph may reference the - // output of a node in the inference graph (but not the other way round). Also, inference - // node cannot reference inputs of "algorithm". With these restrictions, inference graph - // can always be run independently without training information. - // - // By default, this field is an empty graph and its evaluation does not - // produce any output. Evaluating the default training step never - // update any initializers. - GraphProto algorithm = 2; - - // This field specifies the bindings from the outputs of "initialization" to - // some initializers in "ModelProto.graph.initializer" and - // the "algorithm.initializer" in the same TrainingInfoProto. - // See "update_binding" below for details. - // - // By default, this field is empty and no initializer would be changed - // by the execution of "initialization". - repeated StringStringEntryProto initialization_binding = 3; - - // Gradient-based training is usually an iterative procedure. In one gradient - // descent iteration, we apply - // - // x = x - r * g - // - // where "x" is the optimized tensor, "r" stands for learning rate, and "g" is - // gradient of "x" with respect to a chosen loss. To avoid adding assignments - // into the training graph, we split the update equation into - // - // y = x - r * g - // x = y - // - // The user needs to save "y = x - r * g" into TrainingInfoProto.algorithm. To - // tell that "y" should be assigned to "x", the field "update_binding" may - // contain a key-value pair of strings, "x" (key of StringStringEntryProto) - // and "y" (value of StringStringEntryProto). - // For a neural network with multiple trainable (mutable) tensors, there can - // be multiple key-value pairs in "update_binding". - // - // The initializers appears as keys in "update_binding" are considered - // mutable variables. This implies some behaviors - // as described below. - // - // 1. We have only unique keys in all "update_binding"s so that two - // variables may not have the same name. This ensures that one - // variable is assigned up to once. - // 2. The keys must appear in names of "ModelProto.graph.initializer" or - // "TrainingInfoProto.algorithm.initializer". - // 3. The values must be output names of "algorithm" or "ModelProto.graph.output". - // 4. Mutable variables are initialized to the value specified by the - // corresponding initializer, and then potentially updated by - // "initializer_binding"s and "update_binding"s in "TrainingInfoProto"s. - // - // This field usually contains names of trainable tensors - // (in ModelProto.graph), optimizer states such as momentums in advanced - // stochastic gradient methods (in TrainingInfoProto.graph), - // and number of training iterations (in TrainingInfoProto.graph). - // - // By default, this field is empty and no initializer would be changed - // by the execution of "algorithm". - repeated StringStringEntryProto update_binding = 4; -} - -// Models -// -// ModelProto is a top-level file/container format for bundling a ML model and -// associating its computation graph with metadata. -// -// The semantics of the model are described by the associated GraphProto's. -message ModelProto { - // The version of the IR this model targets. See Version enum above. - // This field MUST be present. - int64 ir_version = 1; - - // The OperatorSets this model relies on. - // All ModelProtos MUST have at least one entry that - // specifies which version of the ONNX OperatorSet is - // being imported. - // - // All nodes in the ModelProto's graph will bind against the operator - // with the same-domain/same-op_type operator with the HIGHEST version - // in the referenced operator sets. - repeated OperatorSetIdProto opset_import = 8; - - // The name of the framework or tool used to generate this model. - // This field SHOULD be present to indicate which implementation/tool/framework - // emitted the model. - string producer_name = 2; - - // The version of the framework or tool used to generate this model. - // This field SHOULD be present to indicate which implementation/tool/framework - // emitted the model. - string producer_version = 3; - - // Domain name of the model. - // We use reverse domain names as name space indicators. For example: - // `com.facebook.fair` or `com.microsoft.cognitiveservices` - // - // Together with `model_version` and GraphProto.name, this forms the unique identity of - // the graph. - string domain = 4; - - // The version of the graph encoded. See Version enum below. - int64 model_version = 5; - - // A human-readable documentation for this model. Markdown is allowed. - string doc_string = 6; - - // The parameterized graph that is evaluated to execute the model. - GraphProto graph = 7; - - // Named metadata values; keys should be distinct. - repeated StringStringEntryProto metadata_props = 14; - - // Training-specific information. Sequentially executing all stored - // `TrainingInfoProto.algorithm`s and assigning their outputs following - // the corresponding `TrainingInfoProto.update_binding`s is one training - // iteration. Similarly, to initialize the model - // (as if training hasn't happened), the user should sequentially execute - // all stored `TrainingInfoProto.initialization`s and assigns their outputs - // using `TrainingInfoProto.initialization_binding`s. - // - // If this field is empty, the training behavior of the model is undefined. - repeated TrainingInfoProto training_info = 20; -}; - -// StringStringEntryProto follows the pattern for cross-proto-version maps. -// See https://developers.google.com/protocol-buffers/docs/proto3#maps -message StringStringEntryProto { - string key = 1; - string value= 2; -}; - -message TensorAnnotation { - string tensor_name = 1; - // pairs to annotate tensor specified by above. - // The keys used in the mapping below must be pre-defined in ONNX spec. - // For example, for 8-bit linear quantization case, 'SCALE_TENSOR', 'ZERO_POINT_TENSOR' will be pre-defined as - // quantization parameter keys. - repeated StringStringEntryProto quant_parameter_tensor_names = 2; -} - - - -// Graphs -// -// A graph defines the computational logic of a model and is comprised of a parameterized -// list of nodes that form a directed acyclic graph based on their inputs and outputs. -// This is the equivalent of the "network" or "graph" in many deep learning -// frameworks. -message GraphProto { - // The nodes in the graph, sorted topologically. - repeated NodeProto node = 1; - - // The name of the graph. - string name = 2; // namespace Graph - - // A list of named tensor values, used to specify constant inputs of the graph. - // Each initializer (both TensorProto as well SparseTensorProto) MUST have a name. - // The name MUST be unique across both initializer and sparse_initializer, - // but the name MAY also appear in the input list. - repeated TensorProto initializer = 5; - - // Initializers (see above) stored in sparse format. - repeated SparseTensorProto sparse_initializer = 15; - - // A human-readable documentation for this graph. Markdown is allowed. - string doc_string = 10; - - // The inputs and outputs of the graph. - repeated ValueInfoProto input = 11; - repeated ValueInfoProto output = 12; - - // Information for the values in the graph. The ValueInfoProto.name's - // must be distinct. It is optional for a value to appear in value_info list. - repeated ValueInfoProto value_info = 13; - - // This field carries information to indicate the mapping among a tensor and its - // quantization parameter tensors. For example: - // For tensor 'a', it may have {'SCALE_TENSOR', 'a_scale'} and {'ZERO_POINT_TENSOR', 'a_zero_point'} annotated, - // which means, tensor 'a_scale' and tensor 'a_zero_point' are scale and zero point of tensor 'a' in the model. - repeated TensorAnnotation quantization_annotation = 14; - - // DO NOT USE the following fields, they were deprecated from earlier versions. - // repeated string input = 3; - // repeated string output = 4; - // optional int64 ir_version = 6; - // optional int64 producer_version = 7; - // optional string producer_tag = 8; - // optional string domain = 9; -} - -// Tensors -// -// A serialized tensor value. -message TensorProto { - enum DataType { - UNDEFINED = 0; - // Basic types. - FLOAT = 1; // float - UINT8 = 2; // uint8_t - INT8 = 3; // int8_t - UINT16 = 4; // uint16_t - INT16 = 5; // int16_t - INT32 = 6; // int32_t - INT64 = 7; // int64_t - STRING = 8; // string - BOOL = 9; // bool - - // IEEE754 half-precision floating-point format (16 bits wide). - // This format has 1 sign bit, 5 exponent bits, and 10 mantissa bits. - FLOAT16 = 10; - - DOUBLE = 11; - UINT32 = 12; - UINT64 = 13; - COMPLEX64 = 14; // complex with float32 real and imaginary components - COMPLEX128 = 15; // complex with float64 real and imaginary components - - // Non-IEEE floating-point format based on IEEE754 single-precision - // floating-point number truncated to 16 bits. - // This format has 1 sign bit, 8 exponent bits, and 7 mantissa bits. - BFLOAT16 = 16; - - // Future extensions go here. - } - - // The shape of the tensor. - repeated int64 dims = 1; - - // The data type of the tensor. - // This field MUST have a valid TensorProto.DataType value - int32 data_type = 2; - - // For very large tensors, we may want to store them in chunks, in which - // case the following fields will specify the segment that is stored in - // the current TensorProto. - message Segment { - int64 begin = 1; - int64 end = 2; - } - Segment segment = 3; - - // Tensor content must be organized in row-major order. - // - // Depending on the data_type field, exactly one of the fields below with - // name ending in _data is used to store the elements of the tensor. - - // For float and complex64 values - // Complex64 tensors are encoded as a single array of floats, - // with the real components appearing in odd numbered positions, - // and the corresponding imaginary component appearing in the - // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] - // is encoded as [1.0, 2.0 ,3.0 ,4.0] - // When this field is present, the data_type field MUST be FLOAT or COMPLEX64. - repeated float float_data = 4 [packed = true]; - - // For int32, uint8, int8, uint16, int16, bool, and float16 values - // float16 values must be bit-wise converted to an uint16_t prior - // to writing to the buffer. - // When this field is present, the data_type field MUST be - // INT32, INT16, INT8, UINT16, UINT8, BOOL, or FLOAT16 - repeated int32 int32_data = 5 [packed = true]; - - // For strings. - // Each element of string_data is a UTF-8 encoded Unicode - // string. No trailing null, no leading BOM. The protobuf "string" - // scalar type is not used to match ML community conventions. - // When this field is present, the data_type field MUST be STRING - repeated bytes string_data = 6; - - // For int64. - // When this field is present, the data_type field MUST be INT64 - repeated int64 int64_data = 7 [packed = true]; - - // Optionally, a name for the tensor. - string name = 8; // namespace Value - - // A human-readable documentation for this tensor. Markdown is allowed. - string doc_string = 12; - - // Serializations can either use one of the fields above, or use this - // raw bytes field. The only exception is the string case, where one is - // required to store the content in the repeated bytes string_data field. - // - // When this raw_data field is used to store tensor value, elements MUST - // be stored in as fixed-width, little-endian order. - // Floating-point data types MUST be stored in IEEE 754 format. - // Complex64 elements must be written as two consecutive FLOAT values, real component first. - // Complex128 elements must be written as two consecutive DOUBLE values, real component first. - // Boolean type MUST be written one byte per tensor element (00000001 for true, 00000000 for false). - // - // Note: the advantage of specific field rather than the raw_data field is - // that in some cases (e.g. int data), protobuf does a better packing via - // variable length storage, and may lead to smaller binary footprint. - // When this field is present, the data_type field MUST NOT be STRING or UNDEFINED - bytes raw_data = 9; - - // Data can be stored inside the protobuf file using type-specific fields or raw_data. - // Alternatively, raw bytes data can be stored in an external file, using the external_data field. - // external_data stores key-value pairs describing data location. Recognized keys are: - // - "location" (required) - POSIX filesystem path relative to the directory where the ONNX - // protobuf model was stored - // - "offset" (optional) - position of byte at which stored data begins. Integer stored as string. - // Offset values SHOULD be multiples 4096 (page size) to enable mmap support. - // - "length" (optional) - number of bytes containing data. Integer stored as string. - // - "checksum" (optional) - SHA1 digest of file specified in under 'location' key. - repeated StringStringEntryProto external_data = 13; - - // Location of the data for this tensor. MUST be one of: - // - DEFAULT - data stored inside the protobuf message. Data is stored in raw_data (if set) otherwise in type-specified field. - // - EXTERNAL - data stored in an external location as described by external_data field. - enum DataLocation { - DEFAULT = 0; - EXTERNAL = 1; - } - - // If value not set, data is stored in raw_data (if set) otherwise in type-specified field. - DataLocation data_location = 14; - - // For double - // Complex128 tensors are encoded as a single array of doubles, - // with the real components appearing in odd numbered positions, - // and the corresponding imaginary component appearing in the - // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] - // is encoded as [1.0, 2.0 ,3.0 ,4.0] - // When this field is present, the data_type field MUST be DOUBLE or COMPLEX128 - repeated double double_data = 10 [packed = true]; - - // For uint64 and uint32 values - // When this field is present, the data_type field MUST be - // UINT32 or UINT64 - repeated uint64 uint64_data = 11 [packed = true]; -} - -// A serialized sparse-tensor value -message SparseTensorProto { - // The sequence of non-default values are encoded as a tensor of shape [NNZ]. - // The default-value is zero for numeric tensors, and empty-string for string tensors. - // values must have a non-empty name present which serves as a name for SparseTensorProto - // when used in sparse_initializer list. - TensorProto values = 1; - - // The indices of the non-default values, which may be stored in one of two formats. - // (a) Indices can be a tensor of shape [NNZ, rank] with the [i,j]-th value - // corresponding to the j-th index of the i-th value (in the values tensor). - // (b) Indices can be a tensor of shape [NNZ], in which case the i-th value - // must be the linearized-index of the i-th value (in the values tensor). - // The linearized-index can be converted into an index tuple (k_1,...,k_rank) - // using the shape provided below. - // The indices must appear in ascending order without duplication. - // In the first format, the ordering is lexicographic-ordering: - // e.g., index-value [1,4] must appear before [2,1] - TensorProto indices = 2; - - // The shape of the underlying dense-tensor: [dim_1, dim_2, ... dim_rank] - repeated int64 dims = 3; -} - -// Defines a tensor shape. A dimension can be either an integer value -// or a symbolic variable. A symbolic variable represents an unknown -// dimension. -message TensorShapeProto { - message Dimension { - oneof value { - int64 dim_value = 1; - string dim_param = 2; // namespace Shape - }; - // Standard denotation can optionally be used to denote tensor - // dimensions with standard semantic descriptions to ensure - // that operations are applied to the correct axis of a tensor. - // Refer to https://github.com/onnx/onnx/blob/master/docs/DimensionDenotation.md#denotation-definition - // for pre-defined dimension denotations. - string denotation = 3; - }; - repeated Dimension dim = 1; -} - -// Types -// -// The standard ONNX data types. -message TypeProto { - - message Tensor { - // This field MUST NOT have the value of UNDEFINED - // This field MUST have a valid TensorProto.DataType value - // This field MUST be present for this version of the IR. - int32 elem_type = 1; - TensorShapeProto shape = 2; - } - - // repeated T - message Sequence { - // The type and optional shape of each element of the sequence. - // This field MUST be present for this version of the IR. - TypeProto elem_type = 1; - }; - - // map - message Map { - // This field MUST have a valid TensorProto.DataType value - // This field MUST be present for this version of the IR. - // This field MUST refer to an integral type ([U]INT{8|16|32|64}) or STRING - int32 key_type = 1; - // This field MUST be present for this version of the IR. - TypeProto value_type = 2; - }; - - - oneof value { - // The type of a tensor. - Tensor tensor_type = 1; - - // NOTE: DNN-only implementations of ONNX MAY elect to not support non-tensor values - // as input and output to graphs and nodes. These types are needed to naturally - // support classical ML operators. DNN operators SHOULD restrict their input - // and output types to tensors. - - // The type of a sequence. - Sequence sequence_type = 4; - - // The type of a map. - Map map_type = 5; - - } - - // An optional denotation can be used to denote the whole - // type with a standard semantic description as to what is - // stored inside. Refer to https://github.com/onnx/onnx/blob/master/docs/TypeDenotation.md#type-denotation-definition - // for pre-defined type denotations. - string denotation = 6; -} - -// Operator Sets -// -// OperatorSets are uniquely identified by a (domain, opset_version) pair. -message OperatorSetIdProto { - // The domain of the operator set being identified. - // The empty string ("") or absence of this field implies the operator - // set that is defined as part of the ONNX specification. - // This field MUST be present in this version of the IR when referring to any other operator set. - string domain = 1; - - // The version of the operator set being identified. - // This field MUST be present in this version of the IR. - int64 version = 2; -} - - -// For using protobuf-lite -//option optimize_for = LITE_RUNTIME; - diff --git a/tmva/sofie_parsers/src/ParseBasicBinary.cxx b/tmva/sofie_parsers/src/ParseBasicBinary.cxx index 4a9777cf87551..39760bdec2bc1 100644 --- a/tmva/sofie_parsers/src/ParseBasicBinary.cxx +++ b/tmva/sofie_parsers/src/ParseBasicBinary.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_BasicBinary.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseBasicIs.cxx b/tmva/sofie_parsers/src/ParseBasicIs.cxx index aa84683f69c9a..2f9fbe2e19e47 100644 --- a/tmva/sofie_parsers/src/ParseBasicIs.cxx +++ b/tmva/sofie_parsers/src/ParseBasicIs.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Basic_Is.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseBasicNary.cxx b/tmva/sofie_parsers/src/ParseBasicNary.cxx index 13e5d1ce5e5b4..51ecc9c4f143f 100644 --- a/tmva/sofie_parsers/src/ParseBasicNary.cxx +++ b/tmva/sofie_parsers/src/ParseBasicNary.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_BasicNary.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" #include namespace TMVA { diff --git a/tmva/sofie_parsers/src/ParseBasicUnary.cxx b/tmva/sofie_parsers/src/ParseBasicUnary.cxx index 4f34d600c040a..580190ab1ce83 100644 --- a/tmva/sofie_parsers/src/ParseBasicUnary.cxx +++ b/tmva/sofie_parsers/src/ParseBasicUnary.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_BasicUnary.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseBatchNormalization.cxx b/tmva/sofie_parsers/src/ParseBatchNormalization.cxx index 2c6f337ab4e72..38f326fa4f302 100644 --- a/tmva/sofie_parsers/src/ParseBatchNormalization.cxx +++ b/tmva/sofie_parsers/src/ParseBatchNormalization.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_BatchNormalization.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseCast.cxx b/tmva/sofie_parsers/src/ParseCast.cxx index fda43cfe99a7d..8eb28deddab1d 100644 --- a/tmva/sofie_parsers/src/ParseCast.cxx +++ b/tmva/sofie_parsers/src/ParseCast.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Cast.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseClip.cxx b/tmva/sofie_parsers/src/ParseClip.cxx index 57d54adda9755..a31c8f90651d4 100644 --- a/tmva/sofie_parsers/src/ParseClip.cxx +++ b/tmva/sofie_parsers/src/ParseClip.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Clip.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseComparision.cxx b/tmva/sofie_parsers/src/ParseComparision.cxx index bd1598bb5142b..cfebbad42ee6b 100644 --- a/tmva/sofie_parsers/src/ParseComparision.cxx +++ b/tmva/sofie_parsers/src/ParseComparision.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Comparision.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseConcat.cxx b/tmva/sofie_parsers/src/ParseConcat.cxx index 06d322f88c1ce..8922dbaf62555 100644 --- a/tmva/sofie_parsers/src/ParseConcat.cxx +++ b/tmva/sofie_parsers/src/ParseConcat.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Concat.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseConstant.cxx b/tmva/sofie_parsers/src/ParseConstant.cxx index 2168256bab333..649e847e9fb99 100644 --- a/tmva/sofie_parsers/src/ParseConstant.cxx +++ b/tmva/sofie_parsers/src/ParseConstant.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Constant.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseConv.cxx b/tmva/sofie_parsers/src/ParseConv.cxx index 223eeeaad2832..22931dba5cc55 100644 --- a/tmva/sofie_parsers/src/ParseConv.cxx +++ b/tmva/sofie_parsers/src/ParseConv.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Conv.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseConvTranspose.cxx b/tmva/sofie_parsers/src/ParseConvTranspose.cxx index ce0246c3b2a73..f71c945acd6aa 100644 --- a/tmva/sofie_parsers/src/ParseConvTranspose.cxx +++ b/tmva/sofie_parsers/src/ParseConvTranspose.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_ConvTranspose.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseEinsum.cxx b/tmva/sofie_parsers/src/ParseEinsum.cxx index 2612f7972a0f8..a0cfa02cb5451 100644 --- a/tmva/sofie_parsers/src/ParseEinsum.cxx +++ b/tmva/sofie_parsers/src/ParseEinsum.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Einsum.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseElu.cxx b/tmva/sofie_parsers/src/ParseElu.cxx index 5e3eb5db23ea8..a3dba3fc28740 100644 --- a/tmva/sofie_parsers/src/ParseElu.cxx +++ b/tmva/sofie_parsers/src/ParseElu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Elu.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseErf.cxx b/tmva/sofie_parsers/src/ParseErf.cxx index 7b8fc8a899b2e..1424112c1cf23 100644 --- a/tmva/sofie_parsers/src/ParseErf.cxx +++ b/tmva/sofie_parsers/src/ParseErf.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Erf.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseExpand.cxx b/tmva/sofie_parsers/src/ParseExpand.cxx index 686beb3faea0e..cd98b4bf54910 100644 --- a/tmva/sofie_parsers/src/ParseExpand.cxx +++ b/tmva/sofie_parsers/src/ParseExpand.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Expand.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseEyeLike.cxx b/tmva/sofie_parsers/src/ParseEyeLike.cxx index e7dbcf4f195a3..609ab43ed25fa 100644 --- a/tmva/sofie_parsers/src/ParseEyeLike.cxx +++ b/tmva/sofie_parsers/src/ParseEyeLike.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_EyeLike.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseFuseBatchnormRelu.cxx b/tmva/sofie_parsers/src/ParseFuseBatchnormRelu.cxx index c4a99985056b8..14413d7715e2b 100644 --- a/tmva/sofie_parsers/src/ParseFuseBatchnormRelu.cxx +++ b/tmva/sofie_parsers/src/ParseFuseBatchnormRelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_BatchNormalization.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseFuseConvAdd.cxx b/tmva/sofie_parsers/src/ParseFuseConvAdd.cxx index a3eed11d7e23e..0c81f8ef1f061 100644 --- a/tmva/sofie_parsers/src/ParseFuseConvAdd.cxx +++ b/tmva/sofie_parsers/src/ParseFuseConvAdd.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Conv.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseFuseConvTransposeAdd.cxx b/tmva/sofie_parsers/src/ParseFuseConvTransposeAdd.cxx index e29b345e1e1ee..07eb0332a00ed 100644 --- a/tmva/sofie_parsers/src/ParseFuseConvTransposeAdd.cxx +++ b/tmva/sofie_parsers/src/ParseFuseConvTransposeAdd.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_ConvTranspose.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseFuseGemmRelu.cxx b/tmva/sofie_parsers/src/ParseFuseGemmRelu.cxx index 7e35f6a655e2d..6ec777315964a 100644 --- a/tmva/sofie_parsers/src/ParseFuseGemmRelu.cxx +++ b/tmva/sofie_parsers/src/ParseFuseGemmRelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gemm.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseFuseMatMulAdd.cxx b/tmva/sofie_parsers/src/ParseFuseMatMulAdd.cxx index 7abab0f0122d4..7d9edce66f74c 100644 --- a/tmva/sofie_parsers/src/ParseFuseMatMulAdd.cxx +++ b/tmva/sofie_parsers/src/ParseFuseMatMulAdd.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gemm.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseGRU.cxx b/tmva/sofie_parsers/src/ParseGRU.cxx index cd1b3366cb728..5ea8c4cf0dc04 100644 --- a/tmva/sofie_parsers/src/ParseGRU.cxx +++ b/tmva/sofie_parsers/src/ParseGRU.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_GRU.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseGather.cxx b/tmva/sofie_parsers/src/ParseGather.cxx index 1881bc9e26805..a050757812e4d 100644 --- a/tmva/sofie_parsers/src/ParseGather.cxx +++ b/tmva/sofie_parsers/src/ParseGather.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gather.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" #include namespace TMVA { diff --git a/tmva/sofie_parsers/src/ParseGatherND.cxx b/tmva/sofie_parsers/src/ParseGatherND.cxx index 638c778bcc091..48a0930a9e9d1 100644 --- a/tmva/sofie_parsers/src/ParseGatherND.cxx +++ b/tmva/sofie_parsers/src/ParseGatherND.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_GatherND.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" #include namespace TMVA { diff --git a/tmva/sofie_parsers/src/ParseGelu.cxx b/tmva/sofie_parsers/src/ParseGelu.cxx index 28b15931587e9..e70c24aeecf91 100644 --- a/tmva/sofie_parsers/src/ParseGelu.cxx +++ b/tmva/sofie_parsers/src/ParseGelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gelu.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseGemm.cxx b/tmva/sofie_parsers/src/ParseGemm.cxx index db54fa1e4026c..b7474f2e9e296 100644 --- a/tmva/sofie_parsers/src/ParseGemm.cxx +++ b/tmva/sofie_parsers/src/ParseGemm.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gemm.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseHardSigmoid.cxx b/tmva/sofie_parsers/src/ParseHardSigmoid.cxx index 3d3222cf7c30b..259acf37a89a8 100644 --- a/tmva/sofie_parsers/src/ParseHardSigmoid.cxx +++ b/tmva/sofie_parsers/src/ParseHardSigmoid.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_HardSigmoid.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseHardSwish.cxx b/tmva/sofie_parsers/src/ParseHardSwish.cxx index c04bdb215efc5..b7d46bd8bec76 100644 --- a/tmva/sofie_parsers/src/ParseHardSwish.cxx +++ b/tmva/sofie_parsers/src/ParseHardSwish.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_HardSwish.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseIdentity.cxx b/tmva/sofie_parsers/src/ParseIdentity.cxx index 4e9b6c63c280d..b104a0d2616b6 100644 --- a/tmva/sofie_parsers/src/ParseIdentity.cxx +++ b/tmva/sofie_parsers/src/ParseIdentity.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Identity.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseIf.cxx b/tmva/sofie_parsers/src/ParseIf.cxx index e8d744d6ea39a..7ddc6c95b4b89 100644 --- a/tmva/sofie_parsers/src/ParseIf.cxx +++ b/tmva/sofie_parsers/src/ParseIf.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_SubGraph.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseInstanceNormalization.cxx b/tmva/sofie_parsers/src/ParseInstanceNormalization.cxx index 540d1a082b8a4..8034029ba1bb0 100644 --- a/tmva/sofie_parsers/src/ParseInstanceNormalization.cxx +++ b/tmva/sofie_parsers/src/ParseInstanceNormalization.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_InstanceNormalization.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseLSTM.cxx b/tmva/sofie_parsers/src/ParseLSTM.cxx index a699513c27751..830d92f8cce12 100644 --- a/tmva/sofie_parsers/src/ParseLSTM.cxx +++ b/tmva/sofie_parsers/src/ParseLSTM.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_LSTM.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseLayerNormalization.cxx b/tmva/sofie_parsers/src/ParseLayerNormalization.cxx index d7c773ce47a58..f4961429c09fd 100644 --- a/tmva/sofie_parsers/src/ParseLayerNormalization.cxx +++ b/tmva/sofie_parsers/src/ParseLayerNormalization.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_LayerNormalization.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseLeakyRelu.cxx b/tmva/sofie_parsers/src/ParseLeakyRelu.cxx index 6f33c6444e64e..7619d0880e397 100644 --- a/tmva/sofie_parsers/src/ParseLeakyRelu.cxx +++ b/tmva/sofie_parsers/src/ParseLeakyRelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_LeakyRelu.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseMatMul.cxx b/tmva/sofie_parsers/src/ParseMatMul.cxx index 2c43c351e4c28..d156fbbb5a452 100644 --- a/tmva/sofie_parsers/src/ParseMatMul.cxx +++ b/tmva/sofie_parsers/src/ParseMatMul.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Gemm.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseNonZero.cxx b/tmva/sofie_parsers/src/ParseNonZero.cxx index f3ec5ccd08a3e..f768159b98292 100644 --- a/tmva/sofie_parsers/src/ParseNonZero.cxx +++ b/tmva/sofie_parsers/src/ParseNonZero.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_NonZero.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseNot.cxx b/tmva/sofie_parsers/src/ParseNot.cxx index b9e043e8b83b4..f08694872148c 100644 --- a/tmva/sofie_parsers/src/ParseNot.cxx +++ b/tmva/sofie_parsers/src/ParseNot.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Not.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParsePad.cxx b/tmva/sofie_parsers/src/ParsePad.cxx index 9b7f4dde2e8a7..99bffd6a03767 100644 --- a/tmva/sofie_parsers/src/ParsePad.cxx +++ b/tmva/sofie_parsers/src/ParsePad.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Pad.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParsePool.cxx b/tmva/sofie_parsers/src/ParsePool.cxx index 031f24c66354d..76a6497bf5cad 100644 --- a/tmva/sofie_parsers/src/ParsePool.cxx +++ b/tmva/sofie_parsers/src/ParsePool.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Pool.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseRNN.cxx b/tmva/sofie_parsers/src/ParseRNN.cxx index f051f70c5f6c3..d0ee81dd4b416 100644 --- a/tmva/sofie_parsers/src/ParseRNN.cxx +++ b/tmva/sofie_parsers/src/ParseRNN.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_RNN.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseRandom.cxx b/tmva/sofie_parsers/src/ParseRandom.cxx index f1728b177611d..e72f2968c9fd8 100644 --- a/tmva/sofie_parsers/src/ParseRandom.cxx +++ b/tmva/sofie_parsers/src/ParseRandom.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Random.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseRange.cxx b/tmva/sofie_parsers/src/ParseRange.cxx index c12212187c6d5..a26a0b81f0df5 100644 --- a/tmva/sofie_parsers/src/ParseRange.cxx +++ b/tmva/sofie_parsers/src/ParseRange.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Range.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseReduce.cxx b/tmva/sofie_parsers/src/ParseReduce.cxx index 1753979cfa7bb..e096458c48999 100644 --- a/tmva/sofie_parsers/src/ParseReduce.cxx +++ b/tmva/sofie_parsers/src/ParseReduce.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Reduce.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" #include namespace TMVA { diff --git a/tmva/sofie_parsers/src/ParseRelu.cxx b/tmva/sofie_parsers/src/ParseRelu.cxx index fe54295ce1c1d..5f545cb819673 100644 --- a/tmva/sofie_parsers/src/ParseRelu.cxx +++ b/tmva/sofie_parsers/src/ParseRelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Relu.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseReshape.cxx b/tmva/sofie_parsers/src/ParseReshape.cxx index ddb316ca837a4..50dcb4ba8507c 100644 --- a/tmva/sofie_parsers/src/ParseReshape.cxx +++ b/tmva/sofie_parsers/src/ParseReshape.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Reshape.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseScatterElements.cxx b/tmva/sofie_parsers/src/ParseScatterElements.cxx index dd29cc7bbbd2d..02c9998ea329d 100644 --- a/tmva/sofie_parsers/src/ParseScatterElements.cxx +++ b/tmva/sofie_parsers/src/ParseScatterElements.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_ScatterElements.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseScatterND.cxx b/tmva/sofie_parsers/src/ParseScatterND.cxx index 236725a4910a5..fd138114aea76 100644 --- a/tmva/sofie_parsers/src/ParseScatterND.cxx +++ b/tmva/sofie_parsers/src/ParseScatterND.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_ScatterND.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSelu.cxx b/tmva/sofie_parsers/src/ParseSelu.cxx index 9866f94224de2..87993252035f6 100644 --- a/tmva/sofie_parsers/src/ParseSelu.cxx +++ b/tmva/sofie_parsers/src/ParseSelu.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Selu.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseShape.cxx b/tmva/sofie_parsers/src/ParseShape.cxx index 617c607f8068c..8211c677d748b 100644 --- a/tmva/sofie_parsers/src/ParseShape.cxx +++ b/tmva/sofie_parsers/src/ParseShape.cxx @@ -1,6 +1,8 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Shape.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" + +#include // for INT_MAX namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSigmoid.cxx b/tmva/sofie_parsers/src/ParseSigmoid.cxx index e498cbcb8c60b..13262e70a8149 100644 --- a/tmva/sofie_parsers/src/ParseSigmoid.cxx +++ b/tmva/sofie_parsers/src/ParseSigmoid.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Sigmoid.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSlice.cxx b/tmva/sofie_parsers/src/ParseSlice.cxx index 2b6f38e316ada..e051c2e747e47 100644 --- a/tmva/sofie_parsers/src/ParseSlice.cxx +++ b/tmva/sofie_parsers/src/ParseSlice.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Slice.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSoftmax.cxx b/tmva/sofie_parsers/src/ParseSoftmax.cxx index bc53162ab471a..1a3f3c324b4f6 100644 --- a/tmva/sofie_parsers/src/ParseSoftmax.cxx +++ b/tmva/sofie_parsers/src/ParseSoftmax.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Softmax.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSplit.cxx b/tmva/sofie_parsers/src/ParseSplit.cxx index dc23796d65d56..636c2098b74d6 100644 --- a/tmva/sofie_parsers/src/ParseSplit.cxx +++ b/tmva/sofie_parsers/src/ParseSplit.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Split.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseSwish.cxx b/tmva/sofie_parsers/src/ParseSwish.cxx index 366b410fd5f2c..c265db4465213 100644 --- a/tmva/sofie_parsers/src/ParseSwish.cxx +++ b/tmva/sofie_parsers/src/ParseSwish.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Swish.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseTanh.cxx b/tmva/sofie_parsers/src/ParseTanh.cxx index 5848d7fdf6f21..6d07b5d00a19b 100644 --- a/tmva/sofie_parsers/src/ParseTanh.cxx +++ b/tmva/sofie_parsers/src/ParseTanh.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Tanh.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseTile.cxx b/tmva/sofie_parsers/src/ParseTile.cxx index c93f2e3d1e5e9..7796ea9ec0e52 100644 --- a/tmva/sofie_parsers/src/ParseTile.cxx +++ b/tmva/sofie_parsers/src/ParseTile.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Tile.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseTopK.cxx b/tmva/sofie_parsers/src/ParseTopK.cxx index f16bbfa979378..b750bd2a6ed4f 100644 --- a/tmva/sofie_parsers/src/ParseTopK.cxx +++ b/tmva/sofie_parsers/src/ParseTopK.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_TopK.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseTranspose.cxx b/tmva/sofie_parsers/src/ParseTranspose.cxx index 0023021cbdfe3..7ed3656974b8b 100644 --- a/tmva/sofie_parsers/src/ParseTranspose.cxx +++ b/tmva/sofie_parsers/src/ParseTranspose.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Transpose.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/ParseWhere.cxx b/tmva/sofie_parsers/src/ParseWhere.cxx index dc4b436282cab..f6b6220b2156c 100644 --- a/tmva/sofie_parsers/src/ParseWhere.cxx +++ b/tmva/sofie_parsers/src/ParseWhere.cxx @@ -1,6 +1,6 @@ #include "TMVA/RModelParser_ONNX.hxx" #include "TMVA/ROperator_Where.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" namespace TMVA { namespace Experimental { diff --git a/tmva/sofie_parsers/src/RModelParser_ONNX.cxx b/tmva/sofie_parsers/src/RModelParser_ONNX.cxx index 5249f97338169..162aa8de9d11d 100644 --- a/tmva/sofie_parsers/src/RModelParser_ONNX.cxx +++ b/tmva/sofie_parsers/src/RModelParser_ONNX.cxx @@ -1,7 +1,8 @@ #include "Byteswap.h" #include "TMVA/RModelParser_ONNX.hxx" -#include "onnx_proto3.pb.h" +#include "onnx.hxx" +#include #include #include #include @@ -128,8 +129,8 @@ struct ExtractDataFromTP { static void Copy(onnx::TensorProto * tensor, void * data, int length) { if (tensor->float_data_size() != length) throw std::runtime_error("TMVA::SOFIE - Failed to read float initialized tensor - actual size is " + std::to_string(tensor->float_data_size())); - tensor->mutable_float_data()->ExtractSubrange(0, tensor->float_data_size(), - static_cast(data)); + const auto &src = tensor->float_data(); + std::copy(src.begin(), src.end(), static_cast(data)); } }; template<> @@ -137,8 +138,8 @@ struct ExtractDataFromTP { static void Copy(onnx::TensorProto * tensor, void * data, int length) { if (tensor->double_data_size() != length) throw std::runtime_error("TMVA::SOFIE - Failed to read double initialized tensor - actual size is " + std::to_string(tensor->double_data_size())); - tensor->mutable_double_data()->ExtractSubrange(0, tensor->double_data_size(), - static_cast(data)); + const auto &src = tensor->double_data(); + std::copy(src.begin(), src.end(), static_cast(data)); } }; template<> @@ -146,8 +147,8 @@ struct ExtractDataFromTP { static void Copy(onnx::TensorProto * tensor, void * data, int length) { if (tensor->int32_data_size() != length) throw std::runtime_error("TMVA::SOFIE - Failed to read int32 initialized tensor - actual size is " + std::to_string(tensor->int32_data_size())); - tensor->mutable_int32_data()->ExtractSubrange(0, tensor->int32_data_size(), - static_cast(data)); + const auto &src = tensor->int32_data(); + std::copy(src.begin(), src.end(), static_cast(data)); } }; template<> @@ -155,8 +156,8 @@ struct ExtractDataFromTP { static void Copy(onnx::TensorProto * tensor, void * data, int length) { if (tensor->int64_data_size() != length) throw std::runtime_error("TMVA::SOFIE - Failed to read int64 initialized tensor - actual size is " + std::to_string(tensor->int64_data_size())); - tensor->mutable_int64_data()->ExtractSubrange(0, tensor->int64_data_size(), - static_cast(data)); + const auto &src = tensor->int64_data(); + std::copy(src.begin(), src.end(), static_cast(data)); } }; @@ -576,8 +577,8 @@ std::unique_ptr RModelParser_ONNX::LoadModel(const std::string return LoadModel(input); } -std::unique_ptr RModelParser_ONNX::LoadModel(std::istream &input) { - GOOGLE_PROTOBUF_VERIFY_VERSION; +std::unique_ptr RModelParser_ONNX::LoadModel(std::istream &input) +{ auto model = std::make_unique(); if (!model->ParseFromIstream(&input)) { @@ -589,9 +590,7 @@ std::unique_ptr RModelParser_ONNX::LoadModel(std::istream &inp if (fVerbose) { std::cout << "ONNX Version " << model->ir_version() << std::endl; } - google::protobuf::ShutdownProtobufLibrary(); return model; - } void RModelParser_ONNX::CheckGraph(const onnx::GraphProto & graph, int & level, std::map & missingOperators) { diff --git a/tmva/sofie_parsers/src/onnx.hxx b/tmva/sofie_parsers/src/onnx.hxx new file mode 100644 index 0000000000000..df7c3e8a672b1 --- /dev/null +++ b/tmva/sofie_parsers/src/onnx.hxx @@ -0,0 +1,663 @@ +// TMVA SOFIE — minimal, dependency-free ONNX protobuf reader. +// +// Drop-in replacement for the protoc-generated onnx_proto3.pb.h. Provides the +// subset of the onnx:: message API that the SOFIE ONNX parser actually uses, +// backed by a hand-written protobuf wire-format decoder. No libprotobuf, no +// protoc, no codegen. +// +// Only the read-side accessors used by RModelParser_ONNX and the Parse*.cxx +// operator parsers are implemented. + +#ifndef TMVA_SOFIE_ONNX_LITE +#define TMVA_SOFIE_ONNX_LITE + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace onnx { + +// --------------------------------------------------------------------------- +// Protobuf wire-format reader (proto3 subset: varint, 64-bit, len, 32-bit) +// --------------------------------------------------------------------------- +namespace detail { + +enum WireType { + WT_VARINT = 0, + WT_I64 = 1, + WT_LEN = 2, + WT_I32 = 5 +}; + +class WireReader { + const uint8_t *fP; + const uint8_t *fEnd; + bool fOk = true; + +public: + WireReader(const char *data, std::size_t n) : fP(reinterpret_cast(data)), fEnd(fP + n) {} + + bool ok() const { return fOk; } + bool eof() const { return fP >= fEnd; } + + uint64_t ReadVarint() + { + uint64_t result = 0; + int shift = 0; + while (fP < fEnd && shift < 64) { + uint8_t b = *fP++; + result |= uint64_t(b & 0x7F) << shift; + if (!(b & 0x80)) + return result; + shift += 7; + } + fOk = false; + return result; + } + + // Fixed-width fields are little-endian on the wire. Assemble them byte-wise + // so the result is a correct host-order value on both little- and big-endian + // machines (ROOT CI covers big-endian s390x). Varints need no such handling. + uint32_t ReadFixed32() + { + if (fP + 4 > fEnd) { + fOk = false; + return 0; + } + uint32_t v = uint32_t(fP[0]) | (uint32_t(fP[1]) << 8) | (uint32_t(fP[2]) << 16) | (uint32_t(fP[3]) << 24); + fP += 4; + return v; + } + + uint64_t ReadFixed64() + { + if (fP + 8 > fEnd) { + fOk = false; + return 0; + } + uint64_t v = 0; + for (int k = 0; k < 8; ++k) + v |= uint64_t(fP[k]) << (8 * k); + fP += 8; + return v; + } + + // Length-delimited payload returned as a (ptr,len) view into the buffer. + std::pair ReadLen() + { + uint64_t n = ReadVarint(); + if (fP + n > fEnd) { + fOk = false; + return {nullptr, 0}; + } + auto ptr = reinterpret_cast(fP); + fP += n; + return {ptr, std::size_t(n)}; + } + + bool ReadTag(uint32_t &field, uint32_t &wire) + { + if (eof()) + return false; + uint64_t tag = ReadVarint(); + if (!fOk) + return false; + field = uint32_t(tag >> 3); + wire = uint32_t(tag & 7); + return true; + } + + void SkipField(uint32_t wire) + { + switch (wire) { + case WT_VARINT: ReadVarint(); break; + case WT_I64: ReadFixed64(); break; + case WT_LEN: ReadLen(); break; + case WT_I32: ReadFixed32(); break; + default: fOk = false; break; // groups (3,4) unsupported / not used by ONNX + } + } +}; + +// Read a repeated numeric field that may be packed (single WT_LEN block) or +// written as individual entries. +inline void ReadPackedVarint(WireReader &r, uint32_t wire, std::vector &out) +{ + if (wire == WT_LEN) { + auto s = r.ReadLen(); + WireReader rr(s.first, s.second); + while (!rr.eof()) + out.push_back(int64_t(rr.ReadVarint())); + } else { + out.push_back(int64_t(r.ReadVarint())); + } +} +inline void ReadPackedI32(WireReader &r, uint32_t wire, std::vector &out) +{ + if (wire == WT_LEN) { + auto s = r.ReadLen(); + WireReader rr(s.first, s.second); + while (!rr.eof()) + out.push_back(int32_t(rr.ReadVarint())); + } else { + out.push_back(int32_t(r.ReadVarint())); + } +} +inline void ReadPackedFloat(WireReader &r, uint32_t wire, std::vector &out) +{ + auto one = [](uint32_t bits) { + float f; + std::memcpy(&f, &bits, 4); + return f; + }; + if (wire == WT_LEN) { + auto s = r.ReadLen(); + WireReader rr(s.first, s.second); + while (!rr.eof()) + out.push_back(one(rr.ReadFixed32())); + } else { + out.push_back(one(r.ReadFixed32())); + } +} +inline void ReadPackedDouble(WireReader &r, uint32_t wire, std::vector &out) +{ + auto one = [](uint64_t bits) { + double d; + std::memcpy(&d, &bits, 8); + return d; + }; + if (wire == WT_LEN) { + auto s = r.ReadLen(); + WireReader rr(s.first, s.second); + while (!rr.eof()) + out.push_back(one(rr.ReadFixed64())); + } else { + out.push_back(one(r.ReadFixed64())); + } +} + +inline std::string Str(std::pair v) +{ + return std::string(v.first, v.second); +} + +} // namespace detail + +// --------------------------------------------------------------------------- +// Message types (subset). Each exposes the generated-protobuf-style accessors. +// --------------------------------------------------------------------------- + +class GraphProto; // fwd +class TensorProto; // fwd + +// --- TensorShapeProto::Dimension (flattened name: TensorShapeProto_Dimension) +class TensorShapeProto_Dimension { +public: + enum class ValueCase { + VALUE_NOT_SET = 0, + kDimValue = 1, + kDimParam = 2 + }; + + ValueCase value_case() const { return fCase; } + int64_t dim_value() const { return fDimValue; } + const std::string &dim_param() const { return fDimParam; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: + fDimValue = int64_t(r.ReadVarint()); + fCase = ValueCase::kDimValue; + break; + case 2: + fDimParam = detail::Str(r.ReadLen()); + fCase = ValueCase::kDimParam; + break; + default: r.SkipField(wt); break; + } + } + } + +private: + ValueCase fCase = ValueCase::VALUE_NOT_SET; + int64_t fDimValue = 0; + std::string fDimParam; +}; + +class TensorShapeProto { +public: + int dim_size() const { return int(fDim.size()); } + const TensorShapeProto_Dimension &dim(int i) const { return fDim[i]; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + if (f == 1 && wt == detail::WT_LEN) { + auto s = r.ReadLen(); + fDim.emplace_back(); + fDim.back().ParseFrom(detail::WireReader(s.first, s.second)); + } else { + r.SkipField(wt); + } + } + } + +private: + std::vector fDim; +}; + +// TypeProto::Tensor +class TypeProto_Tensor { +public: + int elem_type() const { return fElemType; } + bool has_shape() const { return fHasShape; } + const TensorShapeProto &shape() const { return fShape; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fElemType = int(r.ReadVarint()); break; + case 2: { + auto s = r.ReadLen(); + fShape.ParseFrom(detail::WireReader(s.first, s.second)); + fHasShape = true; + break; + } + default: r.SkipField(wt); break; + } + } + } + +private: + int fElemType = 0; + bool fHasShape = false; + TensorShapeProto fShape; +}; + +class TypeProto { +public: + const TypeProto_Tensor &tensor_type() const { return fTensorType; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + if (f == 1 && wt == detail::WT_LEN) { // tensor_type + auto s = r.ReadLen(); + fTensorType.ParseFrom(detail::WireReader(s.first, s.second)); + } else { + r.SkipField(wt); + } + } + } + +private: + TypeProto_Tensor fTensorType; +}; + +class ValueInfoProto { +public: + const std::string &name() const { return fName; } + const TypeProto &type() const { return fType; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fName = detail::Str(r.ReadLen()); break; + case 2: { + auto s = r.ReadLen(); + fType.ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + default: r.SkipField(wt); break; + } + } + } + +private: + std::string fName; + TypeProto fType; +}; + +class StringStringEntryProto { +public: + const std::string &key() const { return fKey; } + const std::string &value() const { return fValue; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fKey = detail::Str(r.ReadLen()); break; + case 2: fValue = detail::Str(r.ReadLen()); break; + default: r.SkipField(wt); break; + } + } + } + +private: + std::string fKey, fValue; +}; + +class TensorProto { +public: + enum DataType { + UNDEFINED = 0, + FLOAT = 1, + UINT8 = 2, + INT8 = 3, + UINT16 = 4, + INT16 = 5, + INT32 = 6, + INT64 = 7, + STRING = 8, + BOOL = 9, + FLOAT16 = 10, + DOUBLE = 11, + UINT32 = 12, + UINT64 = 13, + COMPLEX64 = 14, + COMPLEX128 = 15, + BFLOAT16 = 16 + }; + enum DataLocation { + DEFAULT = 0, + EXTERNAL = 1 + }; + + const std::string &name() const { return fName; } + int data_type() const { return fDataType; } + int dims_size() const { return int(fDims.size()); } + int64_t dims(int i) const { return fDims[i]; } + const std::string &raw_data() const { return fRawData; } + DataLocation data_location() const { return fDataLocation; } + const std::vector &external_data() const { return fExternalData; } + + int float_data_size() const { return int(fFloatData.size()); } + int double_data_size() const { return int(fDoubleData.size()); } + int int32_data_size() const { return int(fInt32Data.size()); } + int int64_data_size() const { return int(fInt64Data.size()); } + const std::vector &float_data() const { return fFloatData; } + const std::vector &double_data() const { return fDoubleData; } + const std::vector &int32_data() const { return fInt32Data; } + const std::vector &int64_data() const { return fInt64Data; } + // Indexed element accessors (the generated protobuf API exposes both forms). + float float_data(int i) const { return fFloatData[i]; } + double double_data(int i) const { return fDoubleData[i]; } + int32_t int32_data(int i) const { return fInt32Data[i]; } + int64_t int64_data(int i) const { return fInt64Data[i]; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: detail::ReadPackedVarint(r, wt, fDims); break; + case 2: fDataType = int(r.ReadVarint()); break; + case 4: detail::ReadPackedFloat(r, wt, fFloatData); break; + case 5: detail::ReadPackedI32(r, wt, fInt32Data); break; + case 7: detail::ReadPackedVarint(r, wt, fInt64Data); break; + case 8: fName = detail::Str(r.ReadLen()); break; + case 9: fRawData = detail::Str(r.ReadLen()); break; + case 10: detail::ReadPackedDouble(r, wt, fDoubleData); break; + case 13: { + auto s = r.ReadLen(); + fExternalData.emplace_back(); + fExternalData.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + case 14: fDataLocation = DataLocation(r.ReadVarint()); break; + default: r.SkipField(wt); break; + } + } + } + +private: + std::string fName; + int fDataType = 0; + std::vector fDims; + std::string fRawData; + DataLocation fDataLocation = DEFAULT; + std::vector fExternalData; + std::vector fFloatData; + std::vector fDoubleData; + std::vector fInt32Data; + std::vector fInt64Data; +}; + +class AttributeProto { +public: + enum AttributeType { + UNDEFINED = 0, + FLOAT = 1, + INT = 2, + STRING = 3, + TENSOR = 4, + GRAPH = 5, + FLOATS = 6, + INTS = 7, + STRINGS = 8, + TENSORS = 9, + GRAPHS = 10, + SPARSE_TENSOR = 11, + SPARSE_TENSORS = 12 + }; + + const std::string &name() const { return fName; } + AttributeType type() const { return fType; } + float f() const { return fF; } + int64_t i() const { return fI; } + const std::string &s() const { return fS; } + const TensorProto &t() const { return fT; } + const GraphProto &g() const; // defined after GraphProto + bool has_g() const { return fHasG; } + bool has_t() const { return fHasT; } + + const std::vector &floats() const { return fFloats; } + const std::vector &ints() const { return fInts; } + const std::vector &strings() const { return fStrings; } + + void ParseFrom(detail::WireReader r); // defined after GraphProto (needs g()) + +private: + std::string fName; + AttributeType fType = UNDEFINED; + float fF = 0.f; + int64_t fI = 0; + std::string fS; + bool fHasG = false, fHasT = false; + std::vector fFloats; + std::vector fInts; + std::vector fStrings; + TensorProto fT; + // graph attribute held by shared_ptr to break the cyclic type dependency + // (a subgraph contains nodes, whose attributes may again hold subgraphs) + std::shared_ptr fG; +}; + +class NodeProto { +public: + const std::string &op_type() const { return fOpType; } + const std::string &name() const { return fName; } + int input_size() const { return int(fInput.size()); } + const std::string &input(int i) const { return fInput[i]; } + const std::vector &input() const { return fInput; } + int output_size() const { return int(fOutput.size()); } + const std::string &output(int i) const { return fOutput[i]; } + const std::vector &output() const { return fOutput; } + int attribute_size() const { return int(fAttribute.size()); } + const AttributeProto &attribute(int i) const { return fAttribute[i]; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fInput.push_back(detail::Str(r.ReadLen())); break; + case 2: fOutput.push_back(detail::Str(r.ReadLen())); break; + case 3: fName = detail::Str(r.ReadLen()); break; + case 4: fOpType = detail::Str(r.ReadLen()); break; + case 5: { + auto s = r.ReadLen(); + fAttribute.emplace_back(); + fAttribute.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + default: r.SkipField(wt); break; + } + } + } + +private: + std::vector fInput, fOutput; + std::string fName, fOpType; + std::vector fAttribute; +}; + +class GraphProto { +public: + const std::string &name() const { return fName; } + int node_size() const { return int(fNode.size()); } + const NodeProto &node(int i) const { return fNode[i]; } + int input_size() const { return int(fInput.size()); } + const ValueInfoProto &input(int i) const { return fInput[i]; } + int output_size() const { return int(fOutput.size()); } + const ValueInfoProto &output(int i) const { return fOutput[i]; } + int initializer_size() const { return int(fInitializer.size()); } + const TensorProto &initializer(int i) const { return fInitializer[i]; } + + void ParseFrom(detail::WireReader r) + { + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: { + auto s = r.ReadLen(); + fNode.emplace_back(); + fNode.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + case 2: fName = detail::Str(r.ReadLen()); break; + case 5: { + auto s = r.ReadLen(); + fInitializer.emplace_back(); + fInitializer.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + case 11: { + auto s = r.ReadLen(); + fInput.emplace_back(); + fInput.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + case 12: { + auto s = r.ReadLen(); + fOutput.emplace_back(); + fOutput.back().ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + default: r.SkipField(wt); break; + } + } + } + +private: + std::string fName; + std::vector fNode; + std::vector fInitializer; + std::vector fInput, fOutput; +}; + +// --- AttributeProto members that depend on the complete GraphProto type ------ +inline const GraphProto &AttributeProto::g() const +{ + return *fG; +} + +inline void AttributeProto::ParseFrom(detail::WireReader r) +{ + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fName = detail::Str(r.ReadLen()); break; + case 2: { + uint32_t bits = r.ReadFixed32(); + std::memcpy(&fF, &bits, 4); + break; + } + case 3: fI = int64_t(r.ReadVarint()); break; + case 4: fS = detail::Str(r.ReadLen()); break; + case 5: { + auto s = r.ReadLen(); + fT.ParseFrom(detail::WireReader(s.first, s.second)); + fHasT = true; + break; + } + case 6: { + auto s = r.ReadLen(); + fG = std::make_shared(); + fG->ParseFrom(detail::WireReader(s.first, s.second)); + fHasG = true; + break; + } + case 7: detail::ReadPackedFloat(r, wt, fFloats); break; + case 8: detail::ReadPackedVarint(r, wt, fInts); break; + case 9: fStrings.push_back(detail::Str(r.ReadLen())); break; + case 20: fType = AttributeType(r.ReadVarint()); break; + default: r.SkipField(wt); break; + } + } +} + +class ModelProto { +public: + int64_t ir_version() const { return fIrVersion; } + const std::string &producer_name() const { return fProducerName; } + const GraphProto &graph() const { return fGraph; } + + bool ParseFromIstream(std::istream *in) + { + std::ostringstream ss; + ss << in->rdbuf(); + fBuffer = ss.str(); + detail::WireReader r(fBuffer.data(), fBuffer.size()); + uint32_t f, wt; + while (r.ReadTag(f, wt)) { + switch (f) { + case 1: fIrVersion = int64_t(r.ReadVarint()); break; + case 2: fProducerName = detail::Str(r.ReadLen()); break; + case 7: { + auto s = r.ReadLen(); + fGraph.ParseFrom(detail::WireReader(s.first, s.second)); + break; + } + default: r.SkipField(wt); break; + } + } + return r.ok(); + } + +private: + std::string fBuffer; + int64_t fIrVersion = 0; + std::string fProducerName; + GraphProto fGraph; +}; + +} // namespace onnx + +#endif diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 24294904e2562..8e99a4b27ba2d 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -368,14 +368,14 @@ else() list(APPEND tmva_veto machine_learning/TMVA_SOFIE_RSofieReader.C) endif() # These SOFIE tutorials take models trained via PyMVA-PyKeras as input - if (NOT tmva-sofie OR NOT ROOT_KERAS_FOUND) + if (NOT ROOT_KERAS_FOUND) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_Keras.py) endif() - if (NOT tmva-sofie OR NOT ROOT_TORCH_FOUND) + if (NOT ROOT_TORCH_FOUND) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_PyTorch.py) endif() # These SOFIE tutorials take the ONNX HiggsModel trained with PyTorch as input - if (NOT tmva-sofie OR NOT ROOT_TORCH_FOUND OR NOT ROOT_ONNX_FOUND) + if (NOT ROOT_TORCH_FOUND OR NOT ROOT_ONNX_FOUND) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_ONNX.py) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_Models.py) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_PyTorch_HiggsModel.py) @@ -391,7 +391,7 @@ else() list(APPEND tmva_veto machine_learning/TMVA_SOFIE_GNN.py) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_GNN_Application.C) endif() - if (NOT tmva-sofie OR NOT ROOT_ONNX_FOUND) + if (NOT ROOT_ONNX_FOUND) list(APPEND tmva_veto machine_learning/TMVA_SOFIE_ONNX.C) else() #generate ONNX file needed for the tutorial