MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / parse

Method parse

src/onnx/parse_rnn.cpp:64–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 std::vector<op_desc> operators() const { return {{"RNN"}}; }
63
64 std::vector<instruction_ref> parse(const op_desc& /*opd*/,
65 const onnx_parser& parser,
66 onnx_parser::node_info info,
67 std::vector<instruction_ref> args) const
68 {
69 migraphx::shape input_shape = args[0]->get_shape();
70 std::size_t hidden_size = args[1]->get_shape().lens()[1];
71
72 if(contains(info.attributes, "hidden_size"))
73 {
74 std::size_t hidden_size_att =
75 parser.parse_value(info.attributes.at("hidden_size")).at<int>();
76 if(hidden_size != hidden_size_att)
77 {
78 MIGRAPHX_THROW("RNN: hidden size mismatch in input and attribute");
79 }
80 }
81
82 // Handling of direction to be added later
83 std::string direction{"forward"};
84 if(contains(info.attributes, "direction"))
85 {
86 direction = info.attributes.at("direction").s();
87 }
88
89 op::rnn_direction dirct = op::rnn_direction::forward;
90 if(direction == "bidirectional")
91 {
92 dirct = op::rnn_direction::bidirectional;
93 }
94 else if(direction == "reverse")
95 {
96 dirct = op::rnn_direction::reverse;
97 }
98
99 std::vector<std::string> vec_names = {"tanh", "tanh"};
100 if(contains(info.attributes, "activations"))
101 {
102 auto names = info.attributes.at("activations").strings();
103 vec_names.clear();
104 vec_names.resize(names.size());
105 std::transform(names.begin(), names.end(), vec_names.begin(), [](auto name) {
106 return to_lower(std::move(name));
107 });
108 }
109
110 if(vec_names.size() == 2 and dirct != op::rnn_direction::bidirectional)
111 {
112 // default activations are {"tanh", "tanh"}
113 // in this case, take the first default activation.
114 vec_names.resize(1);
115 }
116
117 auto num_actv_functions = dirct == op::rnn_direction::bidirectional ? 2 : 1;
118 if(vec_names.size() != static_cast<size_t>(num_actv_functions))
119 {
120 MIGRAPHX_THROW("RNN: Invalid activation functions number, should be: " +
121 to_string(num_actv_functions));

Callers

nothing calls this directly

Calls 15

containsFunction · 0.85
to_lowerFunction · 0.85
rnn_transpose_inputsFunction · 0.85
rnn_transpose_outputsFunction · 0.85
lensMethod · 0.80
parse_valueMethod · 0.80
atMethod · 0.80
resizeMethod · 0.80
transformFunction · 0.50
to_stringFunction · 0.50
find_ifFunction · 0.50
make_opFunction · 0.50

Tested by

no test coverage detected