Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseFuseGemmRelu.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
10 const onnx::NodeProto &relunode) -> std::unique_ptr<ROperator> {
12 // check input type - only first input from Gemm
13 auto input_name = gemmnode.input(0);
16 } else {
17 throw std::runtime_error("TMVA::SOFIE ONNX Parser MatMul op has input tensor " + input_name +
18 " but its type is not yet registered");
19 }
20
21 // we don't check input type of ADD since it is not be registered
22 std::unique_ptr<ROperator> op;
23
24 float attr_alpha = 1.0;
25 float attr_beta = 1.0;
28
29 for (int i = 0; i < gemmnode.attribute_size(); i++) {
30 std::string attribute_name = gemmnode.attribute(i).name();
31 if (attribute_name == "alpha") {
32 attr_alpha = gemmnode.attribute(i).f();
33 } else if (attribute_name == "beta") {
34 attr_beta = gemmnode.attribute(i).f();
35 } else if (attribute_name == "transA") {
36 attr_transA = gemmnode.attribute(i).i();
37 if (attr_transA != 0 && attr_transA != 1)
38 throw std::runtime_error("TMVA::SOFIE Error - Model Loading - attribute transA in Operator Gemm not 0/1");
39 } else if (attribute_name == "transB") {
40 attr_transB = gemmnode.attribute(i).i();
41 if (attr_transB != 0 && attr_transB != 1)
42 throw std::runtime_error("TMVA::SOFIE Error - Model Loading - attribute transB in Operator Gemm not 0/1");
43 } else {
44 std::cout << "TMVA::SOFIE Warning - Model Loading - Attribute " << attribute_name << " in OperatorNode "
45 << gemmnode.name() << " is not defined in ONNX IR and not applied!\n";
46 }
47 }
48 switch (input_type) {
50 if (gemmnode.input_size() == 2) {
52 gemmnode.input(1), relunode.output(0), EActivationType::RELU));
53 } else {
55 gemmnode.input(1), gemmnode.input(2), relunode.output(0), EActivationType::RELU));
56 }
57 break;
58 default:
59 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Gemm does not yet support input type " +
60 std::to_string(static_cast<int>(input_type)));
61 }
62
63 std::string output_name = relunode.output(0);
66 }
67
68 return op;
69};
70
71} // namespace SOFIE
72} // namespace Experimental
73} // namespace TMVA
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &, const onnx::NodeProto &)> ParserFuseFuncSignature
ParserFuseFuncSignature ParseFuseGemmRelu
create variable transformations