You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rnn.h 39 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*!
  17. * \file rnn.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_RNN_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_RNN_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief: Basic LSTM Cell forward calculation.
  26. *@par Inputs:
  27. *five inputs:
  28. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  29. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  30. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  31. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  32. *@li b:A 1D Tensor. Must be one of the following types: float16. The format must be ND . \n
  33. *@par Attributes:
  34. *@li keep_prob:An integer identifying the keep prob in the op. Default to 1.
  35. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  36. *@li state_is_tuple:An bool identifying if the hidden state and cell state is tuple. Default to true.
  37. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  38. *@par Outputs:
  39. *seven outputs:
  40. *@li mask:A 1D Tensor. Must be one of the following types: uint8.
  41. *@li ct:A 4D Tensor. Must be one of the following types: float16, float32.
  42. *@li ht:A 4D Tensor. Must be one of the following types: float16.
  43. *@li it:A 4D Tensor. Must be one of the following types: float16, float32.
  44. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32.
  45. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32.
  46. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32.
  47. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  48. */
  49. REG_OP(BasicLSTMCell)
  50. .INPUT(x, TensorType({DT_FLOAT16}))
  51. .INPUT(h, TensorType({DT_FLOAT16}))
  52. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  53. .INPUT(w, TensorType({DT_FLOAT16}))
  54. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  55. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  56. .OUTPUT(ct, TensorType({DT_FLOAT16, DT_FLOAT}))
  57. .OUTPUT(ht, TensorType({DT_FLOAT16}))
  58. .OUTPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  59. .OUTPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  60. .OUTPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  61. .OUTPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  62. .OUTPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  63. .ATTR(keep_prob, Float, 1.0)
  64. .ATTR(forget_bias, Float, 1.0)
  65. .ATTR(state_is_tuple, Bool, true)
  66. .ATTR(activation, String, "tanh")
  67. .OP_END_FACTORY_REG(BasicLSTMCell)
  68. /**
  69. *@brief: Dynamic LSTM forward calculation . \n
  70. *@par Inputs:
  71. *@li x:A 4D Tensor. Must be the type float32. The format must be FRACTAL_NZ.
  72. *@li w:A 4D Tensor. Must be the type float32. The format must be FRACTAL_Z.
  73. *@li b:A 1D Tensor. Must be the type float32. The format must be ND . \n
  74. *@par Outputs:
  75. *output_h:A Tensor of output. Must be the type float32. The format must be FRACTAL_Z.
  76. *@par Restrictions:
  77. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  78. */
  79. REG_OP(DynamicLSTM)
  80. .INPUT(x, TensorType({DT_FLOAT32}))
  81. .INPUT(w, TensorType({DT_FLOAT32}))
  82. .INPUT(b, TensorType({DT_FLOAT32}))
  83. .OUTPUT(output_h, TensorType({DT_FLOAT32}))
  84. .OP_END_FACTORY_REG(DynamicLSTM)
  85. /**
  86. *@brief: DynamicRNNGrad calculation.
  87. *@par Inputs:
  88. *ten inputs: \n
  89. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  90. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  91. *@li b:A 1D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  92. *@li y:A 1D Tensor. Must be one of the following types: int32. The format must be FRACTAL_NZ.
  93. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  94. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  95. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  96. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  97. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  98. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  99. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  100. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  101. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  102. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  103. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  104. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  105. *@li seq_length:A 1D Tensor. Must be one of the following types: int32.
  106. *@li mask:A 1D Tensor. Must be one of the following types: int8.
  107. *@li wci:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  108. *@li wcf:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  109. *@li wco:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  110. *@par Attributes:
  111. *@li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  112. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  113. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  114. *@li use_peephole:An bool identifying if use peephole in the op. Default to false.
  115. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  116. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  117. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  118. *@li time_major:An bool identifying the time major in the op. Default to false.
  119. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  120. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  121. *@li is_training:An bool identifying is training in the op. Default to true.
  122. *@par Outputs:
  123. *eight outputs: \n
  124. *@li dw:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  125. *@li db:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  126. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  127. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  128. *@li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  129. *@li dwci:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  130. *@li dwcf:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  131. *@li dwco:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  132. */
  133. REG_OP(DynamicRNNGrad)
  134. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  135. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  136. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  137. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  138. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  139. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  140. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  141. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  142. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  143. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  144. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  145. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  146. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  147. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  148. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  149. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  150. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  151. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  152. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  153. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  154. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  155. .OUTPUT(dw, TensorType({DT_FLOAT16, DT_FLOAT}))
  156. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT}))
  157. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  158. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  159. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  160. .DYNAMIC_OUTPUT(dwci, TensorType({DT_FLOAT16, DT_FLOAT}))
  161. .DYNAMIC_OUTPUT(dwcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  162. .DYNAMIC_OUTPUT(dwco, TensorType({DT_FLOAT16, DT_FLOAT}))
  163. .ATTR(cell_type, String, "LSTM")
  164. .ATTR(direction, String, "UNIDIRECTIONAL")
  165. .ATTR(cell_depth, Int, 0)
  166. .ATTR(use_peephole, Bool, false)
  167. .ATTR(keep_prob, Float, -1.0)
  168. .ATTR(cell_clip, Float, -1.0)
  169. .ATTR(num_proj, Int, 0)
  170. .ATTR(time_major, Bool, true)
  171. .ATTR(forget_bias, Float, 0.0)
  172. .OP_END_FACTORY_REG(DynamicRNNGrad)
  173. /**
  174. *@brief: DynamicRNN calculation.
  175. *@par Inputs:
  176. *ten inputs:
  177. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  178. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  179. *@li b:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  180. *@li seq_length:A 1D Tensor. Must be one of the following types: int32. The format must be ND.
  181. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  182. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  183. *@li wci:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  184. *@li wcf:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  185. *@li wco:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  186. *@li mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  187. *@par Attributes:
  188. *@li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  189. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  190. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  191. *@li use_peephole:An bool identifying if use peephole in the op. Default to false.
  192. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  193. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  194. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  195. *@li time_major:An bool identifying the time major in the op. Default to true.
  196. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  197. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  198. *@li is_training:An bool identifying is training in the op. Default to true . \n
  199. *@par Outputs:
  200. *eight outputs:
  201. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  202. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  203. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  204. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  205. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  206. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  207. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  208. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  209. */
  210. REG_OP(DynamicRNN)
  211. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  212. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  213. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  214. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  215. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  216. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  217. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  218. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  219. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  220. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  221. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  222. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  223. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  224. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  225. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  226. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  227. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  228. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  229. .ATTR(cell_type, String, "LSTM")
  230. .ATTR(direction, String, "UNIDIRECTIONAL")
  231. .ATTR(cell_depth, Int, 1)
  232. .ATTR(use_peephole, Bool, false)
  233. .ATTR(keep_prob, Float, 1.0)
  234. .ATTR(cell_clip, Float, -1.0)
  235. .ATTR(num_proj, Int, 0)
  236. .ATTR(time_major, Bool, true)
  237. .ATTR(activation, String, "tanh")
  238. .ATTR(forget_bias, Float, 0.0)
  239. .ATTR(is_training, Bool, true)
  240. .OP_END_FACTORY_REG(DynamicRNN)
  241. /**
  242. *@brief: LSTMInputGrad calculation.
  243. *@par Inputs:
  244. *ten inputs: \n
  245. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  246. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  247. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  248. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  249. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  250. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  251. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  252. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  253. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  254. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  255. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  256. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  257. *@par Outputs:
  258. *eight outputs: \n
  259. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  260. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  261. *@li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  262. */
  263. REG_OP(LSTMInputGrad)
  264. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  265. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  266. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  267. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  268. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  269. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  270. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  271. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  272. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  273. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  274. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  275. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  276. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  277. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  278. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  279. .OP_END_FACTORY_REG(LSTMInputGrad)
  280. /**
  281. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  282. *@par Inputs:
  283. *three inputs:
  284. *@li dgate:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  285. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  286. *@li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  287. *@par Attributes:
  288. *keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  289. *@par Outputs:
  290. *two outputs:
  291. *@li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  292. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  293. *@par Restrictions:
  294. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  295. */
  296. REG_OP(BasicLSTMCellInputGrad)
  297. .INPUT(dgate, TensorType({DT_FLOAT16}))
  298. .INPUT(w, TensorType({DT_FLOAT16}))
  299. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  300. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  301. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  302. .ATTR(keep_prob, Float, 1.0)
  303. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  304. /**
  305. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  306. *@par Inputs:
  307. *three inputs:
  308. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  309. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  310. *@li dgate:A 4D Tensor. Must be one of the following types: uint8. The format must be FRACTAL_NZ . \n
  311. *@par Outputs:
  312. *two outputs:
  313. *@li dw:A 4D Tensor. Must be one of the following types: float16.
  314. *@li db:A 4D Tensor. Must be one of the following types: float16, float32.
  315. *@par Restrictions:
  316. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  317. */
  318. REG_OP(BasicLSTMCellWeightGrad)
  319. .INPUT(x, TensorType({DT_FLOAT16}))
  320. .INPUT(h, TensorType({DT_FLOAT16}))
  321. .INPUT(dgate, TensorType({DT_FLOAT16}))
  322. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  323. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  324. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  325. /**
  326. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  327. *@par Inputs:
  328. *eight inputs:
  329. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  330. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  331. *@li dct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  332. *@li it:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  333. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  334. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  335. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  336. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  337. *@par Attributes:
  338. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  339. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  340. *@par Outputs:
  341. *two outputs:
  342. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  343. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  344. *@par Restrictions:
  345. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  346. */
  347. REG_OP(BasicLSTMCellCStateGrad)
  348. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  349. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  350. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  351. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  352. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  353. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  354. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  355. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  356. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  357. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  358. .ATTR(forget_bias, Float, 1.0)
  359. .ATTR(activation, String, "tanh")
  360. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  361. /**
  362. *@brief: RNN operator.
  363. *@par Inputs:
  364. *eight inputs:
  365. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  366. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  367. *@li x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  368. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  369. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  370. *@li w_sh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  371. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  372. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  373. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  374. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  375. *@par Attributes:
  376. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  377. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  378. *@par Outputs:
  379. *two outputs:
  380. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  381. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  382. *@par Restrictions:
  383. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  384. */
  385. REG_OP(RNN)
  386. .INPUT(x, TensorType({DT_FLOAT16}))
  387. .INPUT(cont, TensorType({DT_FLOAT16}))
  388. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  389. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  390. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  391. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  392. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  393. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  394. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  395. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  396. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  397. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  398. .ATTR(num_output, Int, 0)
  399. .ATTR(expose_hidden, Bool, false)
  400. .OP_END_FACTORY_REG(RNN)
  401. /**
  402. *@brief: BasicRNNCell operator.
  403. *@par Inputs:
  404. *eight inputs:
  405. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  406. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  407. *@li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  408. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  409. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  410. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  411. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  412. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  413. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  414. *@par Attributes:
  415. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  416. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  417. *@par Outputs:
  418. *two outputs:
  419. *@li o_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  420. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  421. *@par Restrictions:
  422. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  423. */
  424. REG_OP(BasicRNNCell)
  425. .INPUT(x, TensorType({DT_FLOAT16}))
  426. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  427. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  428. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  429. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  430. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  431. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  432. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  433. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  434. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  435. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  436. .ATTR(expose_hidden, Bool, false)
  437. .ATTR(num_output, Int, 0)
  438. .OP_END_FACTORY_REG(BasicRNNCell)
  439. /**
  440. *@brief: DynamicGRU calculation.
  441. *@par Inputs:
  442. *seven inputs: \n
  443. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  444. *@li w:Must be one of the following types: float16. The format must be FRACTAL_Z.
  445. *@li b:Must be one of the following types: float16, float32. The format must be ND.
  446. *@li cw:Must be one of the following types: float16. The format must be FRACTAL_Z.
  447. *@li cb:Must be one of the following types: float16, float32. The format must be ND.
  448. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  449. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  450. *@par Attributes:
  451. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  452. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  453. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  454. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  455. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  456. *@li time_major:An bool identifying the time major in the op. Default to true.
  457. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  458. *@li is_training:An bool identifying is training in the op. Default to true.
  459. *@par Outputs:
  460. *five outputs: \n
  461. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  462. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  463. *@li r:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  464. *@li i:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  465. *@li n:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  466. *@par Restrictions:
  467. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  468. */
  469. REG_OP(DynamicGRU)
  470. .INPUT(x, TensorType({DT_FLOAT16}))
  471. .INPUT(w, TensorType({DT_FLOAT16}))
  472. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  473. .INPUT(cw, TensorType({DT_FLOAT16}))
  474. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  475. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  476. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  477. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  478. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  479. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  480. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  481. .OUTPUT(n, TensorType({DT_FLOAT16, DT_FLOAT}))
  482. .ATTR(direction, String, "UNIDIRECTIONAL")
  483. .ATTR(cell_depth, Int, 1)
  484. .ATTR(keep_prob, Float, 1.0)
  485. .ATTR(cell_clip, Float, -1.0)
  486. .ATTR(num_proj, Int, 0)
  487. .ATTR(time_major, Bool, true)
  488. .ATTR(activation, String, "tanh")
  489. .ATTR(is_training, Bool, true)
  490. .OP_END_FACTORY_REG(DynamicGRU)
  491. /**
  492. *@brief: DynamicGRUV2 calculation.
  493. *@par Inputs:
  494. *seven inputs: \n
  495. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  496. *@li weight_input:Must be one of the following types: float16. The format must be FRACTAL_Z.
  497. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  498. *@li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  499. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  500. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  501. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  502. *@par Attributes:
  503. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  504. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  505. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  506. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  507. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  508. *@li time_major:An bool identifying the time major in the op. Default to true.
  509. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  510. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  511. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  512. *@li is_training:An bool identifying is training in the op. Default to true.
  513. *@par Outputs:
  514. *six outputs: \n
  515. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  516. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  517. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  518. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  519. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  520. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  521. *@par Restrictions:
  522. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  523. */
  524. REG_OP(DynamicGRUV2)
  525. .INPUT(x, TensorType({DT_FLOAT16}))
  526. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  527. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  528. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  529. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  530. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  531. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  532. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  533. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  534. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  535. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  536. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  537. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  538. .ATTR(direction, String, "UNIDIRECTIONAL")
  539. .ATTR(cell_depth, Int, 1)
  540. .ATTR(keep_prob, Float, 1.0)
  541. .ATTR(cell_clip, Float, -1.0)
  542. .ATTR(num_proj, Int, 0)
  543. .ATTR(time_major, Bool, true)
  544. .ATTR(activation, String, "tanh")
  545. .ATTR(gate_order, String, "zrh")
  546. .ATTR(reset_after, Bool, true)
  547. .ATTR(is_training, Bool, true)
  548. .OP_END_FACTORY_REG(DynamicGRUV2)
  549. /**
  550. *@brief: DynamicGRUV2Grad calculation.
  551. *@par Inputs:
  552. *fourteen inputs: \n
  553. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  554. *@li weight_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  555. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  556. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  557. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  558. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  559. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  560. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  561. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  562. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  563. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  564. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  565. *@li seq_length:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  566. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  567. *@par Attributes:
  568. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  569. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  570. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  571. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  572. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  573. *@li time_major:An bool identifying the time major in the op. Default to true.
  574. *@li bias_type:An string identifying the type of bias_type function in the op. Default to "double_bias".
  575. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  576. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  577. *@par Outputs:
  578. *six outputs: \n
  579. *@li dw_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  580. *@li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  581. *@li db_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  582. *@li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  583. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  584. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  585. */
  586. REG_OP(DynamicGRUV2Grad)
  587. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  588. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  589. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  590. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  591. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  592. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  593. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  594. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  595. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  596. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  597. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  598. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  599. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  600. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  601. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  602. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  603. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  604. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  605. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  606. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  607. .ATTR(direction, String, "UNIDIRECTIONAL")
  608. .ATTR(cell_depth, Int, 0)
  609. .ATTR(keep_prob, Float, -1.0)
  610. .ATTR(cell_clip, Float, -1.0)
  611. .ATTR(num_proj, Int, 0)
  612. .ATTR(time_major, Bool, true)
  613. .ATTR(bias_type, String, "double_bias")
  614. .ATTR(gate_order, String, "zrh")
  615. .ATTR(reset_after, Bool, true)
  616. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  617. /**
  618. *@brief: GRUV2HiddenGrad calculation.
  619. *@par Inputs:
  620. *nine inputs: \n
  621. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  622. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  623. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  624. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  625. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  626. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  627. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  628. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  629. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  630. *@par Attributes:
  631. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  632. *@par Outputs:
  633. *three outputs: \n
  634. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  635. *@li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  636. *@li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  637. */
  638. REG_OP(GRUV2HiddenGrad)
  639. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  640. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  641. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  642. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  643. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  644. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  645. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  646. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  647. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  648. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  649. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  650. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  651. .ATTR(gate_order, String, "zrh")
  652. .OP_END_FACTORY_REG(GRUV2HiddenGrad)
  653. } // namespace ge
  654. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示