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 53 kB

5 years ago
4 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
4 years ago
4 years ago
4 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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 required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  178. *@li w:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  179. *@li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  180. *@li seq_length:A optional 1D Tensor. Must be one of the following types: int32. The format must be ND.
  181. *@li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  182. *@li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  183. *@li wci:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  184. *@li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  185. *@li wco:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  186. *@li mask:A 1D optional 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. *@par Third-party framework compatibility:
  210. * Compatible with the TF operator LSTM.
  211. */
  212. REG_OP(DynamicRNN)
  213. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  214. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  215. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  216. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  217. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  218. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  219. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  220. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  221. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  222. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  223. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  224. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  225. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  226. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  227. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  228. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  229. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  230. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  231. .ATTR(cell_type, String, "LSTM")
  232. .ATTR(direction, String, "UNIDIRECTIONAL")
  233. .ATTR(cell_depth, Int, 1)
  234. .ATTR(use_peephole, Bool, false)
  235. .ATTR(keep_prob, Float, 1.0)
  236. .ATTR(cell_clip, Float, -1.0)
  237. .ATTR(num_proj, Int, 0)
  238. .ATTR(time_major, Bool, true)
  239. .ATTR(activation, String, "tanh")
  240. .ATTR(forget_bias, Float, 0.0)
  241. .ATTR(is_training, Bool, true)
  242. .OP_END_FACTORY_REG(DynamicRNN)
  243. /**
  244. *@brief: DynamicLSTMV2 calculation.
  245. *@par Inputs:
  246. *ten inputs:
  247. *@li x:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  248. *@li w:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  249. *@li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  250. *@li cont:A required 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  251. *@li w_xc_x_static:A optional 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  252. *@li h0:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  253. *@li c0:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  254. *@li wci:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  255. *@li wcf:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  256. *@li wco:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  257. *@li mask:A optional 1D Tensor. Must be one of the following types: uint8. The format must be ND .
  258. *@par Attributes:
  259. *@li num_output:An integer identifying the num projection in the op. Default to 0.
  260. *@li expose_hidden:An bool identifying the expose_hidden in the op. Default to flase.
  261. *@li need_output_last:An bool identifying the time major in the op. Default to true.
  262. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  263. *@par Outputs:
  264. *eight outputs:
  265. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  266. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  267. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  268. *@li last_output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  269. *@li last_output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  270. *@par Third-party framework compatibility:
  271. * Compatible with the Caffe operator LSTM.
  272. *@par Restrictions:
  273. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  274. */
  275. REG_OP(DynamicLSTMV2)
  276. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  277. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  278. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  279. .INPUT(cont, TensorType({DT_FLOAT16, DT_FLOAT}))
  280. .OPTIONAL_INPUT(w_xc_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  281. .OPTIONAL_INPUT(h0, TensorType({DT_FLOAT16, DT_FLOAT}))
  282. .OPTIONAL_INPUT(c0, TensorType({DT_FLOAT16, DT_FLOAT}))
  283. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  284. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  285. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  286. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  287. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  288. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  289. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  290. .OUTPUT(last_output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  291. .OUTPUT(last_output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  292. .ATTR(num_output, Int, 0)
  293. .ATTR(expose_hidden, Bool, false)
  294. .ATTR(need_output_last, Bool, false)
  295. .ATTR(forget_bias, Float, 0.0)
  296. .OP_END_FACTORY_REG(DynamicLSTMV2)
  297. /**
  298. *@brief: LSTMInputGrad calculation.
  299. *@par Inputs:
  300. *ten inputs: \n
  301. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  302. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  303. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  304. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  305. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  306. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  307. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  308. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  309. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  310. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  311. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  312. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  313. *@par Outputs:
  314. *eight outputs: \n
  315. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  316. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  317. *@li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  318. */
  319. REG_OP(LSTMInputGrad)
  320. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  321. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  322. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  323. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  324. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  325. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  326. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  327. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  328. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  329. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  330. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  331. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  332. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  333. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  334. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  335. .OP_END_FACTORY_REG(LSTMInputGrad)
  336. /**
  337. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  338. *@par Inputs:
  339. *three inputs:
  340. *@li dgate:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  341. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  342. *@li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  343. *@par Attributes:
  344. *keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  345. *@par Outputs:
  346. *two outputs:
  347. *@li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  348. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  349. *@par Restrictions:
  350. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  351. */
  352. REG_OP(BasicLSTMCellInputGrad)
  353. .INPUT(dgate, TensorType({DT_FLOAT16}))
  354. .INPUT(w, TensorType({DT_FLOAT16}))
  355. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  356. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  357. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  358. .ATTR(keep_prob, Float, 1.0)
  359. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  360. /**
  361. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  362. *@par Inputs:
  363. *three inputs:
  364. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  365. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  366. *@li dgate:A 4D Tensor. Must be one of the following types: uint8. The format must be FRACTAL_NZ . \n
  367. *@par Outputs:
  368. *two outputs:
  369. *@li dw:A 4D Tensor. Must be one of the following types: float16.
  370. *@li db:A 4D Tensor. Must be one of the following types: float16, float32.
  371. *@par Restrictions:
  372. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  373. */
  374. REG_OP(BasicLSTMCellWeightGrad)
  375. .INPUT(x, TensorType({DT_FLOAT16}))
  376. .INPUT(h, TensorType({DT_FLOAT16}))
  377. .INPUT(dgate, TensorType({DT_FLOAT16}))
  378. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  379. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  380. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  381. /**
  382. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  383. *@par Inputs:
  384. *eight inputs:
  385. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  386. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  387. *@li dct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  388. *@li it:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  389. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  390. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  391. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  392. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  393. *@par Attributes:
  394. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  395. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  396. *@par Outputs:
  397. *two outputs:
  398. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  399. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  400. *@par Restrictions:
  401. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  402. */
  403. REG_OP(BasicLSTMCellCStateGrad)
  404. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  405. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  406. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  407. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  408. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  409. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  410. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  411. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  412. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  413. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  414. .ATTR(forget_bias, Float, 1.0)
  415. .ATTR(activation, String, "tanh")
  416. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  417. /**
  418. *@brief: RNN operator.
  419. *@par Inputs:
  420. *eight inputs:
  421. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  422. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  423. *@li x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  424. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  425. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  426. *@li w_sh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  427. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  428. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  429. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  430. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  431. *@par Attributes:
  432. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  433. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  434. *@par Outputs:
  435. *two outputs:
  436. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  437. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  438. *@par Restrictions:
  439. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  440. */
  441. REG_OP(RNN)
  442. .INPUT(x, TensorType({DT_FLOAT16}))
  443. .INPUT(cont, TensorType({DT_FLOAT16}))
  444. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  445. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  446. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  447. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  448. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  449. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  450. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  451. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  452. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  453. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  454. .ATTR(num_output, Int, 0)
  455. .ATTR(expose_hidden, Bool, false)
  456. .OP_END_FACTORY_REG(RNN)
  457. /**
  458. *@brief: BasicRNNCell operator.
  459. *@par Inputs:
  460. *eight inputs:
  461. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  462. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  463. *@li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  464. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  465. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  466. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  467. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  468. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  469. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  470. *@par Attributes:
  471. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  472. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  473. *@par Outputs:
  474. *two outputs:
  475. *@li o_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  476. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  477. *@par Restrictions:
  478. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  479. */
  480. REG_OP(BasicRNNCell)
  481. .INPUT(x, TensorType({DT_FLOAT16}))
  482. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  483. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  484. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  485. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  486. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  487. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  488. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  489. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  490. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  491. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  492. .ATTR(expose_hidden, Bool, false)
  493. .ATTR(num_output, Int, 0)
  494. .OP_END_FACTORY_REG(BasicRNNCell)
  495. /**
  496. *@brief DynamicGRU calculation.
  497. *@par Inputs:
  498. *seven inputs:
  499. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  500. *@li w:Must be one of the following types: float16. The format must be FRACTAL_Z.
  501. *@li b:Must be one of the following types: float16, float32. The format must be ND.
  502. *@li cw:Must be one of the following types: float16. The format must be FRACTAL_Z.
  503. *@li cb:Must be one of the following types: float16, float32. The format must be ND.
  504. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  505. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  506. *@par Attributes:
  507. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  508. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  509. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  510. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  511. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  512. *@li time_major:An bool identifying the time major in the op. Default to true.
  513. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  514. *@li is_training:An bool identifying is training in the op. Default to true.
  515. *@par Outputs:
  516. *five outputs:
  517. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  518. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  519. *@li r:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  520. *@li i:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  521. *@li n:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  522. *@par Restrictions:
  523. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  524. */
  525. REG_OP(DynamicGRU)
  526. .INPUT(x, TensorType({DT_FLOAT16}))
  527. .INPUT(w, TensorType({DT_FLOAT16}))
  528. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  529. .INPUT(cw, TensorType({DT_FLOAT16}))
  530. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  531. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  532. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  533. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  534. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  535. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  536. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  537. .OUTPUT(n, 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(is_training, Bool, true)
  546. .OP_END_FACTORY_REG(DynamicGRU)
  547. /**
  548. *@brief DynamicGRUV2 calculation.
  549. *@par Inputs:
  550. *seven inputs:
  551. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  552. *@li weight_input:Must be one of the following types: float16. The format must be FRACTAL_Z.
  553. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  554. *@li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  555. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  556. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  557. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  558. *@par Attributes:
  559. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  560. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  561. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  562. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  563. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  564. *@li time_major:An bool identifying the time major in the op. Default to true.
  565. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  566. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  567. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  568. *@li is_training:An bool identifying is training in the op. Default to true.
  569. *@par Outputs:
  570. *six outputs:
  571. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  572. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  573. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  574. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  575. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  576. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  577. *@par Restrictions:
  578. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  579. */
  580. REG_OP(DynamicGRUV2)
  581. .INPUT(x, TensorType({DT_FLOAT16}))
  582. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  583. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  584. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  585. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  586. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  587. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  588. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  589. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  590. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  591. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  592. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  593. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  594. .ATTR(direction, String, "UNIDIRECTIONAL")
  595. .ATTR(cell_depth, Int, 1)
  596. .ATTR(keep_prob, Float, 1.0)
  597. .ATTR(cell_clip, Float, -1.0)
  598. .ATTR(num_proj, Int, 0)
  599. .ATTR(time_major, Bool, true)
  600. .ATTR(activation, String, "tanh")
  601. .ATTR(gate_order, String, "zrh")
  602. .ATTR(reset_after, Bool, true)
  603. .ATTR(is_training, Bool, true)
  604. .OP_END_FACTORY_REG(DynamicGRUV2)
  605. /**
  606. *@brief DynamicGRUV2Hidden calculation.
  607. *@par Inputs:
  608. *five inputs:
  609. *@li x_weight_input:Must be one of the following types: float32. The format must be FRACTAL_NZ.
  610. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  611. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  612. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  613. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  614. *@par Attributes:
  615. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  616. Only UNIDIRECTIONAL is currently supported.
  617. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  618. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  619. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  620. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  621. *@li time_major:An bool identifying the time major in the op. Default to true.
  622. *@li activation:An string identifying the type of activation function in the op. Default to "tanh".
  623. Only tanh is currently supported.
  624. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  625. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  626. *@li is_training:An bool identifying is training in the op. Default to true.
  627. *@par Outputs:
  628. *six outputs:
  629. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  630. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  631. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  632. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  633. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  634. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  635. *@par Restrictions:
  636. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  637. */
  638. REG_OP(DynamicGRUV2Hidden)
  639. .INPUT(x_weight_input, TensorType({DT_FLOAT32}))
  640. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  641. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  642. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  643. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  644. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  645. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  646. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  647. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  648. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  649. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  650. .ATTR(direction, String, "UNIDIRECTIONAL")
  651. .ATTR(cell_depth, Int, 1)
  652. .ATTR(keep_prob, Float, 1.0)
  653. .ATTR(cell_clip, Float, -1.0)
  654. .ATTR(num_proj, Int, 0)
  655. .ATTR(time_major, Bool, true)
  656. .ATTR(activation, String, "tanh")
  657. .ATTR(gate_order, String, "zrh")
  658. .ATTR(reset_after, Bool, true)
  659. .ATTR(is_training, Bool, true)
  660. .OP_END_FACTORY_REG(DynamicGRUV2Hidden)
  661. /**
  662. *@brief: DynamicGRUV2Grad calculation.
  663. *@par Inputs:
  664. *fourteen inputs: \n
  665. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  666. *@li weight_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  667. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  668. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  669. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  670. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  671. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  672. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  673. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  674. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  675. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  676. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  677. *@li seq_length:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  678. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  679. *@par Attributes:
  680. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  681. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  682. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  683. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  684. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  685. *@li time_major:An bool identifying the time major in the op. Default to true.
  686. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  687. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  688. *@par Outputs:
  689. *six outputs: \n
  690. *@li dw_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  691. *@li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  692. *@li db_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  693. *@li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  694. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  695. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  696. *@par Restrictions:
  697. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  698. */
  699. REG_OP(DynamicGRUV2Grad)
  700. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  701. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  702. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  703. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  704. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  705. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  706. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  707. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  708. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  709. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  710. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  711. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  712. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  713. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  714. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  715. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  716. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  717. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  718. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  719. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  720. .ATTR(direction, String, "UNIDIRECTIONAL")
  721. .ATTR(cell_depth, Int, 0)
  722. .ATTR(keep_prob, Float, -1.0)
  723. .ATTR(cell_clip, Float, -1.0)
  724. .ATTR(num_proj, Int, 0)
  725. .ATTR(time_major, Bool, true)
  726. .ATTR(gate_order, String, "zrh")
  727. .ATTR(reset_after, Bool, true)
  728. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  729. /**
  730. *@brief: GRUV2HiddenGrad calculation.
  731. *@par Inputs:
  732. *nine inputs: \n
  733. *@li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  734. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  735. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  736. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  737. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  738. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  739. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  740. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  741. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  742. *@par Attributes:
  743. *@li t_state:An Int identifying the current t state. Default to [0, 4].
  744. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  745. *@par Outputs:
  746. *three outputs: \n
  747. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  748. *@li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  749. *@li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  750. *@par Restrictions:
  751. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  752. */
  753. REG_OP(GRUV2HiddenGradCell)
  754. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  755. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  756. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  757. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  758. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  759. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  760. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  761. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  762. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  763. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  764. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  765. .ATTR(t_state, Int, 0)
  766. .ATTR(gate_order, String, "zrh")
  767. .OP_END_FACTORY_REG(GRUV2HiddenGradCell)
  768. /**
  769. * @brief Calculates the reversed outputs of the function "embedding". \n
  770. * @par Inputs:
  771. * Two inputs, including:
  772. * @li grad: A mutable Tensor of word grad. Must be one of the following types:
  773. * float32.
  774. * @li indices: A mutable word index Tensor of the int32 type.\n
  775. * @par Attributes:
  776. * @li num_weights: An int attr which use to judge how many words in dict. \n
  777. * @li padding_idx: An int attr judge which word to fill zeros. Defaults to "-1". \n
  778. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  779. * If "True", "grad_weight" will be scale by word_frequency.
  780. * If "False", "grad_weight" will not be scale by word_frequency. \n
  781. * @par Outputs:
  782. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  783. * @par Third-party framework compatibility
  784. * Compatible with the Pytorch operator EmbeddingDenseGrad.
  785. */
  786. REG_OP(EmbeddingDenseGrad)
  787. .INPUT(grad, TensorType({ DT_FLOAT32 })) /* "First operand." */
  788. .INPUT(indices, TensorType({ DT_INT32 })) /* "Second operand." */
  789. .OUTPUT(y, TensorType({ DT_FLOAT32 })) /* "Result, has same element type as two inputs" */
  790. .REQUIRED_ATTR(num_weights, Int)
  791. .ATTR(padding_idx, Int, -1)
  792. .ATTR(scale_grad_by_freq, Bool, false)
  793. .OP_END_FACTORY_REG(EmbeddingDenseGrad)
  794. /**
  795. *@brief CommonLSTM calculation.
  796. *@par Inputs:
  797. *eight inputs: \n
  798. *@li x:Each time step is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  799. *@li w:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  800. *@li r:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  801. *@li b:An optional input. Each direction is a 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  802. *@li sequence_lens:An optional input. A 1D Tensor.Must be one of the following types: int32. The format must be ND.
  803. *@li initial_h:An optional input. Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  804. *@li initial_c:An optional input. Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  805. *@li p:An optional input. Each direction is a 1D Tensor.Must be one of the following types: float16, float32. The format must be ND.
  806. *@par Attributes:
  807. *@li activation_alpha:Optional scaling values used by some activation functions. Empty is currently supported.
  808. *@li activation_beta:Optional scaling values used by some activation functions. Empty is currently supported.
  809. *@li activations:The list of activation functions. Empty is currently supported.
  810. *@li clip:An float identifying the cell clip in the op. Default to -1.
  811. *@li direction:Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward(default), reverse, or bidirectional.
  812. *@li hidden_size:Number of neurons in the hidden layer. Reserved.
  813. *@li input_forget:Couple the input and forget gates if 1. Reserved.
  814. *@par Outputs:
  815. *three outputs: \n
  816. *@li y:First dimension is time step, second dimension is direction, others is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  817. *@li y_h:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  818. *@li y_c:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  819. */
  820. REG_OP(CommonLSTM)
  821. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  822. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  823. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  824. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  825. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  826. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  827. .OPTIONAL_INPUT(initial_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  828. .OPTIONAL_INPUT(p, TensorType({DT_FLOAT16, DT_FLOAT}))
  829. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  830. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  831. .OUTPUT(y_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  832. .ATTR(activation_alpha, ListFloat, {})
  833. .ATTR(activation_beta, ListFloat, {})
  834. .ATTR(activations, ListString, {})
  835. .ATTR(clip, Float, -1.0)
  836. .ATTR(direction, String, "forward")
  837. .REQUIRED_ATTR(hidden_size, Int)
  838. .ATTR(input_forget, Int, 0)
  839. .OP_END_FACTORY_REG(CommonLSTM)
  840. /**
  841. * @brief Common GRU calculation.
  842. * @par Inputs:
  843. * Eight inputs, including:
  844. * @li x: The input sequences packed (and pontentially padded) into on 3D Tesnor(float16). The format must be FRACTAL_NZ
  845. * @li w: The weight tensor for the gates is 3D Tensor(float16). The format must be FRACTAL_Z
  846. * @li r: The recurrence weight tesnor is 3D Tensor(float16). The format must be FRACTAL_Z
  847. * @li b: The bias tensor for the gates. The format must be ND
  848. * @li sequence_lens: Optional tensor specifying lengths of sequences(int32). The format must be ND
  849. * @li init_h: Optional initial value of the hidden(float16,float32). The format must be FRACTAL_NZ
  850. * @par Attributes:
  851. * @li activation_alpha: Optional scaling values used by some activation functions. \n
  852. * @li activation_beta: Optional scaling values used by some activation functions. \n
  853. * @li activations: A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. \n
  854. * @li clip: Cell clip threshold. \n
  855. * @li direction: Specify if the RNN is forward, reverse, or bidirectional. \n
  856. * @li hidden_size: Number of neurons in the hidden layer. \n
  857. * @li linear_before_reset: When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate. \n
  858. * @par Outputs:
  859. * @li y: A Tensor that concats all the intermediate output values of the hidden(float16,float32). The format must be FRACTAL_NZ
  860. * @li y_h: The last output value of the hidden(float16,float32). The format must be FRACTAL_NZ
  861. */
  862. REG_OP(CommonGRU)
  863. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  864. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  865. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  866. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  867. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  868. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  869. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  870. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  871. .ATTR(activation_alpha, ListFloat, {})
  872. .ATTR(activation_beta , ListFloat, {})
  873. .ATTR(activations , ListString, {})
  874. .ATTR(clip, Float, -1.0)
  875. .ATTR(direction, String, "forward")
  876. .REQUIRED_ATTR(hidden_size, Int)
  877. .ATTR(linear_before_reset , Int, 0)
  878. .OP_END_FACTORY_REG(CommonGRU)
  879. } // namespace ge
  880. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

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