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

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
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
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628
  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. * @li gate_order:An string identifying the type of gate order in the op. Support "ijfo" and "ifjo". Default to "ijfo".
  121. * @par Outputs:
  122. * eight outputs: \n
  123. * @li dw:A 4D Tensor. Must be one of the following types: float16, float32.
  124. * @li db:A 4D Tensor. Must be one of the following types: float16, float32.
  125. * @li dx:A 4D Tensor. Must be one of the following types: float16, float32.
  126. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  127. * @li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  128. * @li dwci:A 4D Tensor. Must be one of the following types: float16, float32.
  129. * @li dwcf:A 4D Tensor. Must be one of the following types: float16, float32.
  130. * @li dwco:A 4D Tensor. Must be one of the following types: float16, float32.
  131. */
  132. REG_OP(DynamicRNNGrad)
  133. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  134. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  135. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  136. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  137. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  138. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  139. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  140. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  141. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  142. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  143. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  144. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  145. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  146. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  147. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  148. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  149. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  150. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  151. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  152. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  153. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  154. .OUTPUT(dw, TensorType({DT_FLOAT16, DT_FLOAT}))
  155. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT}))
  156. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  157. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  158. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  159. .DYNAMIC_OUTPUT(dwci, TensorType({DT_FLOAT16, DT_FLOAT}))
  160. .DYNAMIC_OUTPUT(dwcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  161. .DYNAMIC_OUTPUT(dwco, TensorType({DT_FLOAT16, DT_FLOAT}))
  162. .ATTR(cell_type, String, "LSTM")
  163. .ATTR(direction, String, "UNIDIRECTIONAL")
  164. .ATTR(cell_depth, Int, 0)
  165. .ATTR(use_peephole, Bool, false)
  166. .ATTR(keep_prob, Float, -1.0)
  167. .ATTR(cell_clip, Float, -1.0)
  168. .ATTR(num_proj, Int, 0)
  169. .ATTR(time_major, Bool, true)
  170. .ATTR(forget_bias, Float, 0.0)
  171. .ATTR(gate_order, String, "ijfo")
  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.
  178. * @li w:A required 4D Tensor. Must be one of the following types: float16, float32.
  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 int32 in ND.
  181. * @li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32.
  182. * @li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32.
  183. * @li wci:A 4D optional Tensor. Must be one of the following types: float16, float32.
  184. * @li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32.
  185. * @li wco:A 4D optional Tensor. Must be one of the following types: float16, float32.
  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.
  203. * @li output_h:A 4D Tensor. Must be one of the following types: float16, float32.
  204. * @li output_c:A 4D Tensor. Must be one of the following types: float16, float32.
  205. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  206. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  207. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  208. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  209. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  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.
  250. * @li weight_input:A required 4D Tensor. Must be one of the following types: float16, float32.
  251. * @li weight_hidden:A required 4D Tensor. Must be one of the following types: float16, float32.
  252. * @li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  253. * @li seq_length:A optional 1D Tensor. Must be one of the following types: float16, int32.
  254. * @li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32.
  255. * @li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32.
  256. * @li wci:A 4D optional Tensor. Must be one of the following types: float16, float32.
  257. * @li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32.
  258. * @li wco:A 4D optional Tensor. Must be one of the following types: float16, float32.
  259. * @li mask:A 1D optional Tensor. Must be one of the following types: uint8. The format must be ND . \n
  260. * @par Attributes:
  261. * @li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  262. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  263. * Only UNIDIRECTIONAL is currently supported.
  264. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  265. * @li use_peephole:An bool identifying if use peephole in the op. Default to false.
  266. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  267. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  268. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  269. * @li time_major:An bool identifying the time major in the op. Default to true.
  270. * @li activation:An string identifying the type of activation function in the op. Default to "tanh".
  271. * Support "tanh" and "clip".
  272. * @li recurrent_activation:An string identifying the type of activation function in the op. Default to "sigmoid".
  273. * Support "sigmoid" and "hard_sigmoid". In general, set "hard_sigmoid" for TF Keras LSTM.
  274. * @li forget_bias:An float identifying the forget bias in the op. Default to 0.
  275. * @li gate_order:An string identifying the type of gate order in the op. Support "ijfo" and "ifco". Default to "ijfo".
  276. * Set "ijfo" for TF operator LSTM, Set "ifco" for TF Keras LSTM.
  277. * @li stateful: An bool identifying the type of stateful in the op. Default to fasle.Only false is currently supported.
  278. * @li merge_mode: An string identifying the type of merge_modein the op. Default to "concat".
  279. * Only "concat" is currently supported
  280. * @li is_training:An bool identifying is training in the op. Default to true . \n
  281. * @par Outputs:
  282. * eight outputs:
  283. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  284. * @li output_h:A 4D Tensor. Must be one of the following types: float16, float32.
  285. * Return the last output_h.
  286. * @li output_c:A 4D Tensor. Must be one of the following types: float16, float32.
  287. * Return the last output_c.
  288. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  289. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  290. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  291. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  292. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  293. * @par Third-party framework compatibility:
  294. * Compatible with the TF operator LSTM or TF keras operator LSTM.
  295. */
  296. REG_OP(DynamicRNNV2)
  297. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  298. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  299. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  300. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  301. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32, DT_FLOAT16}))
  302. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  303. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  304. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  305. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  306. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  307. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  308. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  309. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  310. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  311. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  312. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  313. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  314. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  315. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  316. .ATTR(cell_type, String, "LSTM")
  317. .ATTR(direction, String, "UNIDIRECTIONAL")
  318. .ATTR(cell_depth, Int, 1)
  319. .ATTR(use_peephole, Bool, false)
  320. .ATTR(keep_prob, Float, 1.0)
  321. .ATTR(cell_clip, Float, -1.0)
  322. .ATTR(num_proj, Int, 0)
  323. .ATTR(time_major, Bool, true)
  324. .ATTR(activation, String, "tanh")
  325. .ATTR(recurrent_activation, String, "sigmoid")
  326. .ATTR(forget_bias, Float, 0.0)
  327. .ATTR(gate_order, String, "ijfo")
  328. .ATTR(stateful, Bool, false)
  329. .ATTR(merge_mode, String, "concat")
  330. .ATTR(is_training, Bool, true)
  331. .OP_END_FACTORY_REG(DynamicRNNV2)
  332. /**
  333. * @brief: DynamicRNNV2Grad calculation.
  334. * @par Inputs:
  335. * twenty-one inputs:
  336. * @li x:A required 4D Tensor. Must be one of the following types: float16, float32.
  337. * @li w_x:A required 4D Tensor. Must be one of the following types: float16, float32.
  338. * @li w_h:A required 4D Tensor. Must be one of the following types: float16, float32.
  339. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  340. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  341. * @li init_c:A 4D Tensor. Must be one of the following types: float16, float32.
  342. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  343. * @li c:A 4D Tensor. Must be one of the following types: float16, float32.
  344. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  345. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  346. * @li dc:A 4D Tensor. Must be one of the following types: float16, float32.
  347. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  348. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  349. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  350. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  351. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  352. * @li seq_length:A 1D Tensor. Must be one of the following types: int32.
  353. * @li wci:A 4D Tensor. Must be one of the following types: float16, float32.
  354. * @li wcf:A 4D Tensor. Must be one of the following types: float16, float32.
  355. * @li wco:A 4D Tensor. Must be one of the following types: float16, float32.
  356. * @li mask:A 1D Tensor. Must be one of the following types: int8. \n
  357. * @par Attributes:
  358. * @li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  359. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL".
  360. * Only UNIDIRECTIONAL is currently supported.
  361. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1. Only 1 is currently supported.
  362. * @li use_peephole:An bool identifying if use peephole in the op. Default to false.
  363. * Only false is currently supported.
  364. * @li keep_prob:An float identifying the keep prob in the op. Default to 1. Only 1 is currently supported.
  365. * @li cell_clip:An float identifying the cell clip in the op. Default to -1. Only -1 is currently supported.
  366. * @li num_proj:An integer identifying the num projection in the op. Default to 0. Only 0 is currently supported.
  367. * @li time_major:An bool identifying the time major in the op. Default to true. Only true is currently supported.
  368. * @li activation:An string identifying the type of activation function in the op. Default to "tanh".
  369. * Only "tanh" is currently supported.
  370. * @li recurrent_activation:An string identifying the type of activation function in the op. Default to "sigmoid".
  371. * Only "sigmoid" is currently supported.
  372. * @li gate_order:An string identifying the type of gate order in the op. Support "ijfo" and "ifco". Default to "ijfo".
  373. * Set "ijfo" for TF operator LSTM, Set "ifco" for TF Keras/Pytorch LSTM .
  374. * @li stateful: An bool identifying the type of stateful in the op. Default to fasle.Only false is currently supported.
  375. * @li merge_mode: An string identifying the type of merge_modein the op. Default to "concat".
  376. * Only "concat" is currently supported. \n
  377. * @par Outputs:
  378. * nine outputs:
  379. * @li dw_x:A 4D Tensor. Must be one of the following types: float16, float32.
  380. * @li dw_h:A 4D Tensor. Must be one of the following types: float16, float32.
  381. * @li db:A 4D Tensor. Must be one of the following types: float16, float32.
  382. * @li dx:A 4D Tensor. Must be one of the following types: float16, float32.
  383. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  384. * @li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  385. * @li dwci:A 4D Tensor. Must be one of the following types: float16, float32.
  386. * @li dwcf:A 4D Tensor. Must be one of the following types: float16, float32.
  387. * @li dwco:A 4D Tensor. Must be one of the following types: float16, float32.
  388. * @par Third-party framework compatibility:
  389. * Compatible with the TF operator LSTM or TF keras operator LSTM.
  390. * @par Restrictions:
  391. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  392. */
  393. REG_OP(DynamicRNNV2Grad)
  394. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  395. .INPUT(w_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  396. .INPUT(w_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  397. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  398. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  399. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  400. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  401. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  402. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  403. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  404. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  405. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  406. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  407. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  408. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  409. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  410. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  411. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  412. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  413. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  414. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  415. .OUTPUT(dw_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  416. .OUTPUT(dw_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  417. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT}))
  418. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  419. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  420. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  421. .DYNAMIC_OUTPUT(dwci, TensorType({DT_FLOAT16, DT_FLOAT}))
  422. .DYNAMIC_OUTPUT(dwcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  423. .DYNAMIC_OUTPUT(dwco, TensorType({DT_FLOAT16, DT_FLOAT}))
  424. .ATTR(cell_type, String, "LSTM")
  425. .ATTR(direction, String, "UNIDIRECTIONAL")
  426. .ATTR(cell_depth, Int, 1)
  427. .ATTR(use_peephole, Bool, false)
  428. .ATTR(keep_prob, Float, 1.0)
  429. .ATTR(cell_clip, Float, -1.0)
  430. .ATTR(num_proj, Int, 0)
  431. .ATTR(time_major, Bool, true)
  432. .ATTR(activation, String, "tanh")
  433. .ATTR(recurrent_activation, String, "sigmoid")
  434. .ATTR(gate_order, String, "ijfo")
  435. .ATTR(stateful, Bool, false)
  436. .ATTR(merge_mode, String, "concat")
  437. .OP_END_FACTORY_REG(DynamicRNNV2Grad)
  438. /**
  439. * @brief: DynamicRNNV3 calculation.
  440. * @par Inputs:
  441. * ten inputs:
  442. * @li x:A required 4D Tensor. Must be one of the following types: float16, float32.
  443. * @li w:A required 4D Tensor. Must be one of the following types: float16, float32.
  444. * @li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  445. * @li seq_length:A optional 1D Tensor. Must be one of the following types: int32. The format must be ND.
  446. * @li init_h:A optional 4D Tensor. Must be one of the following types: float16, float32.
  447. * @li init_c:A optional 4D Tensor. Must be one of the following types: float16, float32.
  448. * @li wci:A 4D optional Tensor. Must be one of the following types: float16, float32.
  449. * @li wcf:A 4D optional Tensor. Must be one of the following types: float16, float32.
  450. * @li wco:A 4D optional Tensor. Must be one of the following types: float16, float32.
  451. * @li mask:A 1D optional Tensor. Must be one of the following types: uint8. The format must be ND . \n
  452. * @li real_mask:A 4D optional Tensor. Must be one of the following types: float16, float32.
  453. * @li project:A 4D optional Tensor. Must be one of the following types: float16, float32.
  454. * @par Attributes:
  455. * @li cell_type:An string identifying the cell type in the op. Default to "LSTM". Only LSTM is currently supported.
  456. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  457. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  458. * @li use_peephole:An bool identifying if use peephole in the op. Default to false.
  459. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  460. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  461. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  462. * @li time_major:An bool identifying the time major in the op. Default to true.
  463. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  464. * @li forget_bias:An float identifying the forget bias in the op. Default to 0.
  465. * @li is_training:An bool identifying is training in the op. Default to true . \n
  466. * @par Outputs:
  467. * eight outputs:
  468. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  469. * @li output_h:A 4D Tensor. Must be one of the following types: float16, float32.
  470. * @li output_c:A 4D Tensor. Must be one of the following types: float16, float32.
  471. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  472. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  473. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  474. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  475. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  476. * @par Third-party framework compatibility:
  477. * Compatible with the TF operator LSTM.
  478. */
  479. REG_OP(DynamicRNNV3)
  480. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  481. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  482. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  483. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  484. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  485. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  486. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  487. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  488. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  489. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  490. .OPTIONAL_INPUT(real_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  491. .OPTIONAL_INPUT(project, TensorType({DT_FLOAT16, DT_FLOAT}))
  492. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  493. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  494. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  495. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  496. .OUTPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  497. .OUTPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  498. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  499. .OUTPUT(tanhc, TensorType({DT_FLOAT16, DT_FLOAT}))
  500. .ATTR(cell_type, String, "LSTM")
  501. .ATTR(direction, String, "UNIDIRECTIONAL")
  502. .ATTR(cell_depth, Int, 1)
  503. .ATTR(use_peephole, Bool, false)
  504. .ATTR(keep_prob, Float, 1.0)
  505. .ATTR(cell_clip, Float, -1.0)
  506. .ATTR(num_proj, Int, 0)
  507. .ATTR(time_major, Bool, true)
  508. .ATTR(activation, String, "tanh")
  509. .ATTR(forget_bias, Float, 0.0)
  510. .ATTR(is_training, Bool, true)
  511. .OP_END_FACTORY_REG(DynamicRNNV3)
  512. /**
  513. * @brief: DynamicLSTMV2 calculation.
  514. * @par Inputs:
  515. * ten inputs:
  516. * @li x:A required 4D Tensor. Must be one of the following types: float16, float32.
  517. * @li w:A required 4D Tensor. Must be one of the following types: float16, float32.
  518. * @li b:A required 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  519. * @li cont:A required 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  520. * @li w_xc_x_static:A optional 2D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  521. * @li h0:A optional 4D Tensor. Must be one of the following types: float16, float32.
  522. * @li c0:A optional 4D Tensor. Must be one of the following types: float16, float32.
  523. * @li wci:A optional 4D Tensor. Must be one of the following types: float16, float32.
  524. * @li wcf:A optional 4D Tensor. Must be one of the following types: float16, float32.
  525. * @li wco:A optional 4D Tensor. Must be one of the following types: float16, float32.
  526. * @li mask:A optional 1D Tensor. Must be one of the following types: uint8. The format must be ND .
  527. * @par Attributes:
  528. * @li num_output:An integer identifying the num projection in the op. Default to 0.
  529. * @li expose_hidden:An bool identifying the expose_hidden in the op. Default to flase.
  530. * @li need_output_last:An bool identifying the time major in the op. Default to true.
  531. * @li forget_bias:An float identifying the forget bias in the op. Default to 0.
  532. * @par Outputs:
  533. * eight outputs:
  534. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  535. * @li output_h:A 4D Tensor. Must be one of the following types: float16, float32.
  536. * @li output_c:A 4D Tensor. Must be one of the following types: float16, float32.
  537. * @li last_output_h:A 4D Tensor. Must be one of the following types: float16, float32.
  538. * @li last_output_c:A 4D Tensor. Must be one of the following types: float16, float32.
  539. * @par Third-party framework compatibility:
  540. * Compatible with the Caffe operator LSTM.
  541. * @par Restrictions:
  542. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  543. */
  544. REG_OP(DynamicLSTMV2)
  545. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  546. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  547. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  548. .INPUT(cont, TensorType({DT_FLOAT16, DT_FLOAT}))
  549. .OPTIONAL_INPUT(w_xc_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  550. .OPTIONAL_INPUT(h0, TensorType({DT_FLOAT16, DT_FLOAT}))
  551. .OPTIONAL_INPUT(c0, TensorType({DT_FLOAT16, DT_FLOAT}))
  552. .OPTIONAL_INPUT(wci, TensorType({DT_FLOAT16, DT_FLOAT}))
  553. .OPTIONAL_INPUT(wcf, TensorType({DT_FLOAT16, DT_FLOAT}))
  554. .OPTIONAL_INPUT(wco, TensorType({DT_FLOAT16, DT_FLOAT}))
  555. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  556. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  557. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  558. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  559. .OUTPUT(last_output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  560. .OUTPUT(last_output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  561. .ATTR(num_output, Int, 0)
  562. .ATTR(expose_hidden, Bool, false)
  563. .ATTR(need_output_last, Bool, false)
  564. .ATTR(forget_bias, Float, 0.0)
  565. .OP_END_FACTORY_REG(DynamicLSTMV2)
  566. /**
  567. * @brief: LSTMInputGrad calculation.
  568. * @par Inputs:
  569. * ten inputs: \n
  570. * @li w:A 4D Tensor. Must be one of the following types: float16, float32.
  571. * @li init_c:A 4D Tensor. Must be one of the following types: float16, float32.
  572. * @li c:A 4D Tensor. Must be one of the following types: float16, float32.
  573. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  574. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  575. * @li dc:A 4D Tensor. Must be one of the following types: float16, float32.
  576. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  577. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  578. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  579. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  580. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  581. * @par Outputs:
  582. * four outputs: \n
  583. * @li dx:A 4D Tensor. Must be one of the following types: float16, float32.
  584. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  585. * @li dc_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  586. * @li dgate:A 4D Tensor. Must be one of the following types: float16.
  587. */
  588. REG_OP(LSTMInputGrad)
  589. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  590. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  591. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  592. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  593. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  594. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  595. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  596. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  597. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  598. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  599. .OPTIONAL_INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  600. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  601. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  602. .OUTPUT(dc_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  603. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  604. .OP_END_FACTORY_REG(LSTMInputGrad)
  605. /**
  606. * @brief: Dynamic LSTM Cell grad calculation.Calculate the gradient of gates and cell state.
  607. * @par Inputs:
  608. * twelve inputs:
  609. * @li init_c:A 4D Tensor. Must be one of the following types: float16, float32.
  610. * @li c:A 4D Tensor. Must be one of the following types: float16, float32.
  611. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  612. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  613. * @li dc:A 4D Tensor. Must be one of the following types: float16, float32.
  614. * @li i:A 4D Tensor. Must be one of the following types: float16, float32.
  615. * @li j:A 4D Tensor. Must be one of the following types: float16, float32.
  616. * @li f:A 4D Tensor. Must be one of the following types: float16, float32.
  617. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  618. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32.
  619. * @li mask:A 4D Tensor. Must be one of the following types: float16, float32.
  620. * @li t_state:A 4D Tensor. Must be one of the following types: float16, float32. . \n
  621. * @par Attributes:
  622. * @li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  623. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  624. * @li direction:An string that marks the calculation sequence of the operator. Default to "Forward".
  625. * @li gate_order:An string mark the order of output 4 gate. Default to "ijfo".
  626. * @par Outputs:
  627. * two outputs:
  628. * @li dgate:A 4D Tensor. Must be one of the following types: float16.
  629. * @li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  630. * @par Restrictions:
  631. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  632. */
  633. REG_OP(DynamicLSTMGradCell)
  634. .INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  635. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  636. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  637. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  638. .INPUT(dc, TensorType({DT_FLOAT16, DT_FLOAT}))
  639. .INPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  640. .INPUT(j, TensorType({DT_FLOAT16, DT_FLOAT}))
  641. .INPUT(f, TensorType({DT_FLOAT16, DT_FLOAT}))
  642. .INPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  643. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  644. .INPUT(t_state, TensorType({DT_INT32, DT_INT32}))
  645. .INPUT(mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  646. .OUTPUT(dgate, TensorType({DT_FLOAT16, DT_FLOAT}))
  647. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  648. .ATTR(forget_bias, Float, 1.0)
  649. .ATTR(activation, String, "tanh")
  650. .ATTR(direction, String, "UNIDIRECTIONAL")
  651. .ATTR(gate_order, String, "ijfo")
  652. .OP_END_FACTORY_REG(DynamicLSTMGradCell)
  653. /**
  654. * @brief: Basic LSTM Cell backward calculation.Calculate the gradient of input and hidden state.
  655. * @par Inputs:
  656. * three inputs:
  657. * @li dgate:A 4D Tensor. Must be one of the following types: float16.
  658. * @li w:A 4D Tensor. Must be one of the following types: float16.
  659. * @li dropout_mask:A 1D Tensor. Must be one of the following types: uint8. The format must be ND . \n
  660. * @par Attributes:
  661. * keep_prob:An integer identifying the keep prob in the op. Default to 1 . \n
  662. * @par Outputs:
  663. * two outputs:
  664. * @li dxt:A 4D Tensor. Must be one of the following types: float16, float32.
  665. * @li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  666. * @par Restrictions:
  667. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  668. */
  669. REG_OP(BasicLSTMCellInputGrad)
  670. .INPUT(dgate, TensorType({DT_FLOAT16}))
  671. .INPUT(w, TensorType({DT_FLOAT16}))
  672. .OPTIONAL_INPUT(dropout_mask, TensorType({DT_UINT8}))
  673. .OUTPUT(dxt, TensorType({DT_FLOAT16, DT_FLOAT32}))
  674. .OUTPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT32}))
  675. .ATTR(keep_prob, Float, 1.0)
  676. .OP_END_FACTORY_REG(BasicLSTMCellInputGrad)
  677. /**
  678. * @brief: Basic LSTM Cell backward calculation.Calculate the gradient of weight and bias.
  679. * @par Inputs:
  680. * three inputs:
  681. * @li x:A 4D Tensor. Must be one of the following types: float16.
  682. * @li h:A 4D Tensor. Must be one of the following types: float16.
  683. * @li dgate:A 4D Tensor. Must be one of the following types: uint8. \n
  684. * @par Outputs:
  685. * two outputs:
  686. * @li dw:A 4D Tensor. Must be one of the following types: float16.
  687. * @li db:A 4D Tensor. Must be one of the following types: float16, float32.
  688. * @par Restrictions:
  689. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  690. */
  691. REG_OP(BasicLSTMCellWeightGrad)
  692. .INPUT(x, TensorType({DT_FLOAT16}))
  693. .INPUT(h, TensorType({DT_FLOAT16}))
  694. .INPUT(dgate, TensorType({DT_FLOAT16}))
  695. .OUTPUT(dw, TensorType({DT_FLOAT16}))
  696. .OUTPUT(db, TensorType({DT_FLOAT16, DT_FLOAT32}))
  697. .OP_END_FACTORY_REG(BasicLSTMCellWeightGrad)
  698. /**
  699. * @brief: Basic LSTM Cell backward calculation.Calculate the gradient of gates and cell state.
  700. * @par Inputs:
  701. * eight inputs:
  702. * @li c:A 4D Tensor. Must be one of the following types: float16, float32.
  703. * @li dht:A 4D Tensor. Must be one of the following types: float16, float32.
  704. * @li dct:A 4D Tensor. Must be one of the following types: float16, float32.
  705. * @li it:A 4D Tensor. Must be one of the following types: float16, float32.
  706. * @li jt:A 4D Tensor. Must be one of the following types: float16, float32.
  707. * @li ft:A 4D Tensor. Must be one of the following types: float16, float32.
  708. * @li ot:A 4D Tensor. Must be one of the following types: float16, float32.
  709. * @li tanhct:A 4D Tensor. Must be one of the following types: float16, float32. \n
  710. * @par Attributes:
  711. * @li forget_bias:An integer identifying the forget bias in the op. Default to 1.
  712. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported . \n
  713. * @par Outputs:
  714. * two outputs:
  715. * @li dgate:A 4D Tensor. Must be one of the following types: float16.
  716. * @li dct_1:A 4D Tensor. Must be one of the following types: float16, float32.
  717. * @par Restrictions:
  718. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  719. */
  720. REG_OP(BasicLSTMCellCStateGrad)
  721. .INPUT(c, TensorType({DT_FLOAT16, DT_FLOAT}))
  722. .INPUT(dht, TensorType({DT_FLOAT16, DT_FLOAT}))
  723. .INPUT(dct, TensorType({DT_FLOAT16, DT_FLOAT}))
  724. .INPUT(it, TensorType({DT_FLOAT16, DT_FLOAT}))
  725. .INPUT(jt, TensorType({DT_FLOAT16, DT_FLOAT}))
  726. .INPUT(ft, TensorType({DT_FLOAT16, DT_FLOAT}))
  727. .INPUT(ot, TensorType({DT_FLOAT16, DT_FLOAT}))
  728. .INPUT(tanhct, TensorType({DT_FLOAT16, DT_FLOAT}))
  729. .OUTPUT(dgate, TensorType({DT_FLOAT16}))
  730. .OUTPUT(dct_1, TensorType({DT_FLOAT16, DT_FLOAT}))
  731. .ATTR(forget_bias, Float, 1.0)
  732. .ATTR(activation, String, "tanh")
  733. .OP_END_FACTORY_REG(BasicLSTMCellCStateGrad)
  734. /**
  735. * @brief: RNN operator.
  736. * @par Inputs:
  737. * eight inputs:
  738. * @li x:A 4D Tensor. Must be one of the following types: float16.
  739. * @li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  740. * @li x_static:A 4D Tensor. Must be one of the following types: float16.
  741. * @li h_0:A 4D Tensor. Must be one of the following types: float16, float32.
  742. * @li w_xh:A 4D Tensor. Must be one of the following types: float16.
  743. * @li w_sh:A 4D Tensor. Must be one of the following types: float16.
  744. * @li w_hh:A 4D Tensor. Must be one of the following types: float16.
  745. * @li w_ho:A 4D Tensor. Must be one of the following types: float16.
  746. * @li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  747. * @li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  748. * @par Attributes:
  749. * @li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  750. * @li num_output:An integer identifying the number of output features. Default to 0 . \n
  751. * @par Outputs:
  752. * two outputs:
  753. * @li o:A 4D Tensor. Must be one of the following types: float16, float32.
  754. * @li h_t:A 4D Tensor. Must be one of the following types: float16, float32.
  755. * @par Restrictions:
  756. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  757. */
  758. REG_OP(RNN)
  759. .INPUT(x, TensorType({DT_FLOAT16}))
  760. .INPUT(cont, TensorType({DT_FLOAT16}))
  761. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  762. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  763. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  764. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  765. .OPTIONAL_INPUT(w_sh, TensorType({DT_FLOAT16}))
  766. .INPUT(w_hh, TensorType({DT_FLOAT16}))
  767. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  768. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  769. .OUTPUT(o, TensorType({DT_FLOAT16, DT_FLOAT}))
  770. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  771. .ATTR(num_output, Int, 0)
  772. .ATTR(expose_hidden, Bool, false)
  773. .OP_END_FACTORY_REG(RNN)
  774. /**
  775. * @brief: BasicRNNCell operator.
  776. * @par Inputs:
  777. * eight inputs:
  778. * @li x:A 4D Tensor. Must be one of the following types: float16.
  779. * @li cont:A 1D Tensor. Must be one of the following types: float16. The format must be ND.
  780. * @li w_xh_x_static:A 4D Tensor. Must be one of the following types: float16.
  781. * @li h_0:A 4D Tensor. Must be one of the following types: float16, float32.
  782. * @li w_xh:A 4D Tensor. Must be one of the following types: float16.
  783. * @li w_hh:A 4D Tensor. Must be one of the following types: float16.
  784. * @li w_ho:A 4D Tensor. Must be one of the following types: float16.
  785. * @li bias_h:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND.
  786. * @li bias_o:A 1D Tensor. Must be one of the following types: float16, float32. The format must be ND . \n
  787. * @par Attributes:
  788. * @li expose_hidden:An bool identifying if expose the hidden state of last time step. Default to false.
  789. * @li num_output:An integer identifying the number of output features. Default to 0 . \n
  790. * @par Outputs:
  791. * two outputs:
  792. * @li o_t:A 4D Tensor. Must be one of the following types: float16, float32.
  793. * @li h_t:A 4D Tensor. Must be one of the following types: float16, float32.
  794. * @par Restrictions:
  795. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  796. */
  797. REG_OP(BasicRNNCell)
  798. .INPUT(x, TensorType({DT_FLOAT16}))
  799. .OPTIONAL_INPUT(cont, TensorType({DT_FLOAT16}))
  800. .OPTIONAL_INPUT(w_xh_x_static, TensorType({DT_FLOAT16, DT_FLOAT}))
  801. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16, DT_FLOAT}))
  802. .INPUT(w_xh, TensorType({DT_FLOAT16}))
  803. .INPUT(bias_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  804. .OPTIONAL_INPUT(w_hh, TensorType({DT_FLOAT16}))
  805. .INPUT(w_ho, TensorType({DT_FLOAT16}))
  806. .INPUT(bias_o, TensorType({DT_FLOAT16, DT_FLOAT}))
  807. .OUTPUT(o_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  808. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  809. .ATTR(expose_hidden, Bool, false)
  810. .ATTR(num_output, Int, 0)
  811. .OP_END_FACTORY_REG(BasicRNNCell)
  812. /**
  813. * @brief DynamicGRU calculation.
  814. * @par Inputs:
  815. * seven inputs:
  816. * @li x:Must be one of the following types: float16.
  817. * @li w:Must be one of the following types: float16.
  818. * @li b:Must be one of the following types: float16, float32. The format must be ND.
  819. * @li cw:Must be one of the following types: float16.
  820. * @li cb:Must be one of the following types: float16, float32. The format must be ND.
  821. * @li seq_length:Must be one of the following types: int32. The format must be ND.
  822. * @li init_h:Must be one of the following types: float16, float32.
  823. * @par Attributes:
  824. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  825. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  826. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  827. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  828. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  829. * @li time_major:An bool identifying the time major in the op. Default to true.
  830. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  831. * @li is_training:An bool identifying is training in the op. Default to true.
  832. * @par Outputs:
  833. * five outputs:
  834. * @li y:Must be one of the following types: float16, float32.
  835. * @li output_h:Must be one of the following types: float16, float32.
  836. * @li r:Must be one of the following types: float16, float32.
  837. * @li i:Must be one of the following types: float16, float32.
  838. * @li n:Must be one of the following types: float16, float32.
  839. * @par Restrictions:
  840. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  841. */
  842. REG_OP(DynamicGRU)
  843. .INPUT(x, TensorType({DT_FLOAT16}))
  844. .INPUT(w, TensorType({DT_FLOAT16}))
  845. .INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  846. .INPUT(cw, TensorType({DT_FLOAT16}))
  847. .INPUT(cb, TensorType({DT_FLOAT16, DT_FLOAT}))
  848. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  849. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  850. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  851. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  852. .OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  853. .OUTPUT(i, TensorType({DT_FLOAT16, DT_FLOAT}))
  854. .OUTPUT(n, TensorType({DT_FLOAT16, DT_FLOAT}))
  855. .ATTR(direction, String, "UNIDIRECTIONAL")
  856. .ATTR(cell_depth, Int, 1)
  857. .ATTR(keep_prob, Float, 1.0)
  858. .ATTR(cell_clip, Float, -1.0)
  859. .ATTR(num_proj, Int, 0)
  860. .ATTR(time_major, Bool, true)
  861. .ATTR(activation, String, "tanh")
  862. .ATTR(is_training, Bool, true)
  863. .OP_END_FACTORY_REG(DynamicGRU)
  864. /**
  865. * @brief DynamicGRUV2 calculation.
  866. * @par Inputs:
  867. * seven inputs:
  868. * @li x:Must be one of the following types: float16.
  869. * @li weight_input:Must be one of the following types: float16.
  870. * @li weight_hidden:Must be one of the following types: float16.
  871. * @li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  872. * @li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  873. * @li seq_length:Must be one of the following types: int32 in ND.
  874. * @li init_h:Must be one of the following types: float16, float32.
  875. * @par Attributes:
  876. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Support "UNIDIRECTIONAL" and "REDIRECTIONAL".
  877. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  878. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  879. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  880. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  881. * @li time_major:An bool identifying the time major in the op. Default to true.
  882. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  883. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  884. * @li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  885. * @li is_training:An bool identifying is training in the op. Default to true.
  886. * @par Outputs:
  887. * six outputs:
  888. * @li y:Must be one of the following types: float16, float32.
  889. * @li output_h:Must be one of the following types: float16, float32.
  890. * @li update:Must be one of the following types: float16, float32.
  891. * @li reset:Must be one of the following types: float16, float32.
  892. * @li new:Must be one of the following types: float16, float32.
  893. * @li hidden_new:Must be one of the following types: float16, float32.
  894. */
  895. REG_OP(DynamicGRUV2)
  896. .INPUT(x, TensorType({DT_FLOAT16}))
  897. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  898. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  899. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  900. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  901. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32, DT_FLOAT16}))
  902. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  903. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  904. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  905. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  906. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  907. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  908. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  909. .ATTR(direction, String, "UNIDIRECTIONAL")
  910. .ATTR(cell_depth, Int, 1)
  911. .ATTR(keep_prob, Float, 1.0)
  912. .ATTR(cell_clip, Float, -1.0)
  913. .ATTR(num_proj, Int, 0)
  914. .ATTR(time_major, Bool, true)
  915. .ATTR(activation, String, "tanh")
  916. .ATTR(gate_order, String, "zrh")
  917. .ATTR(reset_after, Bool, true)
  918. .ATTR(is_training, Bool, true)
  919. .OP_END_FACTORY_REG(DynamicGRUV2)
  920. /**
  921. * @brief DynamicGRUV2Hidden calculation.
  922. * @par Inputs:
  923. * five inputs:
  924. * @li x_weight_input:Must be one of the following types: float32.
  925. * @li weight_hidden:Must be one of the following types: float16.
  926. * @li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  927. * @li seq_length:Must be one of the following types: int32 in ND.
  928. * @li init_h:Must be one of the following types: float16, float32.
  929. * @par Attributes:
  930. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Support "UNIDIRECTIONAL" and "REDIRECTIONAL".
  931. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  932. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  933. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  934. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  935. * @li time_major:An bool identifying the time major in the op. Default to true.
  936. * @li activation:An string identifying the type of activation function in the op. Default to "tanh".
  937. Only tanh is currently supported.
  938. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  939. * @li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  940. * @li is_training:An bool identifying is training in the op. Default to true.
  941. *@par Outputs:
  942. * six outputs:
  943. * @li y:Must be one of the following types: float16, float32.
  944. * @li output_h:Must be one of the following types: float16, float32.
  945. * @li update:Must be one of the following types: float16, float32.
  946. * @li reset:Must be one of the following types: float16, float32.
  947. * @li new:Must be one of the following types: float16, float32.
  948. * @li hidden_new:Must be one of the following types: float16, float32.
  949. * @par Restrictions:
  950. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  951. */
  952. REG_OP(DynamicGRUV2Hidden)
  953. .INPUT(x_weight_input, TensorType({DT_FLOAT32}))
  954. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  955. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  956. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32, DT_FLOAT16}))
  957. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  958. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  959. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  960. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  961. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  962. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  963. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  964. .ATTR(direction, String, "UNIDIRECTIONAL")
  965. .ATTR(cell_depth, Int, 1)
  966. .ATTR(keep_prob, Float, 1.0)
  967. .ATTR(cell_clip, Float, -1.0)
  968. .ATTR(num_proj, Int, 0)
  969. .ATTR(time_major, Bool, true)
  970. .ATTR(activation, String, "tanh")
  971. .ATTR(gate_order, String, "zrh")
  972. .ATTR(reset_after, Bool, true)
  973. .ATTR(is_training, Bool, true)
  974. .OP_END_FACTORY_REG(DynamicGRUV2Hidden)
  975. /**
  976. * @brief DynamicAUGRU calculation.
  977. * @par Inputs:
  978. * eight inputs:
  979. * @li x:Must be one of the following types: float16.
  980. * @li weight_input:Must be one of the following types: float16.
  981. * @li weight_hidden:Must be one of the following types: float16.
  982. * @li weight_attr:Must be one of the following types: float16.
  983. * @li bias_input:Must be one of the following types: float16, float32. The format must be ND.
  984. * @li bias_hidden:Must be one of the following types: float16, float32. The format must be ND.
  985. * @li seq_length:Must be one of the following types: int32 in ND.
  986. * @li init_h:Must be one of the following types: float16, float32.
  987. * @par Attributes:
  988. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  989. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  990. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  991. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  992. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  993. * @li time_major:An bool identifying the time major in the op. Default to true.
  994. * @li activation:An string identifying the type of activation function in the op. Default to "tanh". Only tanh is currently supported.
  995. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  996. * @li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  997. * @li is_training:An bool identifying is training in the op. Default to true.
  998. * @par Outputs:
  999. * seven outputs:
  1000. * @li y:Must be one of the following types: float16, float32.
  1001. * @li output_h:Must be one of the following types: float16, float32.
  1002. * @li update:Must be one of the following types: float16, float32.
  1003. * @li update_att:Must be one of the following types: float16, float32.
  1004. * @li reset:Must be one of the following types: float16, float32.
  1005. * @li new:Must be one of the following types: float16, float32.
  1006. * @li hidden_new:Must be one of the following types: float16, float32.
  1007. */
  1008. REG_OP(DynamicAUGRU)
  1009. .INPUT(x, TensorType({DT_FLOAT16}))
  1010. .INPUT(weight_input, TensorType({DT_FLOAT16}))
  1011. .INPUT(weight_hidden, TensorType({DT_FLOAT16}))
  1012. .INPUT(weight_att, TensorType({DT_FLOAT16}))
  1013. .OPTIONAL_INPUT(bias_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1014. .OPTIONAL_INPUT(bias_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1015. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32, DT_FLOAT16}))
  1016. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1017. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1018. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1019. .OUTPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1020. .OUTPUT(update_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1021. .OUTPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1022. .OUTPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1023. .OUTPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1024. .ATTR(direction, String, "UNIDIRECTIONAL")
  1025. .ATTR(cell_depth, Int, 1)
  1026. .ATTR(keep_prob, Float, 1.0)
  1027. .ATTR(cell_clip, Float, -1.0)
  1028. .ATTR(num_proj, Int, 0)
  1029. .ATTR(time_major, Bool, true)
  1030. .ATTR(activation, String, "tanh")
  1031. .ATTR(gate_order, String, "zrh")
  1032. .ATTR(reset_after, Bool, true)
  1033. .ATTR(is_training, Bool, true)
  1034. .OP_END_FACTORY_REG(DynamicAUGRU)
  1035. /**
  1036. * @brief: DynamicAUGRUGrad calculation.
  1037. * @par Inputs:
  1038. * sixteen inputs: \n
  1039. * @li x:A 4D Tensor. Must be one of the following types: float16, float32.
  1040. * @li weight_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1041. * @li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1042. * @li weight_att:A 4D Tensor. Must be one of the following types: float16, float32.
  1043. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  1044. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1045. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  1046. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  1047. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  1048. * @li update:A 4D Tensor. Must be one of the following types: float16, float32.
  1049. * @li update_att:A 4D Tensor. Must be one of the following types: float16, float32.
  1050. * @li reset:A 4D Tensor. Must be one of the following types: float16, float32.
  1051. * @li new:A 4D Tensor. Must be one of the following types: float16, float32.
  1052. * @li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32.
  1053. * @li seq_length:A 4D Tensor. Must be one of the following types: float16, float32.
  1054. * @li mask:A 4D Tensor. Must be one of the following types: float16, float32.
  1055. * @par Attributes:
  1056. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  1057. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  1058. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  1059. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  1060. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  1061. * @li time_major:An bool identifying the time major in the op. Default to true.
  1062. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  1063. * @li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  1064. * @par Outputs:
  1065. * seven outputs: \n
  1066. * @li dw_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1067. * @li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1068. * @li db_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1069. * @li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1070. * @li dx:A 4D Tensor. Must be one of the following types: float16, float32.
  1071. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  1072. * @li dw_att:A 4D Tensor. Must be one of the following types: float16, float32.
  1073. * @par Restrictions:
  1074. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1075. */
  1076. REG_OP(DynamicAUGRUGrad)
  1077. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1078. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1079. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1080. .INPUT(weight_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1081. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1082. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1083. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1084. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  1085. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  1086. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1087. .INPUT(update_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1088. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1089. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1090. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1091. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  1092. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  1093. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1094. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1095. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1096. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1097. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  1098. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  1099. .OUTPUT(dw_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1100. .ATTR(direction, String, "UNIDIRECTIONAL")
  1101. .ATTR(cell_depth, Int, 1)
  1102. .ATTR(keep_prob, Float, -1.0)
  1103. .ATTR(cell_clip, Float, -1.0)
  1104. .ATTR(num_proj, Int, 0)
  1105. .ATTR(time_major, Bool, true)
  1106. .ATTR(gate_order, String, "zrh")
  1107. .ATTR(reset_after, Bool, true)
  1108. .OP_END_FACTORY_REG(DynamicAUGRUGrad)
  1109. /**
  1110. * @brief: AUGRUHiddenGrad calculation.
  1111. * @par Inputs:
  1112. * twelve inputs: \n
  1113. * @li weight_att:A 4D Tensor. Must be one of the following types: float16, float32.
  1114. * @li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32.
  1115. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1116. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  1117. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  1118. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  1119. * @li update:A 4D Tensor. Must be one of the following types: float16, float32.
  1120. * @li update_att:A 4D Tensor. Must be one of the following types: float16, float32.
  1121. * @li reset:A 4D Tensor. Must be one of the following types: float16, float32.
  1122. * @li new:A 4D Tensor. Must be one of the following types: float16, float32.
  1123. * @li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32.
  1124. * @li seq_mask:A 4D Tensor. Must be one of the following types: float16, float32.
  1125. * @par Attributes:
  1126. * @li t_state:An Int identifying the current t state. Default to [0, 4].
  1127. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  1128. * @par Outputs:
  1129. * four outputs: \n
  1130. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  1131. * @li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1132. * @li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32.
  1133. * @li dw_att_t:A 4D Tensor. Must be one of the following types: float16, float32.
  1134. * @par Restrictions:
  1135. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1136. */
  1137. REG_OP(AUGRUHiddenGradCell)
  1138. .INPUT(weight_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1139. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1140. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1141. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  1142. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  1143. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1144. .INPUT(update_att, TensorType({DT_FLOAT16, DT_FLOAT}))
  1145. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1146. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1147. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1148. .OPTIONAL_INPUT(seq_length, TensorType({DT_FLOAT16, DT_FLOAT}))
  1149. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  1150. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1151. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1152. .OUTPUT(dw_att_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1153. .ATTR(t_state, Int, 0)
  1154. .ATTR(gate_order, String, "zrh")
  1155. .OP_END_FACTORY_REG(AUGRUHiddenGradCell)
  1156. /**
  1157. * @brief: DynamicGRUV2Grad calculation.
  1158. * @par Inputs:
  1159. * fourteen inputs: \n
  1160. * @li x:A 4D Tensor. Must be one of the following types: float16, float32.
  1161. * @li weight_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1162. * @li weight_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1163. * @li y:A 4D Tensor. Must be one of the following types: float16, float32.
  1164. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1165. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  1166. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  1167. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  1168. * @li update:A 4D Tensor. Must be one of the following types: float16, float32.
  1169. * @li reset:A 4D Tensor. Must be one of the following types: float16, float32.
  1170. * @li new:A 4D Tensor. Must be one of the following types: float16, float32.
  1171. * @li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32.
  1172. * @li seq_length:A 4D Tensor. Must be one of the following types: float16, float32.
  1173. * @li mask:A 4D Tensor. Must be one of the following types: float16, float32.
  1174. * @par Attributes:
  1175. * @li direction:An string identifying the direction in the op. Default to "UNIDIRECTIONAL". Only UNIDIRECTIONAL is currently supported.
  1176. * @li cell_depth:An integer identifying the cell depth in the op. Default to 1.
  1177. * @li keep_prob:An float identifying the keep prob in the op. Default to 1.
  1178. * @li cell_clip:An float identifying the cell clip in the op. Default to -1.
  1179. * @li num_proj:An integer identifying the num projection in the op. Default to 0.
  1180. * @li time_major:An bool identifying the time major in the op. Default to true.
  1181. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  1182. * @li reset_after:An bool identifying whether to apply reset gate after matrix multiplication. Default to true.
  1183. * @par Outputs:
  1184. * six outputs: \n
  1185. * @li dw_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1186. * @li dw_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1187. * @li db_input:A 4D Tensor. Must be one of the following types: float16, float32.
  1188. * @li db_hidden:A 4D Tensor. Must be one of the following types: float16, float32.
  1189. * @li dx:A 4D Tensor. Must be one of the following types: float16, float32.
  1190. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  1191. * @par Restrictions:
  1192. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1193. */
  1194. REG_OP(DynamicGRUV2Grad)
  1195. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1196. .INPUT(weight_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1197. .INPUT(weight_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1198. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1199. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1200. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1201. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  1202. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  1203. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1204. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1205. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1206. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1207. .OPTIONAL_INPUT(seq_length, TensorType({DT_INT32}))
  1208. .OPTIONAL_INPUT(mask, TensorType({DT_UINT8}))
  1209. .OUTPUT(dw_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1210. .OUTPUT(dw_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1211. .OUTPUT(db_input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1212. .OUTPUT(db_hidden, TensorType({DT_FLOAT16, DT_FLOAT}))
  1213. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  1214. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  1215. .ATTR(direction, String, "UNIDIRECTIONAL")
  1216. .ATTR(cell_depth, Int, 0)
  1217. .ATTR(keep_prob, Float, -1.0)
  1218. .ATTR(cell_clip, Float, -1.0)
  1219. .ATTR(num_proj, Int, 0)
  1220. .ATTR(time_major, Bool, true)
  1221. .ATTR(gate_order, String, "zrh")
  1222. .ATTR(reset_after, Bool, true)
  1223. .OP_END_FACTORY_REG(DynamicGRUV2Grad)
  1224. /**
  1225. * @brief: GRUV2HiddenGrad calculation.
  1226. * @par Inputs:
  1227. * nine inputs: \n
  1228. * @li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32.
  1229. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1230. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  1231. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  1232. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  1233. * @li update:A 4D Tensor. Must be one of the following types: float16, float32.
  1234. * @li reset:A 4D Tensor. Must be one of the following types: float16, float32.
  1235. * @li new:A 4D Tensor. Must be one of the following types: float16, float32.
  1236. * @li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32.
  1237. * @li seq_length:A 1D Tensor. Must be one of the following types: float16, float32.
  1238. * @par Attributes:
  1239. * @li t_state:An Int identifying the current t state. Default to [0, 4].
  1240. * @li gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  1241. * @par Outputs:
  1242. * three outputs: \n
  1243. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  1244. * @li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1245. * @li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32.
  1246. * @par Restrictions:
  1247. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1248. */
  1249. REG_OP(GRUV2HiddenGradCell)
  1250. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1251. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1252. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  1253. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  1254. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1255. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1256. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1257. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1258. .OPTIONAL_INPUT(seq_length, TensorType({DT_FLOAT16, DT_FLOAT}))
  1259. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  1260. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1261. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1262. .ATTR(t_state, Int, 0)
  1263. .ATTR(gate_order, String, "zrh")
  1264. .OP_END_FACTORY_REG(GRUV2HiddenGradCell)
  1265. /**
  1266. * @brief: DynamicGRUCellGrad calculation.
  1267. * @par Inputs:
  1268. * eleven inputs: \n
  1269. * @li dh_pre_t:A 4D Tensor. Must be one of the following types: float16, float32.
  1270. * @li h:A 4D Tensor. Must be one of the following types: float16, float32.
  1271. * @li dy:A 4D Tensor. Must be one of the following types: float16, float32.
  1272. * @li dh:A 4D Tensor. Must be one of the following types: float16, float32.
  1273. * @li update:A 4D Tensor. Must be one of the following types: float16, float32.
  1274. * @li reset:A 4D Tensor. Must be one of the following types: float16, float32.
  1275. * @li new:A 4D Tensor. Must be one of the following types: float16, float32.
  1276. * @li hidden_new:A 4D Tensor. Must be one of the following types: float16, float32.+
  1277. * @li init_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1278. * @li t_state:A 1D Tensor. Must be one of the following types: int32. The format must be ND.
  1279. * @li seq_length:A 1D Tensor. Must be one of the following types: float16, float32.
  1280. * @par Attributes:
  1281. * gate_order:An string identifying the gate order in weight and bias. Default to "zrh". "rzh" is another option.
  1282. * @par Outputs:
  1283. * three outputs: \n
  1284. * @li dh_prev:A 4D Tensor. Must be one of the following types: float16, float32.
  1285. * @li dgate_h:A 4D Tensor. Must be one of the following types: float16, float32.
  1286. * @li dnt_x:A 4D Tensor. Must be one of the following types: float16, float32.
  1287. * @par Restrictions:
  1288. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1289. */
  1290. REG_OP(DynamicGRUCellGrad)
  1291. .INPUT(dh_pre_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1292. .INPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1293. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  1294. .INPUT(dh, TensorType({DT_FLOAT16, DT_FLOAT}))
  1295. .INPUT(update, TensorType({DT_FLOAT16, DT_FLOAT}))
  1296. .INPUT(reset, TensorType({DT_FLOAT16, DT_FLOAT}))
  1297. .INPUT(new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1298. .INPUT(hidden_new, TensorType({DT_FLOAT16, DT_FLOAT}))
  1299. .INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1300. .INPUT(t_state, TensorType({DT_INT32, DT_INT32}))
  1301. .OPTIONAL_INPUT(seq_length, TensorType({DT_FLOAT16, DT_FLOAT}))
  1302. .OUTPUT(dh_prev, TensorType({DT_FLOAT16, DT_FLOAT}))
  1303. .OUTPUT(dgate_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1304. .OUTPUT(dnt_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1305. .ATTR(gate_order, String, "zrh")
  1306. .OP_END_FACTORY_REG(DynamicGRUCellGrad)
  1307. /**
  1308. * @brief Calculates the reversed outputs of the function "embedding". \n
  1309. * @par Inputs:
  1310. * Two inputs, including:
  1311. * @li grad: A mutable Tensor of word grad. Must be one of the following types:
  1312. * float32.
  1313. * @li indices: A mutable word index Tensor of the int32 type.\n
  1314. * @par Attributes:
  1315. * @li num_weights: An int attr which use to judge how many words in dict. \n
  1316. * @li padding_idx: An int attr judge which word to fill zeros. Defaults to "-1". \n
  1317. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  1318. * If "True", "grad_weight" will be scale by word_frequency.
  1319. * If "False", "grad_weight" will not be scale by word_frequency. \n
  1320. * @par Outputs:
  1321. * y: A mutable output Tensor of new word grad has the same type as "grads". \n
  1322. * @par Third-party framework compatibility
  1323. * Compatible with the Pytorch operator EmbeddingDenseGrad.
  1324. */
  1325. REG_OP(EmbeddingDenseGrad)
  1326. .INPUT(grad, TensorType({ DT_FLOAT32 })) /* "First operand." */
  1327. .INPUT(indices, TensorType({ DT_INT32 })) /* "Second operand." */
  1328. .OUTPUT(y, TensorType({ DT_FLOAT32 })) /* "Result, has same element type as two inputs" */
  1329. .REQUIRED_ATTR(num_weights, Int)
  1330. .ATTR(padding_idx, Int, -1)
  1331. .ATTR(scale_grad_by_freq, Bool, false)
  1332. .OP_END_FACTORY_REG(EmbeddingDenseGrad)
  1333. /**
  1334. * @brief CommonLSTM calculation.
  1335. * @par Inputs:
  1336. * eight inputs: \n
  1337. * @li x:Each time step is a 4D Tensor. Must be one of the following types: float16, float32.
  1338. * @li w:Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1339. * @li r:Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1340. * @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.
  1341. * @li sequence_lens:An optional input. A 1D Tensor.Must be one of the following types: int32. The format must be ND.
  1342. * @li initial_h:An optional input. Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1343. * @li initial_c:An optional input. Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1344. * @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.
  1345. * @par Attributes:
  1346. * @li activation_alpha:Optional scaling values used by some activation functions. Empty is currently supported.
  1347. * @li activation_beta:Optional scaling values used by some activation functions. Empty is currently supported.
  1348. * @li activations:The list of activation functions. Empty is currently supported.
  1349. * @li clip:An float identifying the cell clip in the op. Default to -1.
  1350. * @li direction:Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward(default), reverse, or bidirectional.
  1351. * @li hidden_size:Number of neurons in the hidden layer. Reserved.
  1352. * @li input_forget:Couple the input and forget gates if 1. Reserved.
  1353. * @par Outputs:
  1354. * three outputs: \n
  1355. * @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.
  1356. * @li y_h:Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1357. * @li y_c:Each direction is a 4D Tensor. Must be one of the following types: float16, float32.
  1358. */
  1359. REG_OP(CommonLSTM)
  1360. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1361. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  1362. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  1363. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  1364. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  1365. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1366. .OPTIONAL_INPUT(initial_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1367. .OPTIONAL_INPUT(p, TensorType({DT_FLOAT16, DT_FLOAT}))
  1368. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1369. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1370. .OUTPUT(y_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1371. .ATTR(activation_alpha, ListFloat, {})
  1372. .ATTR(activation_beta, ListFloat, {})
  1373. .ATTR(activations, ListString, {})
  1374. .ATTR(clip, Float, -1.0)
  1375. .ATTR(direction, String, "forward")
  1376. .REQUIRED_ATTR(hidden_size, Int)
  1377. .ATTR(input_forget, Int, 0)
  1378. .OP_END_FACTORY_REG(CommonLSTM)
  1379. /**
  1380. * @brief Calculate the mask. According to hidden_size and num_step, convert seq_length to mask.
  1381. *
  1382. * @par Inputs:
  1383. * @li seq_length: A 1D Tensor. Must be one of the following types: int32. Record the current length of each batch. [batch_size].
  1384. * @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].
  1385. * @li hidden_size: An optional attribute of type int32. pass the hidden_size. \n
  1386. *
  1387. * @par Outputs:
  1388. * 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
  1389. *
  1390. * @par Restrictions:
  1391. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1392. */
  1393. REG_OP(RnnGenMaskV2)
  1394. .INPUT(seq_length, TensorType({DT_INT32}))
  1395. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1396. .REQUIRED_ATTR(hidden_size, Int)
  1397. .OUTPUT(seq_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  1398. .OP_END_FACTORY_REG(RnnGenMaskV2)
  1399. /**
  1400. * @brief Common GRU calculation.
  1401. * @par Inputs:
  1402. * Eight inputs, including:
  1403. * @li x: The input sequences packed (and pontentially padded) into on 3D Tesnor(float16).
  1404. * @li w: The weight tensor for the gates is 3D Tensor(float16).
  1405. * @li r: The recurrence weight tesnor is 3D Tensor(float16).
  1406. * @li b: The bias tensor for the gates. The format must be ND
  1407. * @li sequence_lens: Optional tensor specifying lengths of sequences(int32). The format must be ND
  1408. * @li init_h: Optional initial value of the hidden(float16,float32).
  1409. * @par Attributes:
  1410. * @li activation_alpha: Optional scaling values used by some activation functions. \n
  1411. * @li activation_beta: Optional scaling values used by some activation functions. \n
  1412. * @li activations: A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. \n
  1413. * @li clip: Cell clip threshold. \n
  1414. * @li direction: Specify if the RNN is forward, reverse, or bidirectional. \n
  1415. * @li hidden_size: Number of neurons in the hidden layer. \n
  1416. * @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
  1417. * @par Outputs:
  1418. * @li y: A Tensor that concats all the intermediate output values of the hidden(float16,float32).
  1419. * @li y_h: The last output value of the hidden(float16,float32).
  1420. */
  1421. REG_OP(CommonGRU)
  1422. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1423. .INPUT(w, TensorType({DT_FLOAT16, DT_FLOAT}))
  1424. .INPUT(r, TensorType({DT_FLOAT16, DT_FLOAT}))
  1425. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_FLOAT}))
  1426. .OPTIONAL_INPUT(sequence_lens, TensorType({DT_INT32}))
  1427. .OPTIONAL_INPUT(initial_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1428. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1429. .OUTPUT(y_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1430. .ATTR(activation_alpha, ListFloat, {})
  1431. .ATTR(activation_beta , ListFloat, {})
  1432. .ATTR(activations , ListString, {})
  1433. .ATTR(clip, Float, -1.0)
  1434. .ATTR(direction, String, "forward")
  1435. .REQUIRED_ATTR(hidden_size, Int)
  1436. .ATTR(linear_before_reset , Int, 0)
  1437. .OP_END_FACTORY_REG(CommonGRU)
  1438. /**
  1439. * @brief Calculates the reversed outputs of the function "embedding". \n
  1440. * @par Inputs:
  1441. * Four inputs, including:
  1442. * @li weight: A mutable Tensor of word grad. Must be one of the following types:
  1443. * float32.
  1444. * @li indices: A mutable word index Tensor of the int32 type.\n
  1445. * @li offsets: A mutable word index Tensor of the int32 type.\n
  1446. * @li per_sample_weights: to indicate all weights should be taken to be 1.
  1447. * If specified, per_sample_weights must have exactly the same shape as input
  1448. * and is treated as having the same offsets, if those are not None.
  1449. * Only supported for mode='sum'.\n
  1450. * @par Attributes:
  1451. * @li mode: An string attr which use "sum"``, ``"mean"`` or ``"max"``. Specifies the way to reduce the bag. \n
  1452. * @li scale_grad_by_freq: An optional bool. Defaults to "False".
  1453. * If "True", "grad_weight" will be scale by word_frequency.
  1454. * If "False", "grad_weight" will not be scale by word_frequency. \n
  1455. * @li sparse: if True, gradient w.r.t.attr weight matrix will be a sparse tensor. \n
  1456. * @li include_last_offset: if True, attr offsets has one additional element, where the last element
  1457. * is equivalent to the size of indices. This matches the CSR format. \n
  1458. * @par Outputs:
  1459. * y: A mutable output Tensor of new word grad has the same type as "grads". \n
  1460. * @par Third-party framework compatibility
  1461. * Compatible with the Pytorch operator EmbeddingBag.
  1462. */
  1463. REG_OP(EmbeddingBag)
  1464. .INPUT(weight, TensorType({ DT_FLOAT32 }))
  1465. .INPUT(indices, TensorType({ DT_INT32 }))
  1466. .OPTIONAL_INPUT(offsets, TensorType({DT_INT32}))
  1467. .OPTIONAL_INPUT(per_sample_weights, TensorType({DT_FLOAT32}))
  1468. .OUTPUT(y, TensorType({ DT_FLOAT32 }))
  1469. .ATTR(mode, String, "mean")
  1470. .ATTR(scale_grad_by_freq, Bool, false)
  1471. .ATTR(sparse, Bool, false)
  1472. .ATTR(include_last_offset, Bool, false)
  1473. .OP_END_FACTORY_REG(EmbeddingBag)
  1474. /**
  1475. * @brief:LSTMP calculation
  1476. * @par Inputs:
  1477. * eight inputs:
  1478. * @li x:A required Tensor(seq, batch, dim). Must be one of the following types: float16, float32.
  1479. * @li real_mask:A optional Tensor(seq, batch). Must be one of the following types: float16, float32.
  1480. * @li init_h:A optional Tensor(batch, state). Must be one of the following types: float16, float32.
  1481. * @li init_c:A optional Tensor(batch, hidden). Must be one of the following types: float16, float32.
  1482. * @li wx:A required Tensor(4*hidden, dim). Must be one of the following types: float16, float32.
  1483. * @li wr:A required Tensor(4*hidden, state). Must be one of the following types: float16, float32.
  1484. * @li bias:A optional Tensor(hidden). Must be one of the following types: float16, float32. The format must be ND.
  1485. * @li project: A optional Tensor. Must be one of the following types: float16, float32.
  1486. *
  1487. * @par Outputs:
  1488. * three outputs:
  1489. * @li y:A Tensor. Must be one of the following types: float16, float32.
  1490. * @li output_h:A Tensor. Must be one of the following types: float16, float32.
  1491. * @li output_c:A Tensor. Must be one of the following types: float16, float32.
  1492. *
  1493. *@par Attributes:
  1494. * time_major:An bool identifying the time major in the op. Default to false.
  1495. * @par Restrictions:
  1496. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1497. */
  1498. REG_OP(LSTMP)
  1499. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1500. .INPUT(wx, TensorType({DT_FLOAT16, DT_FLOAT}))
  1501. .INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT}))
  1502. .INPUT(wr, TensorType({DT_FLOAT16, DT_FLOAT}))
  1503. .INPUT(project, TensorType({DT_FLOAT16, DT_FLOAT}))
  1504. .OPTIONAL_INPUT(real_mask, TensorType({DT_FLOAT16, DT_FLOAT}))
  1505. .OPTIONAL_INPUT(init_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1506. .OPTIONAL_INPUT(init_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1507. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1508. .OUTPUT(output_h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1509. .OUTPUT(output_c, TensorType({DT_FLOAT16, DT_FLOAT}))
  1510. .ATTR(time_major, Bool, false)
  1511. .OP_END_FACTORY_REG(LSTMP)
  1512. } // namespace ge
  1513. #endif // OPS_BUILT_IN_OP_PROTO_INC_RNN_H_

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