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 47 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /**
  2. * Copyright 2019 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: DynamicLSTMV2 calculation.
  243. *@par Inputs:
  244. *ten inputs:
  245. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  246. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  247. *@li b:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  248. *@li cont:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  249. *@li w_xc_x_static:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  250. *@li h0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  251. *@li c0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  252. *@li wci:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  253. *@li wcf:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  254. *@li wco:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  255. *@li mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  256. *@par Attributes:
  257. *@li num_output:An integer identifying the num projection in the op. Default to 0.
  258. *@li expose_hidden:An bool identifying the expose_hidden in the op. Default to flase.
  259. *@li need_output_last:An bool identifying the time major in the op. Default to true.
  260. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  261. *@par Outputs:
  262. *eight outputs:
  263. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  264. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  265. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  266. *@li last_output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  267. *@li last_output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  268. */
  269. REG_OP(DynamicLSTMV2)
  270. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  271. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  272. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  273. .INPUT(cont, TensorType({DT_FLOAT16, DT_FLOAT}))
  274. .OPTIONAL_INPUT(w_xc_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  275. .OPTIONAL_INPUT(h0, TensorType({DT_FLOAT16, DT_FLOAT}))
  276. .OPTIONAL_INPUT(c0, TensorType({DT_FLOAT16, DT_FLOAT}))
  277. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  278. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  279. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  280. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  281. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  282. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  283. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  284. .OUTPUT(last_output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  285. .OUTPUT(last_output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  286. .ATTR(num_output, Int, 0)
  287. .ATTR(expose_hidden, Bool, false)
  288. .ATTR(need_output_last, Bool, false)
  289. .ATTR(forget_bias, Float, 0.0)
  290. .OP_END_FACTORY_REG(DynamicLSTMV2)
  291. /**
  292. *@brief: LSTMInputGrad calculation.
  293. *@par Inputs:
  294. *ten inputs: \n
  295. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  296. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  297. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  298. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  299. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  300. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  301. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  302. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  303. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  304. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  305. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  306. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  307. *@par Outputs:
  308. *eight outputs: \n
  309. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  310. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  311. *@li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  312. */
  313. REG_OP(LSTMInputGrad)
  314. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  315. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  316. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  317. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  318. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  319. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  320. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  321. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  322. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  323. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  324. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  325. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  326. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  327. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  328. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  329. .OP_END_FACTORY_REG(LSTMInputGrad)
  330. /**
  331. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  332. *@par Inputs:
  333. *three inputs:
  334. *@li dgate:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  335. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  336. *@li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  337. *@par Attributes:
  338. *keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  339. *@par Outputs:
  340. *two outputs:
  341. *@li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  342. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  343. *@par Restrictions:
  344. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  345. */
  346. REG_OP(BasicLSTMCellInputGrad)
  347. .INPUT(dgate, TensorType({DT_FLOAT16}))
  348. .INPUT(w, TensorType({DT_FLOAT16}))
  349. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  350. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  351. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  352. .ATTR(keep_prob, Float, 1.0)
  353. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  354. /**
  355. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  356. *@par Inputs:
  357. *three inputs:
  358. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  359. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  360. *@li dgate:A 4D Tensor. Must be one of the following types: uint8. The format must be FRACTAL_NZ . \n
  361. *@par Outputs:
  362. *two outputs:
  363. *@li dw:A 4D Tensor. Must be one of the following types: float16.
  364. *@li db:A 4D Tensor. Must be one of the following types: float16, float32.
  365. *@par Restrictions:
  366. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  367. */
  368. REG_OP(BasicLSTMCellWeightGrad)
  369. .INPUT(x, TensorType({DT_FLOAT16}))
  370. .INPUT(h, TensorType({DT_FLOAT16}))
  371. .INPUT(dgate, TensorType({DT_FLOAT16}))
  372. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  373. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  374. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  375. /**
  376. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  377. *@par Inputs:
  378. *eight inputs:
  379. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  380. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  381. *@li dct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  382. *@li it:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  383. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  384. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  385. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  386. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  387. *@par Attributes:
  388. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  389. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  390. *@par Outputs:
  391. *two outputs:
  392. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  393. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  394. *@par Restrictions:
  395. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  396. */
  397. REG_OP(BasicLSTMCellCStateGrad)
  398. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  399. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  400. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  401. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  402. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  403. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  404. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  405. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  406. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  407. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  408. .ATTR(forget_bias, Float, 1.0)
  409. .ATTR(activation, String, "tanh")
  410. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  411. /**
  412. *@brief: RNN operator.
  413. *@par Inputs:
  414. *eight inputs:
  415. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  416. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  417. *@li x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  418. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  419. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  420. *@li w_sh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  421. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  422. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  423. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  424. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  425. *@par Attributes:
  426. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  427. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  428. *@par Outputs:
  429. *two outputs:
  430. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  431. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  432. *@par Restrictions:
  433. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  434. */
  435. REG_OP(RNN)
  436. .INPUT(x, TensorType({DT_FLOAT16}))
  437. .INPUT(cont, TensorType({DT_FLOAT16}))
  438. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  439. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  440. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  441. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  442. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  443. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  444. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  445. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  446. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  447. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  448. .ATTR(num_output, Int, 0)
  449. .ATTR(expose_hidden, Bool, false)
  450. .OP_END_FACTORY_REG(RNN)
  451. /**
  452. *@brief: BasicRNNCell operator.
  453. *@par Inputs:
  454. *eight inputs:
  455. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  456. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  457. *@li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  458. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  459. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  460. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  461. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  462. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  463. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  464. *@par Attributes:
  465. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  466. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  467. *@par Outputs:
  468. *two outputs:
  469. *@li o_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  470. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  471. *@par Restrictions:
  472. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  473. */
  474. REG_OP(BasicRNNCell)
  475. .INPUT(x, TensorType({DT_FLOAT16}))
  476. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  477. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  478. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  479. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  480. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  481. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  482. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  483. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  484. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  485. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  486. .ATTR(expose_hidden, Bool, false)
  487. .ATTR(num_output, Int, 0)
  488. .OP_END_FACTORY_REG(BasicRNNCell)
  489. /**
  490. *@brief DynamicGRU calculation.
  491. *@par Inputs:
  492. *seven inputs:
  493. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  494. *@li w:Must be one of the following types: float16. The format must be FRACTAL_Z.
  495. *@li b:Must be one of the following types: float16, float32. The format must be ND.
  496. *@li cw:Must be one of the following types: float16. The format must be FRACTAL_Z.
  497. *@li cb:Must be one of the following types: float16, float32. The format must be ND.
  498. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  499. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  500. *@par Attributes:
  501. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  502. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  503. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  504. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  505. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  506. *@li time_major:An bool identifying the time major in the op. Default to true.
  507. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  508. *@li is_training:An bool identifying is training in the op. Default to true.
  509. *@par Outputs:
  510. *five outputs:
  511. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  512. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  513. *@li r:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  514. *@li i:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  515. *@li n:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  516. *@par Restrictions:
  517. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  518. */
  519. REG_OP(DynamicGRU)
  520. .INPUT(x, TensorType({DT_FLOAT16}))
  521. .INPUT(w, TensorType({DT_FLOAT16}))
  522. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  523. .INPUT(cw, TensorType({DT_FLOAT16}))
  524. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  525. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  526. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  527. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  528. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  529. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  530. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  531. .OUTPUT(n, TensorType({DT_FLOAT16, DT_FLOAT}))
  532. .ATTR(direction, String, "UNIDIRECTIONAL")
  533. .ATTR(cell_depth, Int, 1)
  534. .ATTR(keep_prob, Float, 1.0)
  535. .ATTR(cell_clip, Float, -1.0)
  536. .ATTR(num_proj, Int, 0)
  537. .ATTR(time_major, Bool, true)
  538. .ATTR(activation, String, "tanh")
  539. .ATTR(is_training, Bool, true)
  540. .OP_END_FACTORY_REG(DynamicGRU)
  541. /**
  542. *@brief DynamicGRUV2 calculation.
  543. *@par Inputs:
  544. *seven inputs:
  545. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  546. *@li weight_input:Must be one of the following types: float16. The format must be FRACTAL_Z.
  547. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  548. *@li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  549. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  550. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  551. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  552. *@par Attributes:
  553. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  554. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  555. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  556. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  557. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  558. *@li time_major:An bool identifying the time major in the op. Default to true.
  559. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  560. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  561. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  562. *@li is_training:An bool identifying is training in the op. Default to true.
  563. *@par Outputs:
  564. *six outputs:
  565. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  566. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  567. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  568. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  569. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  570. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  571. *@par Restrictions:
  572. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  573. */
  574. REG_OP(DynamicGRUV2)
  575. .INPUT(x, TensorType({DT_FLOAT16}))
  576. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  577. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  578. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  579. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  580. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  581. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  582. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  583. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  584. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  585. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  586. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  587. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  588. .ATTR(direction, String, "UNIDIRECTIONAL")
  589. .ATTR(cell_depth, Int, 1)
  590. .ATTR(keep_prob, Float, 1.0)
  591. .ATTR(cell_clip, Float, -1.0)
  592. .ATTR(num_proj, Int, 0)
  593. .ATTR(time_major, Bool, true)
  594. .ATTR(activation, String, "tanh")
  595. .ATTR(gate_order, String, "zrh")
  596. .ATTR(reset_after, Bool, true)
  597. .ATTR(is_training, Bool, true)
  598. .OP_END_FACTORY_REG(DynamicGRUV2)
  599. /**
  600. *@brief DynamicGRUV2Hidden calculation.
  601. *@par Inputs:
  602. *five inputs:
  603. *@li x_weight_input:Must be one of the following types: float32. The format must be FRACTAL_NZ.
  604. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  605. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  606. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  607. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  608. *@par Attributes:
  609. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  610. Only UNIDIRECTIONAL is currently supported.
  611. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  612. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  613. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  614. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  615. *@li time_major:An bool identifying the time major in the op. Default to true.
  616. *@li activation:An string identifying the type of activation function in the op. Default to "tanh".
  617. Only tanh is currently supported.
  618. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  619. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  620. *@li is_training:An bool identifying is training in the op. Default to true.
  621. *@par Outputs:
  622. *six outputs:
  623. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  624. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  625. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  626. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  627. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  628. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  629. *@par Restrictions:
  630. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  631. */
  632. REG_OP(DynamicGRUV2Hidden)
  633. .INPUT(x_weight_input, TensorType({DT_FLOAT32}))
  634. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  635. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  636. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  637. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  638. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  639. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  640. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  641. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  642. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  643. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  644. .ATTR(direction, String, "UNIDIRECTIONAL")
  645. .ATTR(cell_depth, Int, 1)
  646. .ATTR(keep_prob, Float, 1.0)
  647. .ATTR(cell_clip, Float, -1.0)
  648. .ATTR(num_proj, Int, 0)
  649. .ATTR(time_major, Bool, true)
  650. .ATTR(activation, String, "tanh")
  651. .ATTR(gate_order, String, "zrh")
  652. .ATTR(reset_after, Bool, true)
  653. .ATTR(is_training, Bool, true)
  654. .OP_END_FACTORY_REG(DynamicGRUV2Hidden)
  655. /**
  656. *@brief: DynamicGRUV2Grad calculation.
  657. *@par Inputs:
  658. *fourteen inputs: \n
  659. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  660. *@li weight_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  661. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  662. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  663. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  664. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  665. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  666. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  667. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  668. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  669. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  670. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  671. *@li seq_length:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  672. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  673. *@par Attributes:
  674. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  675. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  676. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  677. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  678. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  679. *@li time_major:An bool identifying the time major in the op. Default to true.
  680. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  681. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  682. *@par Outputs:
  683. *six outputs: \n
  684. *@li dw_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  685. *@li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  686. *@li db_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  687. *@li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  688. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  689. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  690. *@par Restrictions:
  691. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  692. */
  693. REG_OP(DynamicGRUV2Grad)
  694. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  695. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  696. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  697. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  698. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  699. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  700. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  701. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  702. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  703. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  704. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  705. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  706. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  707. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  708. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  709. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  710. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  711. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  712. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  713. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  714. .ATTR(direction, String, "UNIDIRECTIONAL")
  715. .ATTR(cell_depth, Int, 0)
  716. .ATTR(keep_prob, Float, -1.0)
  717. .ATTR(cell_clip, Float, -1.0)
  718. .ATTR(num_proj, Int, 0)
  719. .ATTR(time_major, Bool, true)
  720. .ATTR(gate_order, String, "zrh")
  721. .ATTR(reset_after, Bool, true)
  722. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  723. /**
  724. *@brief: GRUV2HiddenGrad calculation.
  725. *@par Inputs:
  726. *nine inputs: \n
  727. *@li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  728. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  729. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  730. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  731. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  732. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  733. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  734. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  735. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  736. *@par Attributes:
  737. *@li t_state:An Int identifying the current t state. Default to [0, 4].
  738. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  739. *@par Outputs:
  740. *three outputs: \n
  741. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  742. *@li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  743. *@li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  744. *@par Restrictions:
  745. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  746. */
  747. REG_OP(GRUV2HiddenGradCell)
  748. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  749. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  750. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  751. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  752. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  753. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  754. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  755. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  756. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  757. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  758. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  759. .ATTR(t_state, Int, 0)
  760. .ATTR(gate_order, String, "zrh")
  761. .OP_END_FACTORY_REG(GRUV2HiddenGradCell)
  762. /**
  763. * @brief Calculates the reversed outputs of the function "embedding". \n
  764. * @par Inputs:
  765. * Two inputs, including:
  766. * @li grad: A mutable Tensor of word grad. Must be one of the following types:
  767. * float32.
  768. * @li indices: A mutable word index Tensor of the int32 type.\n
  769. * @par Attributes:
  770. * @li num_weights: An int attr which use to judge how many words in dict. \n
  771. * @li padding_idx: An int attr judge which word to fill zeros. Defaults to "-1". \n
  772. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  773. * If "True", "grad_weight" will be scale by word_frequency.
  774. * If "False", "grad_weight" will not be scale by word_frequency. \n
  775. * @par Outputs:
  776. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  777. * @par Third-party framework compatibility
  778. * Compatible with the Pytorch operator EmbeddingDenseGrad.
  779. */
  780. REG_OP(EmbeddingDenseGrad)
  781. .INPUT(grad, TensorType({ DT_FLOAT32 })) /* "First operand." */
  782. .INPUT(indices, TensorType({ DT_INT32 })) /* "Second operand." */
  783. .OUTPUT(y, TensorType({ DT_FLOAT32 })) /* "Result, has same element type as two inputs" */
  784. .REQUIRED_ATTR(num_weights, Int)
  785. .ATTR(padding_idx, Int, -1)
  786. .ATTR(scale_grad_by_freq, Bool, false)
  787. .OP_END_FACTORY_REG(EmbeddingDenseGrad)
  788. } // namespace ge
  789. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

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