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

5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 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
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
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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. *@li mask:A 1D Tensor. Must be one of the following types: uint8.
  34. *@par Attributes:
  35. *@li keep_prob:An integer identifying the keep prob in the op. Default to 1.
  36. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  37. *@li state_is_tuple:An bool identifying if the hidden state and cell state is tuple. Default to true.
  38. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  39. *@par Outputs:
  40. *seven outputs:
  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 Tensor. Only Support float16 in FRACTAL_NZ and int32 in 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 gate_order:An string identifying the type of gate order in the op. Support "ijfo" and "ifjo". Default to "ijfo".
  199. *@li is_training:An bool identifying is training in the op. Default to true . \n
  200. *@par Outputs:
  201. *eight outputs:
  202. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  203. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  204. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  205. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  206. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  207. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  208. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  209. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  210. *@par Third-party framework compatibility:
  211. * Compatible with the TF operator LSTM.
  212. */
  213. REG_OP(DynamicRNN)
  214. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  215. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  216. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  217. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32, DT_FLOAT16}))
  218. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  219. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  220. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  221. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  222. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  223. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  224. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  225. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  226. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  227. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  228. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  229. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  230. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  231. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  232. .ATTR(cell_type, String, "LSTM")
  233. .ATTR(direction, String, "UNIDIRECTIONAL")
  234. .ATTR(cell_depth, Int, 1)
  235. .ATTR(use_peephole, Bool, false)
  236. .ATTR(keep_prob, Float, 1.0)
  237. .ATTR(cell_clip, Float, -1.0)
  238. .ATTR(num_proj, Int, 0)
  239. .ATTR(time_major, Bool, true)
  240. .ATTR(activation, String, "tanh")
  241. .ATTR(forget_bias, Float, 0.0)
  242. .ATTR(gate_order, String, "ijfo")
  243. .ATTR(is_training, Bool, true)
  244. .OP_END_FACTORY_REG(DynamicRNN)
  245. /**
  246. *@brief: DynamicRNNV2 calculation.
  247. *@par Inputs:
  248. *ten inputs:
  249. *@li x:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  250. *@li weight_input:A required 4D Tensor. Must be one of the following types: float16, float32.
  251. *The format must be FRACTAL_Z.
  252. *@li weight_hidden:A required 4D Tensor. Must be one of the following types: float16, float32.
  253. *The format must be FRACTAL_Z.
  254. *@li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  255. *@li seq_length:A optional 1D Tensor. Must be one of the following types: int32. The format must be ND.
  256. *@li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  257. *@li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  258. *@li wci:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  259. *@li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  260. *@li wco:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  261. *@li mask:A 1D optional Tensor. Must be one of the following types: uint8. The format must be ND . \n
  262. *@par Attributes:
  263. *@li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  264. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  265. *Only UNIDIRECTIONAL is currently supported.
  266. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  267. *@li use_peephole:An bool identifying if use peephole in the op. Default to false.
  268. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  269. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  270. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  271. *@li time_major:An bool identifying the time major in the op. Default to true.
  272. *@li activation:An string identifying the type of activation function in the op. Default to "tanh".
  273. *Only tanh is currently supported.
  274. *@li recurrent_activation:An string identifying the type of activation function in the op. Default to "sigmoid".
  275. *Supprot "sigmoid" and "hard_sigmoid". In general, set "hard_sigmoid" for TF Keras LSTM.
  276. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  277. *@li gate_order:An string identifying the type of gate order in the op. Support "ijfo" and "ifco". Default to "ijfo".
  278. *Set "ijfo" for TF operator LSTM, Set "ifco" for TF Keras LSTM.
  279. *@li stateful: An bool identifying the type of stateful in the op. Default to fasle.Only false is currently supported.
  280. *@li merge_mode: An string identifying the type of merge_modein the op. Default to "concat".
  281. *Only "concat" is currently supported
  282. *@li is_training:An bool identifying is training in the op. Default to true . \n
  283. *@par Outputs:
  284. *eight outputs:
  285. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  286. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  287. *Return the last output_h.
  288. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  289. *Return the last output_c.
  290. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  291. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  292. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  293. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  294. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  295. *@par Third-party framework compatibility:
  296. * Compatible with the TF operator LSTM or TF keras operator LSTM.
  297. */
  298. REG_OP(DynamicRNNV2)
  299. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  300. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  301. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  302. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  303. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  304. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  305. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  306. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  307. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  308. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  309. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  310. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  311. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  312. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  313. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  314. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  315. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  316. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  317. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  318. .ATTR(cell_type, String, "LSTM")
  319. .ATTR(direction, String, "UNIDIRECTIONAL")
  320. .ATTR(cell_depth, Int, 1)
  321. .ATTR(use_peephole, Bool, false)
  322. .ATTR(keep_prob, Float, 1.0)
  323. .ATTR(cell_clip, Float, -1.0)
  324. .ATTR(num_proj, Int, 0)
  325. .ATTR(time_major, Bool, true)
  326. .ATTR(activation, String, "tanh")
  327. .ATTR(recurrent_activation, String, "sigmoid")
  328. .ATTR(forget_bias, Float, 0.0)
  329. .ATTR(gate_order, String, "ijfo")
  330. .ATTR(stateful, Bool, false)
  331. .ATTR(merge_mode, String, "concat")
  332. .ATTR(is_training, Bool, true)
  333. .OP_END_FACTORY_REG(DynamicRNNV2)
  334. /**
  335. *@brief: DynamicRNNV3 calculation.
  336. *@par Inputs:
  337. *ten inputs:
  338. *@li x:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  339. *@li w:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  340. *@li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  341. *@li seq_length:A optional 1D Tensor. Must be one of the following types: int32. The format must be ND.
  342. *@li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  343. *@li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  344. *@li wci:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  345. *@li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  346. *@li wco:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  347. *@li mask:A 1D optional Tensor. Must be one of the following types: uint8. The format must be ND . \n
  348. *@li real_mask:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  349. *@li project:A 4D optional Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  350. *@par Attributes:
  351. *@li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  352. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  353. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  354. *@li use_peephole:An bool identifying if use peephole in the op. Default to false.
  355. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  356. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  357. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  358. *@li time_major:An bool identifying the time major in the op. Default to true.
  359. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  360. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  361. *@li is_training:An bool identifying is training in the op. Default to true . \n
  362. *@par Outputs:
  363. *eight outputs:
  364. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  365. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  366. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  367. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  368. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  369. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  370. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  371. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  372. *@par Third-party framework compatibility:
  373. * Compatible with the TF operator LSTM.
  374. */
  375. REG_OP(DynamicRNNV3)
  376. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  377. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  378. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  379. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  380. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  381. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  382. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  383. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  384. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  385. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  386. .OPTIONAL_INPUT(real_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  387. .OPTIONAL_INPUT(project, TensorType({DT_FLOAT16, DT_FLOAT}))
  388. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  389. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  390. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  391. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  392. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  393. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  394. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  395. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  396. .ATTR(cell_type, String, "LSTM")
  397. .ATTR(direction, String, "UNIDIRECTIONAL")
  398. .ATTR(cell_depth, Int, 1)
  399. .ATTR(use_peephole, Bool, false)
  400. .ATTR(keep_prob, Float, 1.0)
  401. .ATTR(cell_clip, Float, -1.0)
  402. .ATTR(num_proj, Int, 0)
  403. .ATTR(time_major, Bool, true)
  404. .ATTR(activation, String, "tanh")
  405. .ATTR(forget_bias, Float, 0.0)
  406. .ATTR(is_training, Bool, true)
  407. .OP_END_FACTORY_REG(DynamicRNNV3)
  408. /**
  409. *@brief: DynamicLSTMV2 calculation.
  410. *@par Inputs:
  411. *ten inputs:
  412. *@li x:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  413. *@li w:A required 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  414. *@li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  415. *@li cont:A required 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  416. *@li w_xc_x_static:A optional 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  417. *@li h0:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  418. *@li c0:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  419. *@li wci:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  420. *@li wcf:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  421. *@li wco:A optional 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  422. *@li mask:A optional 1D Tensor. Must be one of the following types: uint8. The format must be ND .
  423. *@par Attributes:
  424. *@li num_output:An integer identifying the num projection in the op. Default to 0.
  425. *@li expose_hidden:An bool identifying the expose_hidden in the op. Default to flase.
  426. *@li need_output_last:An bool identifying the time major in the op. Default to true.
  427. *@li forget_bias:An float identifying the forget bias in the op. Default to 0.
  428. *@par Outputs:
  429. *eight outputs:
  430. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  431. *@li output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  432. *@li output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  433. *@li last_output_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  434. *@li last_output_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  435. *@par Third-party framework compatibility:
  436. * Compatible with the Caffe operator LSTM.
  437. *@par Restrictions:
  438. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  439. */
  440. REG_OP(DynamicLSTMV2)
  441. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  442. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  443. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  444. .INPUT(cont, TensorType({DT_FLOAT16, DT_FLOAT}))
  445. .OPTIONAL_INPUT(w_xc_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  446. .OPTIONAL_INPUT(h0, TensorType({DT_FLOAT16, DT_FLOAT}))
  447. .OPTIONAL_INPUT(c0, TensorType({DT_FLOAT16, DT_FLOAT}))
  448. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  449. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  450. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  451. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  452. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  453. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  454. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  455. .OUTPUT(last_output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  456. .OUTPUT(last_output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  457. .ATTR(num_output, Int, 0)
  458. .ATTR(expose_hidden, Bool, false)
  459. .ATTR(need_output_last, Bool, false)
  460. .ATTR(forget_bias, Float, 0.0)
  461. .OP_END_FACTORY_REG(DynamicLSTMV2)
  462. /**
  463. *@brief: LSTMInputGrad calculation.
  464. *@par Inputs:
  465. *ten inputs: \n
  466. *@li w:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  467. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  468. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  469. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  470. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  471. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  472. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  473. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  474. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  475. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  476. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  477. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  478. *@par Outputs:
  479. *eight outputs: \n
  480. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  481. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  482. *@li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  483. */
  484. REG_OP(LSTMInputGrad)
  485. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  486. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  487. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  488. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  489. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  490. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  491. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  492. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  493. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  494. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  495. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  496. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  497. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  498. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  499. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  500. .OP_END_FACTORY_REG(LSTMInputGrad)
  501. /**
  502. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  503. *@par Inputs:
  504. *three inputs:
  505. *@li dgate:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  506. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  507. *@li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  508. *@par Attributes:
  509. *keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  510. *@par Outputs:
  511. *two outputs:
  512. *@li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  513. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  514. *@par Restrictions:
  515. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  516. */
  517. REG_OP(BasicLSTMCellInputGrad)
  518. .INPUT(dgate, TensorType({DT_FLOAT16}))
  519. .INPUT(w, TensorType({DT_FLOAT16}))
  520. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  521. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  522. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  523. .ATTR(keep_prob, Float, 1.0)
  524. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  525. /**
  526. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  527. *@par Inputs:
  528. *three inputs:
  529. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  530. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  531. *@li dgate:A 4D Tensor. Must be one of the following types: uint8. The format must be FRACTAL_NZ . \n
  532. *@par Outputs:
  533. *two outputs:
  534. *@li dw:A 4D Tensor. Must be one of the following types: float16.
  535. *@li db:A 4D Tensor. Must be one of the following types: float16, float32.
  536. *@par Restrictions:
  537. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  538. */
  539. REG_OP(BasicLSTMCellWeightGrad)
  540. .INPUT(x, TensorType({DT_FLOAT16}))
  541. .INPUT(h, TensorType({DT_FLOAT16}))
  542. .INPUT(dgate, TensorType({DT_FLOAT16}))
  543. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  544. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  545. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  546. /**
  547. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  548. *@par Inputs:
  549. *eight inputs:
  550. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  551. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  552. *@li dct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  553. *@li it:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  554. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  555. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  556. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  557. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  558. *@par Attributes:
  559. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  560. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  561. *@par Outputs:
  562. *two outputs:
  563. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  564. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  565. *@par Restrictions:
  566. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  567. */
  568. REG_OP(BasicLSTMCellCStateGrad)
  569. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  570. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  571. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  572. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  573. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  574. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  575. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  576. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  577. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  578. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  579. .ATTR(forget_bias, Float, 1.0)
  580. .ATTR(activation, String, "tanh")
  581. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  582. /**
  583. *@brief: RNN operator.
  584. *@par Inputs:
  585. *eight inputs:
  586. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  587. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  588. *@li x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  589. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  590. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  591. *@li w_sh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  592. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  593. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  594. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  595. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  596. *@par Attributes:
  597. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  598. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  599. *@par Outputs:
  600. *two outputs:
  601. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  602. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  603. *@par Restrictions:
  604. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  605. */
  606. REG_OP(RNN)
  607. .INPUT(x, TensorType({DT_FLOAT16}))
  608. .INPUT(cont, TensorType({DT_FLOAT16}))
  609. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  610. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  611. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  612. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  613. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  614. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  615. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  616. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  617. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  618. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  619. .ATTR(num_output, Int, 0)
  620. .ATTR(expose_hidden, Bool, false)
  621. .OP_END_FACTORY_REG(RNN)
  622. /**
  623. *@brief: BasicRNNCell operator.
  624. *@par Inputs:
  625. *eight inputs:
  626. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  627. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  628. *@li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  629. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  630. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  631. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  632. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  633. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  634. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  635. *@par Attributes:
  636. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  637. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  638. *@par Outputs:
  639. *two outputs:
  640. *@li o_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  641. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  642. *@par Restrictions:
  643. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  644. */
  645. REG_OP(BasicRNNCell)
  646. .INPUT(x, TensorType({DT_FLOAT16}))
  647. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  648. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  649. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  650. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  651. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  652. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  653. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  654. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  655. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  656. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  657. .ATTR(expose_hidden, Bool, false)
  658. .ATTR(num_output, Int, 0)
  659. .OP_END_FACTORY_REG(BasicRNNCell)
  660. /**
  661. *@brief DynamicGRU calculation.
  662. *@par Inputs:
  663. *seven inputs:
  664. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  665. *@li w:Must be one of the following types: float16. The format must be FRACTAL_Z.
  666. *@li b:Must be one of the following types: float16, float32. The format must be ND.
  667. *@li cw:Must be one of the following types: float16. The format must be FRACTAL_Z.
  668. *@li cb:Must be one of the following types: float16, float32. The format must be ND.
  669. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  670. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  671. *@par Attributes:
  672. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  673. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  674. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  675. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  676. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  677. *@li time_major:An bool identifying the time major in the op. Default to true.
  678. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  679. *@li is_training:An bool identifying is training in the op. Default to true.
  680. *@par Outputs:
  681. *five outputs:
  682. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  683. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  684. *@li r:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  685. *@li i:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  686. *@li n:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  687. *@par Restrictions:
  688. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  689. */
  690. REG_OP(DynamicGRU)
  691. .INPUT(x, TensorType({DT_FLOAT16}))
  692. .INPUT(w, TensorType({DT_FLOAT16}))
  693. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  694. .INPUT(cw, TensorType({DT_FLOAT16}))
  695. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  696. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  697. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  698. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  699. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  700. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  701. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  702. .OUTPUT(n, TensorType({DT_FLOAT16, DT_FLOAT}))
  703. .ATTR(direction, String, "UNIDIRECTIONAL")
  704. .ATTR(cell_depth, Int, 1)
  705. .ATTR(keep_prob, Float, 1.0)
  706. .ATTR(cell_clip, Float, -1.0)
  707. .ATTR(num_proj, Int, 0)
  708. .ATTR(time_major, Bool, true)
  709. .ATTR(activation, String, "tanh")
  710. .ATTR(is_training, Bool, true)
  711. .OP_END_FACTORY_REG(DynamicGRU)
  712. /**
  713. *@brief DynamicGRUV2 calculation.
  714. *@par Inputs:
  715. *seven inputs:
  716. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  717. *@li weight_input:Must be one of the following types: float16. The format must be FRACTAL_Z.
  718. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  719. *@li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  720. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  721. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  722. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  723. *@par Attributes:
  724. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  725. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  726. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  727. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  728. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  729. *@li time_major:An bool identifying the time major in the op. Default to true.
  730. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  731. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  732. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  733. *@li is_training:An bool identifying is training in the op. Default to true.
  734. *@par Outputs:
  735. *six outputs:
  736. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  737. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  738. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  739. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  740. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  741. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  742. */
  743. REG_OP(DynamicGRUV2)
  744. .INPUT(x, TensorType({DT_FLOAT16}))
  745. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  746. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  747. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  748. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  749. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  750. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  751. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  752. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  753. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  754. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  755. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  756. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  757. .ATTR(direction, String, "UNIDIRECTIONAL")
  758. .ATTR(cell_depth, Int, 1)
  759. .ATTR(keep_prob, Float, 1.0)
  760. .ATTR(cell_clip, Float, -1.0)
  761. .ATTR(num_proj, Int, 0)
  762. .ATTR(time_major, Bool, true)
  763. .ATTR(activation, String, "tanh")
  764. .ATTR(gate_order, String, "zrh")
  765. .ATTR(reset_after, Bool, true)
  766. .ATTR(is_training, Bool, true)
  767. .OP_END_FACTORY_REG(DynamicGRUV2)
  768. /**
  769. *@brief DynamicGRUV2Hidden calculation.
  770. *@par Inputs:
  771. *five inputs:
  772. *@li x_weight_input:Must be one of the following types: float32. The format must be FRACTAL_NZ.
  773. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  774. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  775. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  776. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  777. *@par Attributes:
  778. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  779. Only UNIDIRECTIONAL is currently supported.
  780. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  781. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  782. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  783. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  784. *@li time_major:An bool identifying the time major in the op. Default to true.
  785. *@li activation:An string identifying the type of activation function in the op. Default to "tanh".
  786. Only tanh is currently supported.
  787. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  788. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  789. *@li is_training:An bool identifying is training in the op. Default to true.
  790. *@par Outputs:
  791. *six outputs:
  792. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  793. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  794. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  795. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  796. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  797. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  798. *@par Restrictions:
  799. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  800. */
  801. REG_OP(DynamicGRUV2Hidden)
  802. .INPUT(x_weight_input, TensorType({DT_FLOAT32}))
  803. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  804. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  805. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  806. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  807. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  808. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  809. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  810. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  811. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  812. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  813. .ATTR(direction, String, "UNIDIRECTIONAL")
  814. .ATTR(cell_depth, Int, 1)
  815. .ATTR(keep_prob, Float, 1.0)
  816. .ATTR(cell_clip, Float, -1.0)
  817. .ATTR(num_proj, Int, 0)
  818. .ATTR(time_major, Bool, true)
  819. .ATTR(activation, String, "tanh")
  820. .ATTR(gate_order, String, "zrh")
  821. .ATTR(reset_after, Bool, true)
  822. .ATTR(is_training, Bool, true)
  823. .OP_END_FACTORY_REG(DynamicGRUV2Hidden)
  824. /**
  825. *@brief: DynamicGRUV2Grad calculation.
  826. *@par Inputs:
  827. *fourteen inputs: \n
  828. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  829. *@li weight_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  830. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  831. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  832. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  833. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  834. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  835. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  836. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  837. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  838. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  839. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  840. *@li seq_length:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  841. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  842. *@par Attributes:
  843. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  844. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  845. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  846. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  847. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  848. *@li time_major:An bool identifying the time major in the op. Default to true.
  849. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  850. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  851. *@par Outputs:
  852. *six outputs: \n
  853. *@li dw_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  854. *@li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  855. *@li db_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  856. *@li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  857. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  858. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  859. *@par Restrictions:
  860. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  861. */
  862. REG_OP(DynamicGRUV2Grad)
  863. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  864. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  865. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  866. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  867. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  868. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  869. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  870. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  871. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  872. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  873. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  874. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  875. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  876. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  877. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  878. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  879. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  880. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  881. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  882. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  883. .ATTR(direction, String, "UNIDIRECTIONAL")
  884. .ATTR(cell_depth, Int, 0)
  885. .ATTR(keep_prob, Float, -1.0)
  886. .ATTR(cell_clip, Float, -1.0)
  887. .ATTR(num_proj, Int, 0)
  888. .ATTR(time_major, Bool, true)
  889. .ATTR(gate_order, String, "zrh")
  890. .ATTR(reset_after, Bool, true)
  891. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  892. /**
  893. *@brief: GRUV2HiddenGrad calculation.
  894. *@par Inputs:
  895. *nine inputs: \n
  896. *@li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  897. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  898. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  899. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  900. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  901. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  902. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  903. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  904. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  905. *@par Attributes:
  906. *@li t_state:An Int identifying the current t state. Default to [0, 4].
  907. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  908. *@par Outputs:
  909. *three outputs: \n
  910. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  911. *@li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  912. *@li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  913. *@par Restrictions:
  914. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  915. */
  916. REG_OP(GRUV2HiddenGradCell)
  917. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  918. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  919. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  920. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  921. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  922. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  923. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  924. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  925. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  926. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  927. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  928. .ATTR(t_state, Int, 0)
  929. .ATTR(gate_order, String, "zrh")
  930. .OP_END_FACTORY_REG(GRUV2HiddenGradCell)
  931. /**
  932. * @brief Calculates the reversed outputs of the function "embedding". \n
  933. * @par Inputs:
  934. * Two inputs, including:
  935. * @li grad: A mutable Tensor of word grad. Must be one of the following types:
  936. * float32.
  937. * @li indices: A mutable word index Tensor of the int32 type.\n
  938. * @par Attributes:
  939. * @li num_weights: An int attr which use to judge how many words in dict. \n
  940. * @li padding_idx: An int attr judge which word to fill zeros. Defaults to "-1". \n
  941. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  942. * If "True", "grad_weight" will be scale by word_frequency.
  943. * If "False", "grad_weight" will not be scale by word_frequency. \n
  944. * @par Outputs:
  945. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  946. * @par Third-party framework compatibility
  947. * Compatible with the Pytorch operator EmbeddingDenseGrad.
  948. */
  949. REG_OP(EmbeddingDenseGrad)
  950. .INPUT(grad, TensorType({ DT_FLOAT32 })) /* "First operand." */
  951. .INPUT(indices, TensorType({ DT_INT32 })) /* "Second operand." */
  952. .OUTPUT(y, TensorType({ DT_FLOAT32 })) /* "Result, has same element type as two inputs" */
  953. .REQUIRED_ATTR(num_weights, Int)
  954. .ATTR(padding_idx, Int, -1)
  955. .ATTR(scale_grad_by_freq, Bool, false)
  956. .OP_END_FACTORY_REG(EmbeddingDenseGrad)
  957. /**
  958. *@brief CommonLSTM calculation.
  959. *@par Inputs:
  960. *eight inputs: \n
  961. *@li x:Each time step is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  962. *@li w:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  963. *@li r:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  964. *@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.
  965. *@li sequence_lens:An optional input. A 1D Tensor.Must be one of the following types: int32. The format must be ND.
  966. *@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.
  967. *@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.
  968. *@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.
  969. *@par Attributes:
  970. *@li activation_alpha:Optional scaling values used by some activation functions. Empty is currently supported.
  971. *@li activation_beta:Optional scaling values used by some activation functions. Empty is currently supported.
  972. *@li activations:The list of activation functions. Empty is currently supported.
  973. *@li clip:An float identifying the cell clip in the op. Default to -1.
  974. *@li direction:Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward(default), reverse, or bidirectional.
  975. *@li hidden_size:Number of neurons in the hidden layer. Reserved.
  976. *@li input_forget:Couple the input and forget gates if 1. Reserved.
  977. *@par Outputs:
  978. *three outputs: \n
  979. *@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.
  980. *@li y_h:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  981. *@li y_c:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  982. */
  983. REG_OP(CommonLSTM)
  984. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  985. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  986. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  987. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  988. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  989. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  990. .OPTIONAL_INPUT(initial_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  991. .OPTIONAL_INPUT(p, TensorType({DT_FLOAT16, DT_FLOAT}))
  992. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  993. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  994. .OUTPUT(y_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  995. .ATTR(activation_alpha, ListFloat, {})
  996. .ATTR(activation_beta, ListFloat, {})
  997. .ATTR(activations, ListString, {})
  998. .ATTR(clip, Float, -1.0)
  999. .ATTR(direction, String, "forward")
  1000. .REQUIRED_ATTR(hidden_size, Int)
  1001. .ATTR(input_forget, Int, 0)
  1002. .OP_END_FACTORY_REG(CommonLSTM)
  1003. /**
  1004. * @brief Calculate the mask. According to hidden_size and num_step, convert seq_length to mask.
  1005. *
  1006. * @par Inputs:
  1007. * @li seq_length: A 1D Tensor. Must be one of the following types: int32. Record the current length of each batch. [batch_size].
  1008. * @li b: A 1D Tensor. Must be one of the following types: fp16/fp32. Record the hidden_size. [4 * hidden_size].
  1009. * @li x: A 3D Tensor. Must be one of the following types: fp16/fp32. Record the num_step/batch_size/input_size. [num_step, batch_size, input_size].
  1010. *
  1011. * @par Outputs:
  1012. * seq_mask: A 3D Tensor. Must be one of the following types: fp16/fp32. with the shape of [num_step, batch_size, hidden_size]. And has the same type as "b" \n
  1013. *
  1014. * @par Restrictions:
  1015. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1016. */
  1017. REG_OP(RnnGenMaskV2)
  1018. .INPUT(seq_length, TensorType({DT_INT32}))
  1019. .INPUT(b, TensorType({{DT_FLOAT16, DT_FLOAT}))
  1020. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1021. .OUTPUT(seq_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  1022. .OP_END_FACTORY_REG(RnnGenMaskV2)
  1023. /**
  1024. * @brief Common GRU calculation.
  1025. * @par Inputs:
  1026. * Eight inputs, including:
  1027. * @li x: The input sequences packed (and pontentially padded) into on 3D Tesnor(float16). The format must be FRACTAL_NZ
  1028. * @li w: The weight tensor for the gates is 3D Tensor(float16). The format must be FRACTAL_Z
  1029. * @li r: The recurrence weight tesnor is 3D Tensor(float16). The format must be FRACTAL_Z
  1030. * @li b: The bias tensor for the gates. The format must be ND
  1031. * @li sequence_lens: Optional tensor specifying lengths of sequences(int32). The format must be ND
  1032. * @li init_h: Optional initial value of the hidden(float16,float32). The format must be FRACTAL_NZ
  1033. * @par Attributes:
  1034. * @li activation_alpha: Optional scaling values used by some activation functions. \n
  1035. * @li activation_beta: Optional scaling values used by some activation functions. \n
  1036. * @li activations: A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. \n
  1037. * @li clip: Cell clip threshold. \n
  1038. * @li direction: Specify if the RNN is forward, reverse, or bidirectional. \n
  1039. * @li hidden_size: Number of neurons in the hidden layer. \n
  1040. * @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
  1041. * @par Outputs:
  1042. * @li y: A Tensor that concats all the intermediate output values of the hidden(float16,float32). The format must be FRACTAL_NZ
  1043. * @li y_h: The last output value of the hidden(float16,float32). The format must be FRACTAL_NZ
  1044. */
  1045. REG_OP(CommonGRU)
  1046. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1047. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  1048. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  1049. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  1050. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  1051. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1052. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1053. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1054. .ATTR(activation_alpha, ListFloat, {})
  1055. .ATTR(activation_beta , ListFloat, {})
  1056. .ATTR(activations , ListString, {})
  1057. .ATTR(clip, Float, -1.0)
  1058. .ATTR(direction, String, "forward")
  1059. .REQUIRED_ATTR(hidden_size, Int)
  1060. .ATTR(linear_before_reset , Int, 0)
  1061. .OP_END_FACTORY_REG(CommonGRU)
  1062. /**
  1063. * @brief Calculates the reversed outputs of the function "embedding". \n
  1064. * @par Inputs:
  1065. * Four inputs, including:
  1066. * @li weight: A mutable Tensor of word grad. Must be one of the following types:
  1067. * float32.
  1068. * @li indices: A mutable word index Tensor of the int32 type.\n
  1069. * @li offsets: A mutable word index Tensor of the int32 type.\n
  1070. * @li per_sample_weights: to indicate all weights should be taken to be 1.
  1071. * If specified, per_sample_weights must have exactly the same shape as input
  1072. * and is treated as having the same offsets, if those are not None.
  1073. * Only supported for mode='sum'..\n
  1074. * @par Attributes:
  1075. * @li mode: An string attr which use "sum"``, ``"mean"`` or ``"max"``. Specifies the way to reduce the bag.. \n
  1076. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  1077. * If "True", "grad_weight" will be scale by word_frequency.
  1078. * If "False", "grad_weight" will not be scale by word_frequency. \n
  1079. * @li sparse: if True, gradient w.r.t.attr weight matrix will be a sparse tensor. \n
  1080. * @li include_last_offset: if True, attr offsets has one additional element, where the last element
  1081. * is equivalent to the size of indices. This matches the CSR format.. \n
  1082. * @par Outputs:
  1083. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  1084. * @par Third-party framework compatibility
  1085. * Compatible with the Pytorch operator EmbeddingBag.
  1086. */
  1087. REG_OP(EmbeddingBag)
  1088. .INPUT(weight, TensorType({ DT_FLOAT32 }))
  1089. .INPUT(indices, TensorType({ DT_INT32 }))
  1090. .OPTIONAL_INPUT(offsets, TensorType({DT_INT32}))
  1091. .OPTIONAL_INPUT(per_sample_weights, TensorType({DT_FLOAT32}))
  1092. .OUTPUT(y, TensorType({ DT_FLOAT32 }))
  1093. .ATTR(mode, String, "mean")
  1094. .ATTR(scale_grad_by_freq, Bool, false)
  1095. .ATTR(sparse, Bool, false)
  1096. .ATTR(include_last_offset, Bool, false)
  1097. .OP_END_FACTORY_REG(EmbeddingBag)
  1098. } // namespace ge
  1099. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

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