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

5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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: Dynamic LSTM Cell grad calculation.Calculate the gradient of gates and cell state.
  503. *@par Inputs:
  504. *twelve inputs:
  505. *@li init_c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  506. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  507. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  508. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  509. *@li dc:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  510. *@li i:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  511. *@li j:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  512. *@li f:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  513. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  514. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  515. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  516. *@li t_state:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  517. *@par Attributes:
  518. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  519. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  520. *@li direction:An string that marks the calculation sequence of the operator. Default to "Forward".
  521. *@li gate_order:An string mark the order of output 4 gate. Default to "ijfo".
  522. *@par Outputs:
  523. *two outputs:
  524. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  525. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  526. *@par Restrictions:
  527. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  528. */
  529. REG_OP(DynamicLSTMGradCell)
  530. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  531. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  532. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  533. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  534. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  535. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  536. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  537. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  538. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  539. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  540. .INPUT(mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  541. .INPUT(t_state, TensorType({DT_INT32, DT_INT32}))
  542. .OUTPUT(dgate, TensorType({DT_FLOAT16, DT_FLOAT}))
  543. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  544. .ATTR(forget_bias, Float, 1)
  545. .ATTR(activation, String, "")
  546. .ATTR(direction, String, "Forward")
  547. .ATTR(gate_order, String, "ijfo")
  548. .OP_END_FACTORY_REG(DynamicLSTMGradCell)
  549. /**
  550. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  551. *@par Inputs:
  552. *three inputs:
  553. *@li dgate:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  554. *@li w:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  555. *@li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  556. *@par Attributes:
  557. *keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  558. *@par Outputs:
  559. *two outputs:
  560. *@li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  561. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  562. *@par Restrictions:
  563. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  564. */
  565. REG_OP(BasicLSTMCellInputGrad)
  566. .INPUT(dgate, TensorType({DT_FLOAT16}))
  567. .INPUT(w, TensorType({DT_FLOAT16}))
  568. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  569. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  570. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  571. .ATTR(keep_prob, Float, 1.0)
  572. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  573. /**
  574. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  575. *@par Inputs:
  576. *three inputs:
  577. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  578. *@li h:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  579. *@li dgate:A 4D Tensor. Must be one of the following types: uint8. The format must be FRACTAL_NZ . \n
  580. *@par Outputs:
  581. *two outputs:
  582. *@li dw:A 4D Tensor. Must be one of the following types: float16.
  583. *@li db:A 4D Tensor. Must be one of the following types: float16, float32.
  584. *@par Restrictions:
  585. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  586. */
  587. REG_OP(BasicLSTMCellWeightGrad)
  588. .INPUT(x, TensorType({DT_FLOAT16}))
  589. .INPUT(h, TensorType({DT_FLOAT16}))
  590. .INPUT(dgate, TensorType({DT_FLOAT16}))
  591. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  592. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  593. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  594. /**
  595. *@brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  596. *@par Inputs:
  597. *eight inputs:
  598. *@li c:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  599. *@li dht:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  600. *@li dct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  601. *@li it:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  602. *@li jt:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  603. *@li ft:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  604. *@li ot:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  605. *@li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ . \n
  606. *@par Attributes:
  607. *@li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  608. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  609. *@par Outputs:
  610. *two outputs:
  611. *@li dgate:A 4D Tensor. Must be one of the following types: float16.
  612. *@li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  613. *@par Restrictions:
  614. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  615. */
  616. REG_OP(BasicLSTMCellCStateGrad)
  617. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  618. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  619. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  620. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  621. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  622. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  623. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  624. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  625. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  626. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  627. .ATTR(forget_bias, Float, 1.0)
  628. .ATTR(activation, String, "tanh")
  629. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  630. /**
  631. *@brief: RNN operator.
  632. *@par Inputs:
  633. *eight inputs:
  634. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  635. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  636. *@li x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  637. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  638. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  639. *@li w_sh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  640. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  641. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  642. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  643. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  644. *@par Attributes:
  645. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  646. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  647. *@par Outputs:
  648. *two outputs:
  649. *@li o:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  650. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  651. *@par Restrictions:
  652. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  653. */
  654. REG_OP(RNN)
  655. .INPUT(x, TensorType({DT_FLOAT16}))
  656. .INPUT(cont, TensorType({DT_FLOAT16}))
  657. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  658. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  659. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  660. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  661. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  662. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  663. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  664. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  665. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  666. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  667. .ATTR(num_output, Int, 0)
  668. .ATTR(expose_hidden, Bool, false)
  669. .OP_END_FACTORY_REG(RNN)
  670. /**
  671. *@brief: BasicRNNCell operator.
  672. *@par Inputs:
  673. *eight inputs:
  674. *@li x:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  675. *@li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  676. *@li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_NZ.
  677. *@li h_0:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  678. *@li w_xh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  679. *@li w_hh:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  680. *@li w_ho:A 4D Tensor. Must be one of the following types: float16. The format must be FRACTAL_Z.
  681. *@li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  682. *@li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  683. *@par Attributes:
  684. *@li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  685. *@li num_output:An integer identifying the number of output features. Default to 0 . \n
  686. *@par Outputs:
  687. *two outputs:
  688. *@li o_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  689. *@li h_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  690. *@par Restrictions:
  691. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  692. */
  693. REG_OP(BasicRNNCell)
  694. .INPUT(x, TensorType({DT_FLOAT16}))
  695. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  696. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  697. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  698. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  699. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  700. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  701. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  702. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  703. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  704. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  705. .ATTR(expose_hidden, Bool, false)
  706. .ATTR(num_output, Int, 0)
  707. .OP_END_FACTORY_REG(BasicRNNCell)
  708. /**
  709. *@brief DynamicGRU calculation.
  710. *@par Inputs:
  711. *seven inputs:
  712. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  713. *@li w:Must be one of the following types: float16. The format must be FRACTAL_Z.
  714. *@li b:Must be one of the following types: float16, float32. The format must be ND.
  715. *@li cw:Must be one of the following types: float16. The format must be FRACTAL_Z.
  716. *@li cb:Must be one of the following types: float16, float32. The format must be ND.
  717. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  718. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  719. *@par Attributes:
  720. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  721. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  722. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  723. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  724. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  725. *@li time_major:An bool identifying the time major in the op. Default to true.
  726. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  727. *@li is_training:An bool identifying is training in the op. Default to true.
  728. *@par Outputs:
  729. *five outputs:
  730. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  731. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  732. *@li r:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  733. *@li i:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  734. *@li n:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  735. *@par Restrictions:
  736. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  737. */
  738. REG_OP(DynamicGRU)
  739. .INPUT(x, TensorType({DT_FLOAT16}))
  740. .INPUT(w, TensorType({DT_FLOAT16}))
  741. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  742. .INPUT(cw, TensorType({DT_FLOAT16}))
  743. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  744. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  745. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  746. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  747. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  748. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  749. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  750. .OUTPUT(n, TensorType({DT_FLOAT16, DT_FLOAT}))
  751. .ATTR(direction, String, "UNIDIRECTIONAL")
  752. .ATTR(cell_depth, Int, 1)
  753. .ATTR(keep_prob, Float, 1.0)
  754. .ATTR(cell_clip, Float, -1.0)
  755. .ATTR(num_proj, Int, 0)
  756. .ATTR(time_major, Bool, true)
  757. .ATTR(activation, String, "tanh")
  758. .ATTR(is_training, Bool, true)
  759. .OP_END_FACTORY_REG(DynamicGRU)
  760. /**
  761. *@brief DynamicGRUV2 calculation.
  762. *@par Inputs:
  763. *seven inputs:
  764. *@li x:Must be one of the following types: float16. The format must be FRACTAL_NZ.
  765. *@li weight_input:Must be one of the following types: float16. The format must be FRACTAL_Z.
  766. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  767. *@li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  768. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  769. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  770. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  771. *@par Attributes:
  772. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  773. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  774. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  775. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  776. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  777. *@li time_major:An bool identifying the time major in the op. Default to true.
  778. *@li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  779. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  780. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  781. *@li is_training:An bool identifying is training in the op. Default to true.
  782. *@par Outputs:
  783. *six outputs:
  784. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  785. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  786. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  787. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  788. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  789. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  790. */
  791. REG_OP(DynamicGRUV2)
  792. .INPUT(x, TensorType({DT_FLOAT16}))
  793. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  794. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  795. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  796. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  797. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  798. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  799. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  800. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  801. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  802. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  803. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  804. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  805. .ATTR(direction, String, "UNIDIRECTIONAL")
  806. .ATTR(cell_depth, Int, 1)
  807. .ATTR(keep_prob, Float, 1.0)
  808. .ATTR(cell_clip, Float, -1.0)
  809. .ATTR(num_proj, Int, 0)
  810. .ATTR(time_major, Bool, true)
  811. .ATTR(activation, String, "tanh")
  812. .ATTR(gate_order, String, "zrh")
  813. .ATTR(reset_after, Bool, true)
  814. .ATTR(is_training, Bool, true)
  815. .OP_END_FACTORY_REG(DynamicGRUV2)
  816. /**
  817. *@brief DynamicGRUV2Hidden calculation.
  818. *@par Inputs:
  819. *five inputs:
  820. *@li x_weight_input:Must be one of the following types: float32. The format must be FRACTAL_NZ.
  821. *@li weight_hidden:Must be one of the following types: float16. The format must be FRACTAL_Z.
  822. *@li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  823. *@li seq_length:Must be one of the following types: int32. The format must be ND.
  824. *@li init_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  825. *@par Attributes:
  826. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  827. Only UNIDIRECTIONAL is currently supported.
  828. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  829. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  830. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  831. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  832. *@li time_major:An bool identifying the time major in the op. Default to true.
  833. *@li activation:An string identifying the type of activation function in the op. Default to "tanh".
  834. Only tanh is currently supported.
  835. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  836. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  837. *@li is_training:An bool identifying is training in the op. Default to true.
  838. *@par Outputs:
  839. *six outputs:
  840. *@li y:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  841. *@li output_h:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  842. *@li update:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  843. *@li reset:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  844. *@li new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  845. *@li hidden_new:Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  846. *@par Restrictions:
  847. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  848. */
  849. REG_OP(DynamicGRUV2Hidden)
  850. .INPUT(x_weight_input, TensorType({DT_FLOAT32}))
  851. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  852. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  853. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  854. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  855. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  856. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  857. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  858. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  859. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  860. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  861. .ATTR(direction, String, "UNIDIRECTIONAL")
  862. .ATTR(cell_depth, Int, 1)
  863. .ATTR(keep_prob, Float, 1.0)
  864. .ATTR(cell_clip, Float, -1.0)
  865. .ATTR(num_proj, Int, 0)
  866. .ATTR(time_major, Bool, true)
  867. .ATTR(activation, String, "tanh")
  868. .ATTR(gate_order, String, "zrh")
  869. .ATTR(reset_after, Bool, true)
  870. .ATTR(is_training, Bool, true)
  871. .OP_END_FACTORY_REG(DynamicGRUV2Hidden)
  872. /**
  873. *@brief: DynamicGRUV2Grad calculation.
  874. *@par Inputs:
  875. *fourteen inputs: \n
  876. *@li x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  877. *@li weight_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  878. *@li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  879. *@li y:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  880. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  881. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  882. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  883. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  884. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  885. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  886. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  887. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  888. *@li seq_length:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  889. *@li mask:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  890. *@par Attributes:
  891. *@li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  892. *@li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  893. *@li keep_prob:An float identifying the keep prob in the op. Default to 1.
  894. *@li cell_clip:An float identifying the cell clip in the op. Default to -1.
  895. *@li num_proj:An integer identifying the num projection in the op. Default to 0.
  896. *@li time_major:An bool identifying the time major in the op. Default to true.
  897. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  898. *@li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  899. *@par Outputs:
  900. *six outputs: \n
  901. *@li dw_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  902. *@li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  903. *@li db_input:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  904. *@li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  905. *@li dx:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  906. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  907. *@par Restrictions:
  908. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  909. */
  910. REG_OP(DynamicGRUV2Grad)
  911. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  912. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  913. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  914. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  915. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  916. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  917. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  918. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  919. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  920. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  921. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  922. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  923. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  924. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  925. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  926. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  927. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  928. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  929. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  930. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  931. .ATTR(direction, String, "UNIDIRECTIONAL")
  932. .ATTR(cell_depth, Int, 0)
  933. .ATTR(keep_prob, Float, -1.0)
  934. .ATTR(cell_clip, Float, -1.0)
  935. .ATTR(num_proj, Int, 0)
  936. .ATTR(time_major, Bool, true)
  937. .ATTR(gate_order, String, "zrh")
  938. .ATTR(reset_after, Bool, true)
  939. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  940. /**
  941. *@brief: GRUV2HiddenGrad calculation.
  942. *@par Inputs:
  943. *nine inputs: \n
  944. *@li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  945. *@li init_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  946. *@li h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  947. *@li dy:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  948. *@li dh:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  949. *@li update:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  950. *@li reset:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  951. *@li new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  952. *@li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  953. *@par Attributes:
  954. *@li t_state:An Int identifying the current t state. Default to [0, 4].
  955. *@li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  956. *@par Outputs:
  957. *three outputs: \n
  958. *@li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  959. *@li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  960. *@li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  961. *@par Restrictions:
  962. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  963. */
  964. REG_OP(GRUV2HiddenGradCell)
  965. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  966. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  967. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  968. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  969. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  970. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  971. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  972. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  973. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  974. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  975. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  976. .ATTR(t_state, Int, 0)
  977. .ATTR(gate_order, String, "zrh")
  978. .OP_END_FACTORY_REG(GRUV2HiddenGradCell)
  979. /**
  980. * @brief Calculates the reversed outputs of the function "embedding". \n
  981. * @par Inputs:
  982. * Two inputs, including:
  983. * @li grad: A mutable Tensor of word grad. Must be one of the following types:
  984. * float32.
  985. * @li indices: A mutable word index Tensor of the int32 type.\n
  986. * @par Attributes:
  987. * @li num_weights: An int attr which use to judge how many words in dict. \n
  988. * @li padding_idx: An int attr judge which word to fill zeros. Defaults to "-1". \n
  989. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  990. * If "True", "grad_weight" will be scale by word_frequency.
  991. * If "False", "grad_weight" will not be scale by word_frequency. \n
  992. * @par Outputs:
  993. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  994. * @par Third-party framework compatibility
  995. * Compatible with the Pytorch operator EmbeddingDenseGrad.
  996. */
  997. REG_OP(EmbeddingDenseGrad)
  998. .INPUT(grad, TensorType({ DT_FLOAT32 })) /* "First operand." */
  999. .INPUT(indices, TensorType({ DT_INT32 })) /* "Second operand." */
  1000. .OUTPUT(y, TensorType({ DT_FLOAT32 })) /* "Result, has same element type as two inputs" */
  1001. .REQUIRED_ATTR(num_weights, Int)
  1002. .ATTR(padding_idx, Int, -1)
  1003. .ATTR(scale_grad_by_freq, Bool, false)
  1004. .OP_END_FACTORY_REG(EmbeddingDenseGrad)
  1005. /**
  1006. *@brief CommonLSTM calculation.
  1007. *@par Inputs:
  1008. *eight inputs: \n
  1009. *@li x:Each time step is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  1010. *@li w:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  1011. *@li r:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_ZN_LSTM.
  1012. *@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.
  1013. *@li sequence_lens:An optional input. A 1D Tensor.Must be one of the following types: int32. The format must be ND.
  1014. *@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.
  1015. *@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.
  1016. *@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.
  1017. *@par Attributes:
  1018. *@li activation_alpha:Optional scaling values used by some activation functions. Empty is currently supported.
  1019. *@li activation_beta:Optional scaling values used by some activation functions. Empty is currently supported.
  1020. *@li activations:The list of activation functions. Empty is currently supported.
  1021. *@li clip:An float identifying the cell clip in the op. Default to -1.
  1022. *@li direction:Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward(default), reverse, or bidirectional.
  1023. *@li hidden_size:Number of neurons in the hidden layer. Reserved.
  1024. *@li input_forget:Couple the input and forget gates if 1. Reserved.
  1025. *@par Outputs:
  1026. *three outputs: \n
  1027. *@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.
  1028. *@li y_h:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  1029. *@li y_c:Each direction is a 4D Tensor. Must be one of the following types: float16, float32. The format must be FRACTAL_NZ.
  1030. */
  1031. REG_OP(CommonLSTM)
  1032. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1033. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  1034. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  1035. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  1036. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  1037. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1038. .OPTIONAL_INPUT(initial_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1039. .OPTIONAL_INPUT(p, TensorType({DT_FLOAT16, DT_FLOAT}))
  1040. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1041. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1042. .OUTPUT(y_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1043. .ATTR(activation_alpha, ListFloat, {})
  1044. .ATTR(activation_beta, ListFloat, {})
  1045. .ATTR(activations, ListString, {})
  1046. .ATTR(clip, Float, -1.0)
  1047. .ATTR(direction, String, "forward")
  1048. .REQUIRED_ATTR(hidden_size, Int)
  1049. .ATTR(input_forget, Int, 0)
  1050. .OP_END_FACTORY_REG(CommonLSTM)
  1051. /**
  1052. * @brief Calculate the mask. According to hidden_size and num_step, convert seq_length to mask.
  1053. *
  1054. * @par Inputs:
  1055. * @li seq_length: A 1D Tensor. Must be one of the following types: int32. Record the current length of each batch. [batch_size].
  1056. * @li b: A 1D Tensor. Must be one of the following types: fp16/fp32. Record the hidden_size. [4 * hidden_size].
  1057. * @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].
  1058. *
  1059. * @par Outputs:
  1060. * 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
  1061. *
  1062. * @par Restrictions:
  1063. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1064. */
  1065. REG_OP(RnnGenMaskV2)
  1066. .INPUT(seq_length, TensorType({DT_INT32}))
  1067. .INPUT(b, TensorType({{DT_FLOAT16, DT_FLOAT}))
  1068. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1069. .OUTPUT(seq_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  1070. .OP_END_FACTORY_REG(RnnGenMaskV2)
  1071. /**
  1072. * @brief Common GRU calculation.
  1073. * @par Inputs:
  1074. * Eight inputs, including:
  1075. * @li x: The input sequences packed (and pontentially padded) into on 3D Tesnor(float16). The format must be FRACTAL_NZ
  1076. * @li w: The weight tensor for the gates is 3D Tensor(float16). The format must be FRACTAL_Z
  1077. * @li r: The recurrence weight tesnor is 3D Tensor(float16). The format must be FRACTAL_Z
  1078. * @li b: The bias tensor for the gates. The format must be ND
  1079. * @li sequence_lens: Optional tensor specifying lengths of sequences(int32). The format must be ND
  1080. * @li init_h: Optional initial value of the hidden(float16,float32). The format must be FRACTAL_NZ
  1081. * @par Attributes:
  1082. * @li activation_alpha: Optional scaling values used by some activation functions. \n
  1083. * @li activation_beta: Optional scaling values used by some activation functions. \n
  1084. * @li activations: A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. \n
  1085. * @li clip: Cell clip threshold. \n
  1086. * @li direction: Specify if the RNN is forward, reverse, or bidirectional. \n
  1087. * @li hidden_size: Number of neurons in the hidden layer. \n
  1088. * @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
  1089. * @par Outputs:
  1090. * @li y: A Tensor that concats all the intermediate output values of the hidden(float16,float32). The format must be FRACTAL_NZ
  1091. * @li y_h: The last output value of the hidden(float16,float32). The format must be FRACTAL_NZ
  1092. */
  1093. REG_OP(CommonGRU)
  1094. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1095. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  1096. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  1097. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  1098. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  1099. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1100. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1101. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1102. .ATTR(activation_alpha, ListFloat, {})
  1103. .ATTR(activation_beta , ListFloat, {})
  1104. .ATTR(activations , ListString, {})
  1105. .ATTR(clip, Float, -1.0)
  1106. .ATTR(direction, String, "forward")
  1107. .REQUIRED_ATTR(hidden_size, Int)
  1108. .ATTR(linear_before_reset , Int, 0)
  1109. .OP_END_FACTORY_REG(CommonGRU)
  1110. /**
  1111. * @brief Calculates the reversed outputs of the function "embedding". \n
  1112. * @par Inputs:
  1113. * Four inputs, including:
  1114. * @li weight: A mutable Tensor of word grad. Must be one of the following types:
  1115. * float32.
  1116. * @li indices: A mutable word index Tensor of the int32 type.\n
  1117. * @li offsets: A mutable word index Tensor of the int32 type.\n
  1118. * @li per_sample_weights: to indicate all weights should be taken to be 1.
  1119. * If specified, per_sample_weights must have exactly the same shape as input
  1120. * and is treated as having the same offsets, if those are not None.
  1121. * Only supported for mode='sum'..\n
  1122. * @par Attributes:
  1123. * @li mode: An string attr which use "sum"``, ``"mean"`` or ``"max"``. Specifies the way to reduce the bag.. \n
  1124. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  1125. * If "True", "grad_weight" will be scale by word_frequency.
  1126. * If "False", "grad_weight" will not be scale by word_frequency. \n
  1127. * @li sparse: if True, gradient w.r.t.attr weight matrix will be a sparse tensor. \n
  1128. * @li include_last_offset: if True, attr offsets has one additional element, where the last element
  1129. * is equivalent to the size of indices. This matches the CSR format.. \n
  1130. * @par Outputs:
  1131. * @li grad_weight: A mutable output Tensor of new word grad has the same type as "grads". \n
  1132. * @par Third-party framework compatibility
  1133. * Compatible with the Pytorch operator EmbeddingBag.
  1134. */
  1135. REG_OP(EmbeddingBag)
  1136. .INPUT(weight, TensorType({ DT_FLOAT32 }))
  1137. .INPUT(indices, TensorType({ DT_INT32 }))
  1138. .OPTIONAL_INPUT(offsets, TensorType({DT_INT32}))
  1139. .OPTIONAL_INPUT(per_sample_weights, TensorType({DT_FLOAT32}))
  1140. .OUTPUT(y, TensorType({ DT_FLOAT32 }))
  1141. .ATTR(mode, String, "mean")
  1142. .ATTR(scale_grad_by_freq, Bool, false)
  1143. .ATTR(sparse, Bool, false)
  1144. .ATTR(include_last_offset, Bool, false)
  1145. .OP_END_FACTORY_REG(EmbeddingBag)
  1146. } // namespace ge
  1147. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

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