Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RModelParser_ONNX.cxx
Go to the documentation of this file.
1#include "Byteswap.h"
3#include "onnx_proto3.pb.h"
4
5#include <stdexcept>
6#include <string>
7#include <memory>
8#include <cassert>
9#include <iostream>
10#include <unordered_map>
11#include <functional>
12#include "TMVA/SOFIE_common.hxx"
13
14namespace TMVA {
15namespace Experimental {
16namespace SOFIE {
17
18// Declaration of operators
19// Unary operators
28// Binary operators
34// Nary operators
39//Comparision Operators
45// Reduce operators
50// Others
90// Declaration of fused operators
96
97// Definition of RModelParser_ONNX::OperatorsMap
99 // Registered operators
100 std::unordered_map<std::string, ParserFuncSignature> fOperatorsMap;
101};
102
103// helper function to get initialized tensor data
104template<typename T>
106};
107// trait function to extract data from TensorProto
108template<>
109struct ExtractDataFromTP<float> {
110 static void Copy(onnx::TensorProto * tensor, void * data) {
111 tensor->mutable_float_data()->ExtractSubrange(0, tensor->float_data_size(),
112 static_cast<float *>(data));
113 }
114};
115template<>
117 static void Copy(onnx::TensorProto * tensor, void * data) {
118 tensor->mutable_double_data()->ExtractSubrange(0, tensor->double_data_size(),
119 static_cast<double *>(data));
120 }
121};
122template<>
123struct ExtractDataFromTP<int32_t> {
124 static void Copy(onnx::TensorProto * tensor, void * data) {
125 tensor->mutable_int32_data()->ExtractSubrange(0, tensor->int32_data_size(),
126 static_cast<int32_t *>(data));
127 }
128};
129template<>
130struct ExtractDataFromTP<int64_t> {
131 static void Copy(onnx::TensorProto * tensor, void * data) {
132 tensor->mutable_int64_data()->ExtractSubrange(0, tensor->int64_data_size(),
133 static_cast<int64_t *>(data));
134 }
135};
136template<typename T>
137std::shared_ptr<void> GetInitializedTensorData(onnx::TensorProto * tensorproto, size_t length) {
138 std::shared_ptr<void> data(malloc(length * sizeof(T)), free);
139
140 if (!tensorproto->raw_data().empty()) {
141#ifdef R__BYTESWAP
142 std::memcpy(data.get(), tensorproto->raw_data().c_str(), length * sizeof(T));
143#else
144 for (std::size_t k = 0; k < length; ++k)
145 (reinterpret_cast<typename RByteSwap<sizeof(T)>::value_type *>(data.get()))[k] =
146 RByteSwap<sizeof(T)>::bswap((reinterpret_cast<const typename RByteSwap<sizeof(T)>::value_type *>(tensorproto->raw_data().c_str()))[k]);
147#endif
148 } else {
150 }
151 return data;
152}
153
154// Constructor of the parser
155RModelParser_ONNX::RModelParser_ONNX() noexcept : fOperatorsMapImpl(std::make_unique<OperatorsMapImpl>()) {
156 // Register operators
157 // Unary operators
159 RegisterOperator("Reciprocal", ParseReciprocal);
166 // Binary operators
172 // Nary operators
177 //Comparision Operators
178 RegisterOperator("Equal", ParseEq);
180 RegisterOperator("LessOrEqual", ParseLessEq);
181 RegisterOperator("Greater", ParseGreater);
182 RegisterOperator("GreaterOrEqual", ParseGreaterEq);
183 // Reduce operators
184 RegisterOperator("ReduceMean", ParseReduceMean);
185 RegisterOperator("ReduceSum", ParseReduceSum);
186 RegisterOperator("ReduceSumSquare", ParseReduceSumSquare);
187 RegisterOperator("ReduceProd", ParseReduceProd);
188 // Others
189 RegisterOperator("BatchNormalization", ParseBatchNormalization);
190 RegisterOperator("Constant", ParseConstant);
191 RegisterOperator("ConstantOfShape", ParseConstant);
193 RegisterOperator("Concat", ParseConcat);
195 RegisterOperator("ConvTranspose", ParseConvTranspose);
198 RegisterOperator("Identity", ParseIdentity);
199 RegisterOperator("LeakyRelu", ParseLeakyRelu);
201 RegisterOperator("AveragePool", ParsePool);
202 RegisterOperator("GlobalAveragePool", ParsePool);
203 RegisterOperator("MaxPool", ParsePool);
205 RegisterOperator("Reshape", ParseReshape);
206 RegisterOperator("Flatten", ParseReshape);
207 RegisterOperator("Squeeze", ParseReshape);
208 RegisterOperator("Unsqueeze", ParseReshape);
212 RegisterOperator("Sigmoid", ParseSigmoid);
214 RegisterOperator("Softmax", ParseSoftmax);
216 RegisterOperator("Transpose", ParseTranspose);
217 RegisterOperator("MatMul", ParseMatMul);
218 RegisterOperator("LayerNormalization", ParseLayerNormalization);
219 RegisterOperator("Expand", ParseExpand);
220 RegisterOperator("Gather", ParseGather);
223 RegisterOperator("EyeLike", ParseEyeLike);
231 RegisterOperator("Einsum", ParseEinsum);
232 RegisterOperator("RandomNormal", ParseRandom);
233 RegisterOperator("RandomNormalLike", ParseRandom);
234 RegisterOperator("RandomUniform", ParseRandom);
235 RegisterOperator("RandomUniformLike", ParseRandom);
236 RegisterOperator("ScatterElements", ParseScatterElements);
237}
238
239// Destructor of the parser
241
243{
244 fOperatorsMapImpl->fOperatorsMap[name] = func;
245}
246
248{
249 return fOperatorsMapImpl->fOperatorsMap.find(name) != fOperatorsMapImpl->fOperatorsMap.end();
250}
251
253{
254 std::vector<std::string> ops;
255 ops.reserve(fOperatorsMapImpl->fOperatorsMap.size());
256 for (auto &it : fOperatorsMapImpl->fOperatorsMap) {
257 ops.emplace_back(it.first);
258 }
259 // return sorted list in alphabetical order
260 std::sort(ops.begin(), ops.end());
261 return ops;
262}
263
268
270{
272}
273
278
279// Parse an operator
280std::unique_ptr<ROperator>
281RModelParser_ONNX::ParseOperator(const size_t i, const onnx::GraphProto &graphproto, const std::vector<size_t> &nodes, const std::vector<int> & children)
282{
283 if (i >= nodes.size())
284 throw std::runtime_error("TMVA::SOFIE - Error in parsing ordered operators " + std::to_string(i) + " is >= " + std::to_string(nodes.size()));
285 int idx = nodes[i];
286 const auto &nodeproto = graphproto.node(idx);
287 const std::string op_type = nodeproto.op_type();
288 if (fVerbose)
289 std::cout << "Parsing operator " << op_type << std::endl;
290
291 // skip already fused operators
292 if (fFusedOperators[idx]) return nullptr;
293
294 // try to fuse with following operator in case it is not last one
295 if (children.size() == 1) {
296 int idx2 = children.front();
297 if (op_type == "MatMul") {
298 // Fuse MatMul and Add
299 if (idx2 < graphproto.node_size() && graphproto.node(idx2).op_type() == "Add") {
300 fFusedOperators[idx2] = true;
301 return ParseFuseMatMulAdd(*this, graphproto.node(idx), graphproto.node(idx2));
302 }
303 else {
304 return ParseMatMul(*this, graphproto.node(idx));
305 }
306 } else if (nodeproto.op_type() == "Conv" || nodeproto.op_type() == "ConvTranspose") {
307 // Fuse Conv or ConvTranspose without bias and Add
308 if (idx2 < graphproto.node_size() && graphproto.node(idx2).op_type() == "Add") {
309 if (nodeproto.op_type() == "Conv") {
310 fFusedOperators[idx2] = true;
311 return ParseFuseConvAdd(*this, graphproto.node(idx), graphproto.node(idx2));
312 } else {
313 fFusedOperators[idx2] = true;
314 return ParseFuseConvTransposeAdd(*this, graphproto.node(idx), graphproto.node(idx2));
315 }
316 }
317 } else if (nodeproto.op_type() == "Gemm") {
318 // Fuse Gemm with activation operators
319 if (idx2 < graphproto.node_size() && graphproto.node(idx2).op_type() == "Relu") {
320 fFusedOperators[idx2] = true;
321 return ParseFuseGemmRelu(*this, graphproto.node(idx), graphproto.node(idx2));
322 }
323 } else if (nodeproto.op_type() == "BatchNormalization") {
324 if (idx2 < graphproto.node_size() && graphproto.node(idx2).op_type() == "Relu") {
325 fFusedOperators[idx2] = true;
326 return ParseFuseBatchnormRelu(*this, graphproto.node(idx), graphproto.node(idx2));
327 }
328 }
329 }
330
331
332
333 auto it = fOperatorsMapImpl->fOperatorsMap.find(op_type);
334 if (it == fOperatorsMapImpl->fOperatorsMap.end()) {
335 std::cout << "operator " << op_type << " is not supported" << std::endl;
336 throw std::runtime_error("TMVA::SOFIE Operator type " + op_type + " is not yet supported");
337 }
338 if (fVerbose) {
339 std::cout << "\tCreating operator " << op_type << std::endl;
340 }
341 return it->second(*this, nodeproto);
342}
343
344// Parse a model
345RModel RModelParser_ONNX::Parse(std::string filename, bool verbose)
346{
347 fVerbose = verbose;
348
349 fTensorTypeMap.clear();
350
351 auto model = LoadModel(filename);
352 if (!model)
353 throw std::runtime_error("TMVA::SOFIE - Failed to load onnx file " + filename);
354
355 const onnx::GraphProto &graph = model->graph(); // not a memory leak. model freed automatically at the end.
356
357
358 std::time_t ttime = std::time(0);
359 std::tm *gmt_time = std::gmtime(&ttime);
360 std::string parsetime(std::asctime(gmt_time));
361
362 // get name of model (filename without directory name)
363 char sep = '/';
364#ifdef _WIN32
365 sep = '\\';
366#endif
367 size_t isep = filename.rfind(sep, filename.length());
368 std::string filename_nodir = filename;
369 if (isep != std::string::npos) {
370 filename_nodir = (filename.substr(isep + 1, filename.length() - isep));
371 }
372
375 return rmodel;
376}
377
378std::unique_ptr<onnx::ModelProto> RModelParser_ONNX::LoadModel(std::string filename) {
379
381 auto model = std::make_unique<onnx::ModelProto>();
382
383 std::fstream input(filename, std::ios::in | std::ios::binary);
384 if (!model->ParseFromIstream(&input)) {
385 std::cerr << "TMVA::SOFIE - Failed to open onnx file " << filename << std::endl;
386 return std::unique_ptr<onnx::ModelProto>();
387 }
388
389 // ONNX version is ir_version() - model_version() returns 0
390 if (fVerbose) {
391 std::cout << "ONNX Version " << model->ir_version() << std::endl;
392 }
393 google::protobuf::ShutdownProtobufLibrary();
394 return model;
395
396}
397
398void RModelParser_ONNX::CheckGraph(const onnx::GraphProto & graph, int & level, std::map<std::string, int> & missingOperators) {
399 if (fVerbose)
400 std::cout << "\n" << graph.name() << " Graph operator list\n";
401 for (int i = 0; i < graph.node_size(); i++) {
402 const auto & node = graph.node(i);
403 const std::string opType = node.op_type();
404 if (fVerbose) {
405 std::cout << "\tOperator " << i << " : " << opType << " (" << node.name() << "), " << graph.node(i).input_size()
406 << " inputs : {";
407 for (int j = 0; j < graph.node(i).input_size(); j++) {
408 std::cout << graph.node(i).input(j);
409 if (j < graph.node(i).input_size() - 1)
410 std::cout << ", ";
411 }
412 std::cout << " }" << std::endl;
413 }
414 // check if operator exists
416 missingOperators[opType] = level;
417 // see if sub-graph exists as node attributes
418 for (int j = 0; j < node.attribute_size(); j++) {
419 const auto & attribute = node.attribute(j);
420 if (attribute.has_g()) {
421 const auto & subGraph = attribute.g();
422 level += 1;
424 }
425 }
426 }
427}
428
429bool RModelParser_ONNX::CheckModel(std::string filename, bool verbose) {
430
431 fVerbose = verbose;
432 auto model = LoadModel(filename);
433 if (!model) return false;
434
435 const onnx::GraphProto &graph = model->graph();
436 // Initial operator order
437 if (fVerbose)
438 std::cout << "\nModel operator list " << model->producer_name() << "\n";
439
440 std::map<std::string, int> missingOperators;
441 int level = 1;
442 CheckGraph(graph, level, missingOperators);
443
444 if (!missingOperators.empty()) {
445 std::cout << "List of missing operators for model loaded from file " << filename << std::endl;
446 for (auto & op : missingOperators) {
447 std::cout << op.first << " " << op.second << std::endl;
448 }
449 return false;
450 }
451 std::cout << "All operators in the loaded model are supported!\n";
452 return true;
453}
454
455void RModelParser_ONNX::ParseONNXGraph(RModel & rmodel, const onnx::GraphProto & graph, std::string graphName)
456{
457 bool verbose = fVerbose;
458
459 if (graphName.empty())
460 graphName = graph.name();
461
462 if (verbose)
463 std::cout << "\nParsing Graph - " << graphName << std::endl;
464
465 std::unordered_set<std::string> initializer_names;
466 for (int i = 0; i < graph.initializer_size(); i++) {
467 initializer_names.insert(graph.initializer(i).name());
468 }
469
470 if (verbose)
471 std::cout << "Parsing model inputs...." << std::endl;
472 /// Loop on model inputs
473 for (int i = 0; i < graph.input_size(); i++) {
474 RegisterTensorType(graph.input(i).name(),
475 static_cast<ETensorType>(graph.input(i).type().tensor_type().elem_type()));
476
477 if (verbose)
478 std::cout << "\tgraph input " << i << " name " << graph.input(i).name() << " type "
479 << graph.input(i).type().tensor_type().elem_type() << std::endl;
480
481 if (initializer_names.find(graph.input(i).name()) != initializer_names.end())
482 continue;
483
484 // input data node is not a weight node (has no initializer)
485 const onnx::ValueInfoProto &valueinfoproto = graph.input(i);
486 std::string input_name = valueinfoproto.name();
487
488 ETensorType type = static_cast<ETensorType>(valueinfoproto.type().tensor_type().elem_type());
489
490 std::vector<Dim> fShape;
491 bool existParam = false;
492 if (!valueinfoproto.type().tensor_type().has_shape())
493 throw std::runtime_error("TMVA::SOFIE data node with no shape restrictions is not supported yet");
494 for (int j = 0; j < valueinfoproto.type().tensor_type().shape().dim_size(); j++) {
495 Dim dim;
496 if (valueinfoproto.type().tensor_type().shape().dim(j).value_case() ==
497 onnx::TensorShapeProto_Dimension::ValueCase::kDimValue) {
498 int dim_value = valueinfoproto.type().tensor_type().shape().dim(j).dim_value();
499 dim.dim = dim_value;
500 // case input dim is -1 - set a parametric shape
501 if (dim_value < 0) {
502 dim.isParam = true;
503 existParam = true;
504 dim.param = UTILITY::Clean_name(input_name) + "_size";
505 }
506 } else if (valueinfoproto.type().tensor_type().shape().dim(j).value_case() ==
507 onnx::TensorShapeProto_Dimension::ValueCase::kDimParam) {
508 dim.isParam = true;
509 existParam = true;
510 dim.param = valueinfoproto.type().tensor_type().shape().dim(j).dim_param();
511 } else {
512 throw std::runtime_error("TMVA::SOFIE ONNX file error: Valueinfoproto " + input_name +
513 " has neither dim_value nor dim_param! \n");
514 }
515 fShape.push_back(dim);
516 }
517 if (valueinfoproto.type().tensor_type().shape().dim_size() == 0) {
518 Dim dim;
519 dim.dim = 1;
520 fShape.push_back(dim);
521 } // in case this TensorShapeProto has no dimension message: ONNX IR defines this to be a scalar
522
523 if (!existParam) {
524 std::vector<size_t> fShape_sizet;
525 for (auto &j : fShape) {
526 fShape_sizet.push_back(j.dim);
527 }
528
529 rmodel.AddInputTensorInfo(input_name, type, fShape_sizet);
530 } else {
531 rmodel.AddInputTensorInfo(input_name, type, fShape);
532 }
533 rmodel.AddInputTensorName(input_name); // store also names in given order
534 }
535
536 std::map<std::string, int> allInitializedTensors;
537
538 if (verbose)
539 std::cout << "\nParsing graph initializer list and fill model initialized tensors" << std::endl;
540
541 for (int i = 0; i < graph.initializer_size(); i++) {
542 onnx::TensorProto *tensorproto = const_cast<onnx::TensorProto *>(&graph.initializer(i));
543 std::vector<std::size_t> shape;
544 std::size_t fLength = 1;
545 for (int j = 0; j < tensorproto->dims_size(); j++) {
546 shape.push_back(tensorproto->dims(j));
547 fLength *= tensorproto->dims(j);
548 }
549 // in case of scalars keep an empty shape but with length =1
550
551 std::string input_name = graph.initializer(i).name();
552
553 if (verbose)
554 std::cout << "\t initializer " << i << " name " << input_name << " type " << graph.initializer(i).data_type()
555 << std::endl;
556
557 // register also the initialized tensors
558 auto tensor_type = static_cast<ETensorType>(graph.initializer(i).data_type());
560
561 switch (tensor_type) {
562 case ETensorType::FLOAT: {
563 std::shared_ptr<void> data = GetInitializedTensorData<float>(tensorproto, fLength);
564 if (verbose) std::cout << "add FLOAT initialized tensor " << input_name << " shape " << ConvertShapeToString(shape) << std::endl;
565 rmodel.AddInitializedTensor(input_name, ETensorType::FLOAT, shape, data);
567 break;
568 }
569 case ETensorType::DOUBLE: {
570 std::shared_ptr<void> data = GetInitializedTensorData<double>(tensorproto, fLength);
571 if (verbose) std::cout << "add DOUBLE initialized tensor " << input_name << " shape " << ConvertShapeToString(shape) << std::endl;
572 rmodel.AddInitializedTensor(input_name, ETensorType::DOUBLE, shape, data);
574 break;
575 }
576 case ETensorType::INT32: {
577 std::shared_ptr<void> data = GetInitializedTensorData<int32_t>(tensorproto, fLength);
578 if (verbose) std::cout << "add INT32 initialized tensor " << input_name << " shape " << ConvertShapeToString(shape) << std::endl;
579 rmodel.AddInitializedTensor(input_name, ETensorType::INT32, shape, data);
581 break;
582 }
583 case ETensorType::INT64: {
584 std::shared_ptr<void> data = GetInitializedTensorData<int64_t>(tensorproto, fLength);
585 if (verbose) std::cout << "add INT64 initialized tensor " << input_name << " shape " << ConvertShapeToString(shape) << std::endl;
586 rmodel.AddInitializedTensor(input_name, ETensorType::INT64, shape, data);
588 break;
589 }
590 default:
591 throw std::runtime_error("Data type in weight tensor " + graph.initializer(i).name() + " not supported!\n");
592 }
593 }
594
595 // Initial operator order
596 if (verbose) {
597 std::cout << "\nGraph operator list (ONNX order)\n";
598 for (int i = 0; i < graph.node_size(); i++) {
599 std::cout << "\tOperator " << i << " : " << graph.node(i).op_type() << " , " << graph.node(i).input_size()
600 << " inputs : {";
601 for (int j = 0; j < graph.node(i).input_size(); j++) {
602 std::cout << graph.node(i).input(j);
603 if (j < graph.node(i).input_size() - 1)
604 std::cout << ", ";
605 }
606 std::cout << " }" << std::endl;
607 }
608 }
609
610 // make order of nodes:
611 if (verbose)
612 std::cout << "\n***********************\nRe-Order graph operator list\n*************************\n";
613 std::vector<size_t> nodesOrder;
614 nodesOrder.reserve(graph.node_size());
615 std::vector<bool> foundNodes(graph.node_size());
616
617 // loop at graph inputs
618 std::map<std::string, int> allInputs;
619 for (int i = 0; i < graph.input_size(); i++) {
620 allInputs[graph.input(i).name()] = -1;
621 }
622 do {
623 auto psize = nodesOrder.size();
624 for (int i = 0; i < graph.node_size(); i++) {
625 if (foundNodes[i])
626 continue;
627 // check if all input exists add to list
628 bool existInputs = true;
629 int input_size = graph.node(i).input_size();
630 // special case for Reshape where shape is input and not a weight tensor
631 if (fVerbose)
632 std::cout << "Checking input of Node " << i << " : " << graph.node(i).name() << std::endl;
633 for (int j = 0; j < input_size; j++) {
634 std::string name = graph.node(i).input(j);
635 // skip empty names
636 if (!name.empty()) {
637 existInputs &= (allInputs.find(name) != allInputs.end() ||
639 if (fVerbose) {
640 std::cout << "\t\t input " << name << " "
641 << bool(allInputs.find(name) != allInputs.end()) << " " <<
643 existInputs << std::endl;
644 }
645 }
646 }
647 if (!existInputs) {
648 if (fVerbose) {
649 std::cout << "skip node " << graph.node(i).op_type() << " " << graph.node(i).name() << " inputs are not existing ";
650 for (int j = 0; j < input_size; j++) {
651 std::cout << graph.node(i).input(j) << " ";
652 }
653 std::cout << std::endl;
654 }
655 continue;
656 }
657
658 // adding node to the currectly ordered list
659 if (verbose)
660 std::cout << "===> New node " << graph.node(i).op_type() << " " << graph.node(i).name() << " order " << i << std::endl;
661
662 nodesOrder.push_back(i);
663 foundNodes[i] = true;
664 // register the outputs
665 for (int j = 0; j < graph.node(i).output_size(); j++) {
666 if (fVerbose) std::cout << "\toutput : " << graph.node(i).output(j) << std::endl;
667 allInputs[graph.node(i).output(j)] = i;
668 }
669 }
670 // no increment in nodes - something wrong
671 if (nodesOrder.size() == psize) {
672 int ilast = nodesOrder.back();
673 std::cout << "cannot find a new node after " << graph.node(ilast).op_type() << " " << graph.node(ilast).name() << std::endl;
674 throw std::runtime_error("TMVA::SOFIE - cannot find a new node ");
675 }
676 } while ((int)nodesOrder.size() < graph.node_size());
677
678
679 // find list of children for each operator (used for fusing oiperators)
680 std::vector<std::vector<int>> nodesChildren(graph.node_size());
681
682 for (int k = 0; k < graph.node_size(); k++) {
683 int i = nodesOrder[k];
684 // compute the number of output for the operators
685 if (graph.node(i).output_size() > 0) nodesChildren[i].reserve(graph.node(i).output_size());
686 for (const auto& output_name : graph.node(i).output()) {
687 // loop on all nodes
688 for (int l = k; l < graph.node_size(); l++) {
689 int j = nodesOrder[l];
690 for (const auto& input_name : graph.node(j).input()) {
691 if (input_name == output_name)
692 nodesChildren[i].push_back(j);
693 }
694 }
695 }
696 }
697
698 // print lit of order operators with list of inputs and list of children nodes
699 if (verbose) {
700 std::cout << "\nGraph operator list (re-ordered)\n";
701 for (int k = 0; k < graph.node_size(); k++) {
702 int i = nodesOrder[k];
703 std::cout << "\tOperator " << i << " : " << graph.node(i).op_type() << " , " << graph.node(i).name() << " input tensors : {";
704 for (int j = 0; j < graph.node(i).input_size(); j++) {
705 std::cout << graph.node(i).input(j);
706 if (j < graph.node(i).input_size() - 1)
707 std::cout << ", ";
708 }
709 std::cout << " } ";
710 std::cout << " children : {";
711 for ( const auto & ichild : nodesChildren[i]) {
712 std::cout << " [ " << ichild << " " << graph.node(ichild).op_type() << " , " << graph.node(ichild).name() << "]";
713 }
714 std::cout << "}" << std::endl;
715 }
716 }
717
718 // fill model with operators
719 if (verbose) {
720 std::cout << "Fill RModel with operators...\n";
721 }
722
723 // we have to record order of node execution separately to
724 // account for fused operators
725 size_t node_order_exec = 0;
726 fFusedOperators = std::vector<bool>(graph.node_size(), false);
727 for (int i = 0; i < graph.node_size(); i++) {
728 std::string op_type = graph.node(nodesOrder[i]).op_type();
729
730 if (verbose) {
731 std::cout << "\t" << i << " " << nodesOrder[i] << " parsing operator " << op_type << std::endl;
732 }
733
734 std::unique_ptr<ROperator> op = ParseOperator(i, graph, nodesOrder, nodesChildren[i]);
735 if (!op) {
736 if (verbose) {
737 std::cout << "\t\tskipping operator since it is fused with previous one" << std::endl;
738 }
739 // for skipping the fused nodes like Add after MatMul
740 continue;
741 }
742 rmodel.AddOperator(std::move(op), node_order_exec++);
743 }
744
745 std::vector<std::string> outputnames;
746 if (verbose)
747 std::cout << "\nParsing Graph output list\n";
748 for (int i = 0; i < graph.output_size(); i++) {
749 if (verbose)
750 std::cout << "\toutput " << i << " name " << graph.output(i).name() << std::endl;
751 outputnames.push_back(graph.output(i).name());
752 }
753 rmodel.AddOutputTensorNameList(outputnames);
754
755 return;
756}
757
758} // namespace SOFIE
759} // namespace Experimental
760} // namespace TMVA
dims_t fShape
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define malloc
Definition civetweb.c:1536
const_iterator begin() const
const_iterator end() const
void RegisterOperator(const std::string &name, ParserFuncSignature func)
std::unique_ptr< ROperator > ParseOperator(const size_t, const onnx::GraphProto &, const std::vector< size_t > &, const std::vector< int > &)
bool IsRegisteredOperator(const std::string &name)
void CheckGraph(const onnx::GraphProto &g, int &level, std::map< std::string, int > &missingOperators)
void ParseONNXGraph(RModel &model, const onnx::GraphProto &g, std::string name="")
std::unordered_map< std::string, ETensorType > fTensorTypeMap
RModel Parse(std::string filename, bool verbose=false)
void RegisterTensorType(const std::string &, ETensorType)
std::unique_ptr< onnx::ModelProto > LoadModel(std::string filename)
ETensorType GetTensorType(const std::string &name)
std::vector< std::string > GetRegisteredOperators()
std::unique_ptr< OperatorsMapImpl > fOperatorsMapImpl
bool CheckModel(std::string filename, bool verbose=false)
std::string Clean_name(std::string input_tensor_name)
ParserFuncSignature ParseSqrt
ParserFuncSignature ParseBatchNormalization
ParserFuncSignature ParseGreater
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &, const onnx::NodeProto &)> ParserFuseFuncSignature
ParserFuncSignature ParseReshape
ParserFuseFuncSignature ParseFuseConvTransposeAdd
ParserFuncSignature ParseReduceMean
ParserFuseFuncSignature ParseFuseMatMulAdd
ParserFuncSignature ParseGather
ParserFuncSignature ParseNeg
ParserFuncSignature ParseWhere
Definition ParseWhere.cxx:9
ParserFuncSignature ParseCos
ParserFuncSignature ParseLog
ParserFuncSignature ParseLeakyRelu
ParserFuncSignature ParseExp
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParseEinsum
ParserFuncSignature ParsePool
Definition ParsePool.cxx:9
ParserFuncSignature ParseDiv
ParserFuncSignature ParseLayerNormalization
ParserFuncSignature ParseConcat
ParserFuncSignature ParseTopK
Definition ParseTopK.cxx:9
ParserFuncSignature ParseMax
ParserFuncSignature ParseEq
ParserFuncSignature ParseIdentity
ParserFuncSignature ParseConvTranspose
ParserFuncSignature ParseReduceProd
ParserFuncSignature ParseSlice
Definition ParseSlice.cxx:9
ParserFuncSignature ParseRandom
ParserFuncSignature ParseTranspose
ParserFuncSignature ParseLess
ParserFuncSignature ParseShape
Definition ParseShape.cxx:9
ParserFuncSignature ParseGRU
Definition ParseGRU.cxx:9
ParserFuncSignature ParseMatMul
ParserFuncSignature ParseErf
Definition ParseErf.cxx:9
ParserFuncSignature ParseSub
ParserFuncSignature ParseAdd
std::shared_ptr< void > GetInitializedTensorData(onnx::TensorProto *tensorproto, size_t length)
ParserFuncSignature ParseIf
Definition ParseIf.cxx:9
ParserFuncSignature ParseRange
Definition ParseRange.cxx:9
ParserFuncSignature ParseExpand
ParserFuncSignature ParseRNN
Definition ParseRNN.cxx:9
ParserFuncSignature ParseLSTM
Definition ParseLSTM.cxx:9
ParserFuncSignature ParseCast
Definition ParseCast.cxx:9
ParserFuncSignature ParseReciprocal
std::string ConvertShapeToString(std::vector< size_t > shape)
ParserFuncSignature ParseSigmoid
ParserFuseFuncSignature ParseFuseConvAdd
ParserFuseFuncSignature ParseFuseBatchnormRelu
ParserFuncSignature ParseSoftmax
ParserFuncSignature ParseGreaterEq
ParserFuncSignature ParseMean
ParserFuncSignature ParseSplit
Definition ParseSplit.cxx:9
ParserFuncSignature ParseConstant
ParserFuncSignature ParseSelu
Definition ParseSelu.cxx:9
ParserFuncSignature ParseLessEq
ParserFuncSignature ParseSum
ParserFuncSignature ParseEyeLike
ParserFuncSignature ParsePad
Definition ParsePad.cxx:9
ParserFuncSignature ParseElu
Definition ParseElu.cxx:9
ParserFuncSignature ParseMin
ParserFuncSignature ParseRelu
Definition ParseRelu.cxx:9
ParserFuncSignature ParseReduceSum
ParserFuncSignature ParseConv
Definition ParseConv.cxx:9
ParserFuncSignature ParseScatterElements
ParserFuncSignature ParseGemm
Definition ParseGemm.cxx:9
ParserFuncSignature ParseTile
Definition ParseTile.cxx:9
ParserFuncSignature ParseMul
ParserFuseFuncSignature ParseFuseGemmRelu
ParserFuncSignature ParsePow
ParserFuncSignature ParseAbs
ParserFuncSignature ParseSin
ParserFuncSignature ParseReduceSumSquare
ParserFuncSignature ParseTanh
Definition ParseTanh.cxx:9
create variable transformations
Helper templated class for swapping bytes; specializations for N={2,4,8} are provided below.
Definition Byteswap.h:124
static void Copy(onnx::TensorProto *tensor, void *data)
static void Copy(onnx::TensorProto *tensor, void *data)
static void Copy(onnx::TensorProto *tensor, void *data)
static void Copy(onnx::TensorProto *tensor, void *data)
std::unordered_map< std::string, ParserFuncSignature > fOperatorsMap
TLine l
Definition textangle.C:4