ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseRNN.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_RNN.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuncSignature
ParseRNN
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
nodeproto
) {
10
ETensorType
input_type
;
11
12
auto
input_name
=
nodeproto
.input(0);
13
if
(
parser
.IsRegisteredTensorType(
input_name
)) {
14
input_type
=
parser
.GetTensorType(
input_name
);
15
}
else
{
16
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser RNN op has input tensor "
+
input_name
+
17
" but its type is not yet registered"
);
18
}
19
20
std::unique_ptr<ROperator>
op
;
21
22
std::vector<float>
attr_activation_alpha
= {};
23
std::vector<float>
attr_activation_beta
= {};
24
std::vector<std::string>
attr_activations
= {};
25
float
attr_clip
= 0.;
26
std::string
attr_direction
=
"forward"
;
27
size_t
attr_hidden_size
= 0;
28
size_t
attr_layout
= 0;
29
30
for
(
int_t
i = 0; i <
nodeproto
.attribute_size(); i++) {
31
std::string
attribute_name
=
nodeproto
.attribute(i).name();
32
if
(
attribute_name
==
"activation_alpha"
) {
33
attr_activation_alpha
= {
nodeproto
.attribute(i).floats().
begin
(),
nodeproto
.attribute(i).floats().
end
()};
34
}
else
if
(
attribute_name
==
"activation_beta"
) {
35
attr_activation_beta
= {
nodeproto
.attribute(i).floats().
begin
(),
nodeproto
.attribute(i).floats().
end
()};
36
}
else
if
(
attribute_name
==
"activations"
) {
37
attr_activations
= {
nodeproto
.attribute(i).strings().
begin
(),
nodeproto
.attribute(i).strings().
end
()};
38
}
else
if
(
attribute_name
==
"clip"
) {
39
attr_clip
=
nodeproto
.attribute(i).i();
40
}
else
if
(
attribute_name
==
"direction"
) {
41
attr_direction
=
nodeproto
.attribute(i).s();
42
}
else
if
(
attribute_name
==
"hidden_size"
) {
43
attr_hidden_size
=
nodeproto
.attribute(i).i();
44
}
else
if
(
attribute_name
==
"layout"
) {
45
attr_layout
=
nodeproto
.attribute(i).i();
46
}
else
{
47
std::cout <<
"TMVA SOFIE Warning - Model Loading - Attribute "
<<
attribute_name
<<
" in OperatorNode "
48
<<
nodeproto
.name() <<
" is not defined in ONNX IR and not applied!\n"
;
49
}
50
}
51
52
// Optional inputs and outputs
53
std::string
name_b
=
""
;
54
std::string
name_sequence_lens
=
""
;
55
std::string
name_initial_h
=
""
;
56
std::string
name_y
=
""
;
57
std::string
name_y_h
=
""
;
58
if
(
nodeproto
.input_size() > 3) {
59
name_b
=
nodeproto
.input(3);
60
}
61
if
(
nodeproto
.input_size() > 4) {
62
name_sequence_lens
=
nodeproto
.input(4);
63
}
64
if
(
nodeproto
.input_size() > 5) {
65
name_initial_h
=
nodeproto
.input(5);
66
}
67
if
(
nodeproto
.output_size() > 0) {
68
name_y
=
nodeproto
.output(0);
69
}
70
if
(
nodeproto
.output_size() > 1) {
71
name_y_h
=
nodeproto
.output(1);
72
}
73
74
switch
(
input_type
) {
75
case
ETensorType::FLOAT
:
76
op
.reset(
new
ROperator_RNN<float>
(
attr_activation_alpha
,
attr_activation_beta
,
attr_activations
,
attr_clip
,
77
attr_direction
,
attr_hidden_size
,
attr_layout
,
nodeproto
.input(0),
78
nodeproto
.input(1),
nodeproto
.input(2),
name_b
,
name_sequence_lens
,
79
name_initial_h
,
name_y
,
name_y_h
));
80
break
;
81
default
:
82
throw
std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator RNN does not yet support input type "
+
83
std::to_string(
static_cast<
int
>
(
input_type
)));
84
}
85
86
for
(
const
auto
&
name
: {
name_y
,
name_y_h
}) {
87
if
(!
parser
.IsRegisteredTensorType(
name
)) {
88
parser
.RegisterTensorType(
name
,
input_type
);
89
}
90
}
91
92
return
op
;
93
};
94
95
}
// namespace SOFIE
96
}
// namespace Experimental
97
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_RNN.hxx
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:359
name
char name[80]
Definition
TGX11.cxx:142
ROOT::Detail::TRangeCast
Definition
TCollection.h:312
ROOT::RRangeCast::begin
const_iterator begin() const
Definition
RRangeCast.hxx:103
ROOT::RRangeCast::end
const_iterator end() const
Definition
RRangeCast.hxx:104
TMVA::Experimental::SOFIE::RModelParser_ONNX
Definition
RModelParser_ONNX.hxx:30
TMVA::Experimental::SOFIE::onnx::NodeProto
Definition
onnx.hxx:504
TMVA::Experimental::SOFIE::ETensorType
ETensorType
Definition
SOFIE_common.hxx:29
TMVA::Experimental::SOFIE::ETensorType::FLOAT
@ FLOAT
TMVA::Experimental::SOFIE::ParserFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
Definition
RModelParser_ONNX.hxx:25
TMVA::Experimental::SOFIE::int_t
std::int64_t int_t
Definition
SOFIE_common.hxx:56
TMVA::Experimental::SOFIE::ParseRNN
ParserFuncSignature ParseRNN
Definition
ParseRNN.cxx:9
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseRNN.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0