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

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