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.

nn_norm_ops.h 72 kB

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
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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 nn_norm_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_NN_NORM_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_NN_NORM_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Computes the gradient for log softmax activations . \n
  26. *@par Inputs:
  27. *@li grad: A Tensor. Must be one of the following types: float16, float32.
  28. *@li x: A Tensor. Must be one of the following types: float16, float32 . \n
  29. *@par Attributes:
  30. * axis: An optional list of ints. Defaults to "{-1}" . \n
  31. *@par Outputs:
  32. * y: A Tensor. Has the same type as "grad" . \n
  33. *@par Third-party framework compatibility
  34. *Compatible with the TensorFlow operator LogSoftmaxGrad.
  35. */
  36. REG_OP(LogSoftmaxGrad)
  37. .INPUT(grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  38. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  39. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  40. .ATTR(axis, ListInt, {-1})
  41. .OP_END_FACTORY_REG(LogSoftmaxGrad)
  42. /**
  43. *@brief Computes sparse softmax cross entropy cost and gradients to backpropagate . \n
  44. *@par Inputs:
  45. *Two inputs, including:
  46. * @li features: A Tensor. Must be one of the following types: half, float32, double.
  47. *A "batch_size * num_classes" matrix.
  48. * @li labels: A Tensor. Must be one of the following types: 'int32', 'int64'.
  49. *batch_size vector with values in [0, num_classes).
  50. *This is the label for the given minibatch entry. \n
  51. *@par Outputs:
  52. *@li loss: A Tensor for per example loss (a "batch_size" vector). Has the same type as "features".
  53. *@li backprop: A Tensor for the backpropagated gradients (a batch_size * num_classes matrix).
  54. Has the same type as "features" . \n
  55. *@par Third-party framework compatibility
  56. *Compatible with the TensorFlow operator SparseSoftmaxCrossEntropyWithLogits.
  57. */
  58. REG_OP(SparseSoftmaxCrossEntropyWithLogits)
  59. .INPUT(features, TensorType({DT_FLOAT16,DT_FLOAT}))
  60. .INPUT(labels, TensorType({DT_INT32, DT_INT64}))
  61. .OUTPUT(loss, TensorType({DT_FLOAT16,DT_FLOAT}))
  62. .OUTPUT(backprop, TensorType({DT_FLOAT16,DT_FLOAT}))
  63. .OP_END_FACTORY_REG(SparseSoftmaxCrossEntropyWithLogits)
  64. /**
  65. *@brief Computes softmax cross entropy cost and gradients to backpropagate . \n
  66. *@par Inputs:
  67. *Two inputs, including:
  68. * @li features: A Tensor. Must be one of the following types: half, float32, double.
  69. * A "batch_size * num_classes" matrix.
  70. * @li labels: A Tensor of the same type as "features". A "batch_size * num_classes" matrix . \n
  71. *@par Outputs:
  72. * @li loss: A Tensor for per example loss (a "batch_size" vector). Has the same type as "features".
  73. * @li backprop: A Tensor for the backpropagated gradients (a batch_size * num_classes matrix). Has the same type as "features" . \n
  74. *@par Third-party framework compatibility
  75. *Compatible with the TensorFlow operator SoftmaxCrossEntropyWithLogits.
  76. */
  77. REG_OP(SoftmaxCrossEntropyWithLogits)
  78. .INPUT(features, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT}))
  79. .INPUT(labels, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT}))
  80. .OUTPUT(loss, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT}))
  81. .OUTPUT(backprop, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT}))
  82. .OP_END_FACTORY_REG(SoftmaxCrossEntropyWithLogits)
  83. /**
  84. *@brief Computes gradients for a softmax operation . \n
  85. *@par Inputs:
  86. * Two inputs, including:
  87. * @li softmax: Output of the softmax operator. Must be one of the following
  88. * types: float16, float31, int32, int8, uint8.
  89. * @li grad_softmax: A Tensor. Has the same shape and type as "softmax".\n
  90. *@par Attributes:
  91. * axes: An optional list of ints. Defaults to "{-1}" . \n
  92. *@par Outputs:
  93. *grad_x: A Tensor. Has the same shape and type as "softmax" . \n
  94. *@par Third-party framework compatibility
  95. * Compatible with TensorFlow operator SoftmaxGrad.
  96. */
  97. REG_OP(SoftmaxGrad)
  98. .INPUT(softmax, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  99. .INPUT(grad_softmax, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  100. .OUTPUT(grad_x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  101. .ATTR(axes, ListInt, {-1})
  102. .OP_END_FACTORY_REG(SoftmaxGrad)
  103. /**
  104. * @brief Computes the sigmoid cross entropy loss of "predict" and "target" .
  105. *@par Inputs:
  106. * Three inputs, including:
  107. *@li predict: A multi-dimensional Tensor of type float16 or float32, specifying the predictive value.
  108. *@li target: A multi-dimensional Tensor of type float16 or float32, specifying the target value .
  109. *@li dout:A multi-dimensional Tensor of float16 or float32,specifying the gradient transferred from the upper layer. \n
  110. *@par Outputs:
  111. *gradient: Sigmoid cross entropy between the predictive value and target value. Has the same dimensions as "predict" . \n
  112. *@par Third-party framework compatibility
  113. * Compatible with the scenario where "reduction" is set to "none"of PyTorch operator SigmoidCrossEntropyWithLogitsGrad.
  114. */
  115. REG_OP(SigmoidCrossEntropyWithLogitsGrad)
  116. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  117. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  118. .INPUT(dout, TensorType({DT_FLOAT16, DT_FLOAT}))
  119. .OUTPUT(gradient, TensorType({DT_FLOAT16, DT_FLOAT}))
  120. .OP_END_FACTORY_REG(SigmoidCrossEntropyWithLogitsGrad)
  121. /**
  122. * @brief Performs the backpropagation of SigmoidCrossEntropyWithLogits for training scenarios .
  123. *@par Inputs:
  124. * Two inputs, including:
  125. *@li predict: A multi-dimensional Tensor of type float16 or float32, specifying the predictive value.
  126. *@li target: A multi-dimensional Tensor of type float16 or float32, specifying the target value. \n
  127. *@par Outputs:
  128. *loss: Return loss. Has the same dimensions and type as "predict" . \n
  129. *@par Third-party framework compatibility
  130. * Compatible with the scenario where "reduction" is set to "none"of PyTorch operator SigmoidCrossEntropyWithLogits.
  131. */
  132. REG_OP(SigmoidCrossEntropyWithLogits)
  133. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  134. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  135. .OUTPUT(loss, TensorType({DT_FLOAT16, DT_FLOAT}))
  136. .OP_END_FACTORY_REG(SigmoidCrossEntropyWithLogits)
  137. /**
  138. *@brief Computes the sigmoid cross entropy loss of "predict" and "target".
  139. *@par Inputs:
  140. * four inputs, including:
  141. *@li predict: A multi-dimensional Tensor of type float16 or float32, specifying the predictive value.
  142. *@li target: A multi-dimensional Tensor of type float16 or float32, specifying the target value.
  143. *@li weight: An multi-dimensional Tensor, specifying the weight value.
  144. *@li pos_weight: An multi-dimensional Tensor, specifying the pos weight value. \n
  145. *@par Attributes:
  146. *reduction: A character string from "none", "mean", and "sum", specifying the reduction type to be applied to the output. Defaults to "mean". \n
  147. *@par Outputs:
  148. *loss: Sigmoid cross entropy between the predictive value and target value. Has the same dimensions as "predict". \n
  149. *@par Third-party framework compatibility
  150. * Compatible with PyTorch operator BCEWithLogitsLoss.
  151. */
  152. REG_OP(SigmoidCrossEntropyWithLogitsV2)
  153. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  154. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  155. .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT16, DT_FLOAT}))
  156. .OPTIONAL_INPUT(pos_weight, TensorType({DT_FLOAT16, DT_FLOAT}))
  157. .OUTPUT(loss, TensorType({DT_FLOAT16, DT_FLOAT}))
  158. .ATTR(reduction, String, "mean")
  159. .OP_END_FACTORY_REG(SigmoidCrossEntropyWithLogitsV2)
  160. /**
  161. * @brief Computes the regression box of the RPN. It is a FasterRCNN operator .
  162. *@par Inputs:
  163. * Two inputs, including:
  164. *@li predict: A multi-dimensional Tensor of type float16 or float32, specifying the predictive value.
  165. *@li label: A multi-dimensional Tensor of type float16 or float32, specifying the target value . \n
  166. *@par Attributes:
  167. * sigma: Must be a floating point number. Defaults to "1.0" . \n
  168. *@par Outputs:
  169. *loss: Indicates the loss between the predictive value and target value. Has the same dimensions as "predict" . \n
  170. *@attention Constraints:
  171. * This operator does not perform the "reduce" operation on the loss value. Call other reduce operators to perform "reduce" operation on the loss if required . \n
  172. *@par Third-party framework compatibility
  173. * Compatible with the scenario where "reduction" is set to "none"of PyTorch operator SmoothL1Loss.
  174. */
  175. REG_OP(SmoothL1Loss)
  176. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  177. .INPUT(label, TensorType({DT_FLOAT16, DT_FLOAT}))
  178. .OUTPUT(loss, TensorType({DT_FLOAT16, DT_FLOAT}))
  179. .ATTR(sigma, Float, 1.0)
  180. .OP_END_FACTORY_REG(SmoothL1Loss)
  181. /**
  182. * @brief Performs the backpropagation of SmoothL1Loss for training scenarios .
  183. *@par Inputs:
  184. * Three inputs, including:
  185. *@li predict: A multi-dimensional Tensor of type float16 or float32, specifying the predictive value.
  186. *@li label: A multi-dimensional Tensor of float16 or float32, specifying the target value.
  187. *@li dout: A multi-dimensional Tensor of float16 or float32, specifying the gradient transferred from the upper layer . \n
  188. *@par Attributes:
  189. * sigma: Must be a floating point number. Defaults to "1.0" . \n
  190. *@par Outputs:
  191. *gradient: Return gradient. Has the same dimensions and type as "predict" . \n
  192. *@par Third-party framework compatibility
  193. * Compatible with the scenario where "reduction" is set to "none"of PyTorch operator SmoothL1LossGrad.
  194. */
  195. REG_OP(SmoothL1LossGrad)
  196. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  197. .INPUT(label, TensorType({DT_FLOAT16, DT_FLOAT}))
  198. .INPUT(dout, TensorType({DT_FLOAT16, DT_FLOAT}))
  199. .OUTPUT(gradient, TensorType({DT_FLOAT16, DT_FLOAT}))
  200. .ATTR(sigma, Float, 1.0)
  201. .OP_END_FACTORY_REG(SmoothL1LossGrad)
  202. /**
  203. *@brief Creates a criterion that measures the Binary Cross Entropy between the target and the output . \n
  204. *@par Inputs:
  205. * Three inputs, including:
  206. *@li x: A 1D or 2D Tensor of type float16 or float32, specifying a predictive value.
  207. *@li y: A 1D or 2D Tensor of type float16 or float32, indicating a tag.
  208. *@li weight: An optional 1D or 2D Tensor, specifying the weight . \n
  209. *@par Attributes:
  210. *reduction: A character string from "none", "mean", and "sum", specifying the reduction type to be applied to the output. Defaults to "mean" . \n
  211. *@par Outputs:
  212. *output: Output loss. Has the same dimension with the inputs. When "reduction" is set to "none", a Tensor with the same size as "x" is output. Otherwise, a Scalar is output . \n
  213. *@attention Constraints:
  214. *@li The value of "x" must range from 0 to 1.
  215. *@li The value of "y" must be "0" or "1" . \n
  216. *@par Third-party framework compatibility
  217. * Compatible with PyTorch operator BCELoss.
  218. */
  219. REG_OP(BinaryCrossEntropy)
  220. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  221. .INPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  222. .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  223. .OUTPUT(output, TensorType({DT_FLOAT, DT_FLOAT16}))
  224. .ATTR(reduction, String, "mean")
  225. .OP_END_FACTORY_REG(BinaryCrossEntropy)
  226. /**
  227. *@brief Performs the backpropagation of BinaryCrossEntropy for training scenarios . \n
  228. *@par Inputs:
  229. * Four inputs, including:
  230. *@li x: A 1D or 2D Tensor of type float16 or float32, specifying a predictive value.
  231. *@li y: A 1D or 2D Tensor of type float16 or float32, indicating a tag.
  232. *@li grad_output: A 1D or 2D Tensor of type float16 or float32, specifying the backpropagation gradient.
  233. *@li weight: An optional 1D or 2D Tensor, specifying the weight . \n
  234. *@par Attributes:
  235. *reduction: A character string from "none", "mean", and "sum", specifying the gradient output mode. Defaults to "mean" . \n
  236. *@par Outputs:
  237. *output: A 1D or 2D Tensor. When "reduction" is set to "none", a Tensor with the same size as "x" is output. Otherwise, a Scalar is output . \n
  238. *@attention Constraints:
  239. *@li The value of "x" must range from 0 to 1.
  240. *@li The value of "y" must be "0" or "1" . \n
  241. *@par Third-party framework compatibility
  242. * Compatible with PyTorch operator BCELossGrad.
  243. */
  244. REG_OP(BinaryCrossEntropyGrad)
  245. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  246. .INPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  247. .INPUT(grad_output, TensorType({DT_FLOAT, DT_FLOAT16}))
  248. .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  249. .OUTPUT(output, TensorType({DT_FLOAT, DT_FLOAT16}))
  250. .ATTR(reduction, String, "mean")
  251. .OP_END_FACTORY_REG(BinaryCrossEntropyGrad)
  252. /**
  253. *@brief Applies the Softmax function to an n-dimensional input Tensor
  254. * rescaling them. so that the elements of the n-dimensional output Tensor lie
  255. * in the range [0,1] and sum to 1 . \n
  256. *@par Inputs:
  257. *One input:
  258. *x: A mutable Tensor. Must be one of the following types: float16, float32,
  259. * double. Should be a Variable Tensor . \n
  260. *@par Attributes:
  261. *axes: A list of int. The dimension softmax would be performed on. Defaults
  262. * to "[-1]" . \n
  263. *@par Outputs:
  264. *y: A Tensor. Has the same dimensionality and shape as the "x" with values in
  265. * the range [0, 1]. Must be one of the following types: float16, float32,
  266. * double . \n
  267. *@par Third-party framework compatibility
  268. * Compatible with the TensorFlow operator Softmax.
  269. */
  270. REG_OP(SoftmaxV2)
  271. .INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT16, DT_FLOAT}))
  272. .OUTPUT(y, TensorType({DT_DOUBLE, DT_FLOAT16, DT_FLOAT}))
  273. .ATTR(axes, ListInt, {-1})
  274. .OP_END_FACTORY_REG(SoftmaxV2)
  275. /**
  276. *@brief Function softmax with dropoutDoMaskV3D
  277. *@par Inputs:
  278. *Two inputs, including:
  279. * @li x: A mutable Tensor. The type only support float16.
  280. * @li mask: A mutable Tensor. Must met all of the following rules:
  281. * shape of mask should be 1D.
  282. * dtype of mask should be uint8.
  283. * value of shape should met the following algorithm:
  284. * value = (size(x) + 128 - 1) // 128 * 128
  285. *@par Attributes:
  286. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  287. * shape of "keep_prob" should be (1,) or [1,].
  288. * Has the same type as "x" . \n
  289. * @li axes: A list of int. The dimension softmax would be performed on. Defaults
  290. * to "[-1]" . \n
  291. *@par Outputs:
  292. *y1: A mutable Tensor. Has the same type as "x".
  293. *y2: A mutable Tensor. Has the same type as "x". \n
  294. *@par Restrictions:
  295. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  296. */
  297. REG_OP(SoftmaxV2WithDropOutDoMaskV3D)
  298. .INPUT(x, TensorType({DT_FLOAT16}))
  299. .INPUT(mask, TensorType({DT_UINT8}))
  300. .OUTPUT(y1, TensorType({DT_FLOAT16}))
  301. .OUTPUT(y2, TensorType({DT_FLOAT16}))
  302. .REQUIRED_ATTR(keep_prob, Float)
  303. .ATTR(axes, ListInt, {-1})
  304. .OP_END_FACTORY_REG(SoftmaxV2WithDropOutDoMaskV3D)
  305. /**
  306. *@brief Computes log softmax activations . \n
  307. *@par Inputs:
  308. *One input:
  309. * logits: A Tensor. Must be one of the following types: double, float16, float32 . \n
  310. *@par Attributes:
  311. * axes: An optional list of ints. Defaults to "{-1}" . \n
  312. *@par Outputs:
  313. * logsoftmax: A Tensor. Has the same type as "logits" . \n
  314. *@par Third-party framework compatibility
  315. *Compatible with the TensorFlow operator LogSoftmax.
  316. */
  317. REG_OP(LogSoftmaxV2)
  318. .INPUT(logits, TensorType({DT_DOUBLE, DT_FLOAT16, DT_FLOAT}))
  319. .OUTPUT(logsoftmax, TensorType({DT_DOUBLE, DT_FLOAT16, DT_FLOAT}))
  320. .ATTR(axes, ListInt, {-1})
  321. .OP_END_FACTORY_REG(LogSoftmaxV2)
  322. /**
  323. *@brief Confuse mul, sum and sub . \n
  324. *@par Inputs:
  325. *Two inputs, including:
  326. * @li grad: A Tensor. Must be one of the following types: float16, float32.
  327. * @li x: A Tensor. Must be one of the following types: float16, float32 . \n
  328. *@par Outputs:
  329. * y: A Tensor of the same type as "grad" . \n
  330. *@par Restrictions:
  331. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  332. */
  333. REG_OP(ConfusionSoftmaxGrad)
  334. .INPUT(grad, TensorType({DT_FLOAT16,DT_FLOAT}))
  335. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  336. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  337. .OP_END_FACTORY_REG(ConfusionSoftmaxGrad)
  338. /**
  339. *@brief Function softmax gradients ext . \n
  340. *@par Inputs:
  341. * @li grad: A Tensor dtype of float16, float32.
  342. * @li x1: A Tensor dtype of float16, float32.
  343. * @li x2: A Tensor dtype of float16, float32 . \n
  344. *@par Attributes:
  345. *@li axis: A int Scalar. The axis for reduce.
  346. *@li keepdims: A bool Scalar. If true, retains reduced dimensions with length 1 . \n
  347. *@par Outputs:
  348. * y: A Tensor dtype of float16, float32. \n
  349. *@attention Constraints:
  350. * THIS OPERATOR IS DEPRECATED. It will be removed in a future version.
  351. */
  352. REG_OP(SoftmaxGradExt)
  353. .INPUT(grad, TensorType({DT_FLOAT16,DT_FLOAT}))
  354. .INPUT(x1, TensorType({DT_FLOAT16,DT_FLOAT}))
  355. .INPUT(x2, TensorType({DT_FLOAT16,DT_FLOAT}))
  356. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  357. .ATTR(axes, Int, 1)
  358. .ATTR(keep_dims, Bool, false)
  359. .OP_END_FACTORY_REG(SoftmaxGradExt)
  360. /**
  361. *@brief Normalizes the input . \n
  362. *@par Inputs:
  363. * One input:
  364. *x: An NCHW tensor of type float16 or float32 . \n
  365. *@par Attributes:
  366. *@li normalize_variance: An optional bool specifying whether to normalize the variance, either "true" (default) or "false"
  367. * the value "false" indicates only to subtract the mean.
  368. *@li across_channels: An optional bool specifying whether to perform across-channel MVN, either "true" or "false" (default)
  369. * The value "true" indicates "CHW" is treated as a vector.
  370. *@li eps: An optional float32 epsilon for not dividing by zero. Defaults to "1e-9" . \n
  371. *@par Outputs:
  372. *y: An NCHW tensor of type float16 or float32 . \n
  373. *@attention Constraints:
  374. * The input tensor must have the NCHW format, whose shape length must be 4.
  375. *@par Third-party framework compatibility
  376. * Compatible with the Caffe operator MVN.
  377. */
  378. REG_OP(MVN)
  379. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16})) /* "First operand." */
  380. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16})) /* "Result, has same element type as inputs" */
  381. .ATTR(normalize_variance, Bool, true)
  382. .ATTR(across_channels, Bool, false)
  383. .ATTR(eps, Float, 1e-9)
  384. .OP_END_FACTORY_REG(MVN)
  385. /**
  386. *@brief Normalizes the input . \n
  387. *@par Inputs:
  388. * One input:
  389. *x: An NCHW tensor of type float16 or float32 . \n
  390. *@par Attributes:
  391. *@li eps: An optional float32 epsilon for not dividing by zero. Defaults to "1e-9" . \n
  392. *@li axes: A list of Intefers, along which axis to reduce. Defaults to "[0, 2, 3]" . \n
  393. *@par Outputs:
  394. *y: An NCHW tensor of type float16 or float32 . \n
  395. *@attention Constraints:
  396. * The input tensor must have the NCHW format, whose shape length must be 4.
  397. *@par Third-party framework compatibility
  398. * Compatible with the ONNX operator MeanVarianceNormalization.
  399. */
  400. REG_OP(MVNV2)
  401. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16})) /* "First operand." */
  402. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16})) /* "Result, has same element type as inputs" */
  403. .ATTR(eps, Float, 1e-9)
  404. .ATTR(axes, ListInt, {0, 2, 3})
  405. .OP_END_FACTORY_REG(MVNV2)
  406. /**
  407. *@brief Normalizes the input "x1" . \n
  408. *@par Inputs:
  409. * Two inputs, including:
  410. *@li x1: A required NCHW or NHWC tensor of type float32, float16, or int8.
  411. *@li x2: A required ND tensor of type float32, float16, or int8, specifying
  412. * the scaling factor. If "channel_shared" is "true", "x2" is a [1]-dimensional
  413. * vector. If "channel_shared" is "false", "x2" is a [C]-dimensional vector . \n
  414. *@par Attributes:
  415. *@li across_spatial: An optional bool, specifying the dimension of input "x1"
  416. * to be summed. The value "true" (default) indicates dimensions C, H, W, and
  417. * the value "false" indicates dimension C.
  418. *@li channel_shared: An optional bool, specifying the dimension count of input
  419. * "x2". The value "true" (default) indicates 1, and the value "false" indicates
  420. * dimension C of "x1".
  421. *@li eps: An optional float32, specifying the bias when "across_spatial" is
  422. * "true". Defaults to "1e-10" . \n
  423. *@par Outputs:
  424. *y: A Tensor. Has the same type and format as "x1" . \n
  425. *@par Third-party framework compatibility
  426. * Compatible with the Caffe operator Normalize.
  427. */
  428. REG_OP(Normalize)
  429. .INPUT(x1, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  430. .INPUT(x2, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  431. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  432. .ATTR(across_spatial, Bool, true)
  433. .ATTR(channel_shared, Bool, true)
  434. .ATTR(eps, Float, 1e-10)
  435. .OP_END_FACTORY_REG(Normalize);
  436. /**
  437. *@brief Layernorm operator interface implementation
  438. * calculating: x, gamma, beta
  439. * mean = np.mean(x, reduce_axis, keepdims=True)
  440. * variance = np.mean(np.power((x - mean),2), reduce_axis, keepdims=True)
  441. * y = gamma*((x - mean) / np.sqrt(variance + 0.001)) + beta
  442. *@par Inputs:
  443. *Three inputs, including:
  444. * @li x: A Tensor. Must be one of the following types: float16, float32.
  445. * @li gamma: A Tensor. Must be one of the following types: float16, float32.
  446. * @li beta: A Tensor. Must be one of the following types: float16, float32 . \n
  447. *@par Attributes:
  448. * @li begin_norm_axis: A optional attribute, the type is int32. Defaults to 0.
  449. * @li begin_params_axis: A optional attribute, the type is int32. Defaults to 0.
  450. * @li epsilon: A optional attribute, the type is float32. Defaults to 1e-7 . \n
  451. *@par Outputs:
  452. *Three outputs, including:
  453. * @li y: A Tensor. Must be one of the following types: float16, float32.
  454. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  455. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  456. */
  457. REG_OP(LayerNorm)
  458. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  459. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  460. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  461. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  462. .OUTPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  463. .OUTPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  464. .ATTR(begin_norm_axis, Int, 0)
  465. .ATTR(begin_params_axis, Int, 0)
  466. .ATTR(epsilon, Float, 0.0000001)
  467. .OP_END_FACTORY_REG(LayerNorm)
  468. /**
  469. *@brief Returns a tensor where each sub-tensor of input along dimension
  470. * dim is normalized such that the p-norm of the sub-tensor is lower than the value maxnorm. \n
  471. *@par Inputs:
  472. *One input, including:
  473. * x: A Tensor. Must be one of the following types: float16, float32 . \n
  474. *@par Attributes:
  475. * @li p: Specify L_p norm, the type is float.
  476. * @li dim: The processed dim, the type is int.
  477. * @li maxnorm: Threshold for comparison, the type is float. \n
  478. *@par Outputs:
  479. *One outputs, including:
  480. * y: shape and dtype of output, should be same shape and type as input.
  481. */
  482. REG_OP(Renorm)
  483. .INPUT(x, TensorType::BasicType())
  484. .OUTPUT(y, TensorType::BasicType())
  485. .REQUIRED_ATTR(p, Float)
  486. .REQUIRED_ATTR(dim, Int)
  487. .REQUIRED_ATTR(maxnorm, Float)
  488. .OP_END_FACTORY_REG(Renorm)
  489. /**
  490. *@brief LayerNormGrad operator interface implementation
  491. * calculating: dy, x, variance, mean, gamma
  492. * pd_xl = data_dy*data_gamma
  493. * pd_var = np.sum(((-0.5)*pd_xl*(data_x - data_mean)
  494. * np.power((data_variance + EPSLON), (-1.5))),
  495. * reduce_axis, keepdims=True)
  496. * pd_mean = np.sum(((-1.0)*pd_xl
  497. * np.power((data_variance + EPSLON), (-0.5))),
  498. * reduce_axis, keepdims=True)
  499. * + pd_var*(1.0/m)
  500. * np.sum(((-2.0)*(data_x - data_mean)), reduce_axis, keepdims=True)
  501. * pd_x = pd_xl*np.power((data_variance + EPSLON), (-0.5)) +
  502. * pd_var*(2.0/m)*(data_x - data_mean) + pd_mean*(1.0/m)
  503. * pd_gamma = np.sum((data_dy*(data_x - data_mean)
  504. * np.power((data_variance + EPSLON), (-0.5))), param_axis, keepdims=True)
  505. * pd_beta = np.sum(data_dy, param_axis, keepdims=True)
  506. *@par Inputs:
  507. *Five inputs, including:
  508. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  509. * @li x: A Tensor. Must be one of the following types: float16, float32.
  510. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  511. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  512. * @li gamma: A Tensor. Must be one of the following types: float16, float32 . \n
  513. *@par Outputs:
  514. *Three outputs, including:
  515. * @li pd_x: A Tensor. Must be one of the following types: float16, float32.
  516. * @li pd_gamma: A Tensor. Must be one of the following types: float16, float32.
  517. * @li pd_beta: A Tensor. Must be one of the following types: float16, float32.
  518. *@par Restrictions:
  519. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  520. */
  521. REG_OP(LayerNormGrad)
  522. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  523. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  524. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  525. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  526. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  527. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  528. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  529. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  530. .OP_END_FACTORY_REG(LayerNormGrad)
  531. /**
  532. *@brief LayerNormXBackprop operator interface implementation
  533. * calculating: dy, x, variance, mean, gamma
  534. * pd_xl = data_dy*data_gamma
  535. * pd_var = np.sum(((-0.5)*pd_xl*(data_x - data_mean)
  536. * np.power((data_variance + EPSLON), (-1.5))),
  537. * reduce_axis, keepdims=True)
  538. * pd_mean = np.sum(((-1.0)*pd_xl
  539. * np.power((data_variance + EPSLON), (-0.5))),
  540. * reduce_axis, keepdims=True)
  541. * + pd_var*(1.0/m)
  542. * np.sum(((-2.0)*(data_x - data_mean)), reduce_axis, keepdims=True)
  543. * pd_x = pd_xl*np.power((data_variance + EPSLON), (-0.5)) +
  544. * pd_var*(2.0/m)*(data_x - data_mean) + pd_mean*(1.0/m)
  545. * pd_gamma = np.sum((data_dy*(data_x - data_mean)
  546. * np.power((data_variance + EPSLON), (-0.5))), param_axis, keepdims=True)
  547. * pd_beta = np.sum(data_dy, param_axis, keepdims=True)
  548. *@par Inputs:
  549. *Five inputs, including:
  550. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  551. * @li x: A Tensor. Must be one of the following types: float16, float32.
  552. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  553. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  554. * @li gamma: A Tensor. Must be one of the following types: float16, float32 . \n
  555. *@par Outputs:
  556. *Three outputs, including:
  557. * @li pd_x: A Tensor. Must be one of the following types: float16, float32.
  558. *@par Restrictions:
  559. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  560. */
  561. REG_OP(LayerNormXBackprop)
  562. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  563. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  564. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  565. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  566. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  567. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  568. .OP_END_FACTORY_REG(LayerNormXBackprop)
  569. /**
  570. *@brief LayerNormXBackpropV2 operator interface implementation
  571. * calculating: dy, x, variance, mean, gamma
  572. * pd_xl = data_dy*data_gamma
  573. * pd_var = np.sum(((-0.5)*pd_xl*(data_x - data_mean)
  574. * np.power((data_variance + EPSLON), (-1.5))),
  575. * reduce_axis, keepdims=True)
  576. * pd_mean = np.sum(((-1.0)*pd_xl
  577. * np.power((data_variance + EPSLON), (-0.5))),
  578. * reduce_axis, keepdims=True)
  579. * + pd_var*(1.0/m)
  580. * np.sum(((-2.0)*(data_x - data_mean)), reduce_axis, keepdims=True)
  581. * pd_x = pd_xl*np.power((data_variance + EPSLON), (-0.5)) +
  582. * pd_var*(2.0/m)*(data_x - data_mean) + pd_mean*(1.0/m)
  583. * res_for_gamma = (data_x - data_mean) * np.power((data_variance + EPSLON), (-0.5))
  584. *@par Inputs:
  585. *Five inputs, including:
  586. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  587. * @li x: A Tensor. Must be one of the following types: float16, float32.
  588. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  589. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  590. * @li gamma: A Tensor. Must be one of the following types: float16, float32 . \n
  591. *@par Outputs:
  592. *Three outputs, including:
  593. * @li pd_x: A Tensor. Must be one of the following types: float16, float32.
  594. * @li res_for_gamma: A Tensor. Must be one of the following types: float32.
  595. *@par Restrictions:
  596. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  597. */
  598. REG_OP(LayerNormXBackpropV2)
  599. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  600. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  601. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  602. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  603. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  604. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  605. .OUTPUT(res_for_gamma, TensorType({DT_FLOAT}))
  606. .OP_END_FACTORY_REG(LayerNormXBackpropV2)
  607. /**
  608. *@brief LayerNormBetaGammaBackprop operator interface implementation
  609. * calculating: dy, x, variance, mean
  610. * pd_xl = data_dy*data_gamma
  611. * pd_var = np.sum(((-0.5)*pd_xl*(data_x - data_mean)
  612. * np.power((data_variance + EPSLON), (-1.5))),
  613. * reduce_axis, keepdims=True)
  614. * pd_mean = np.sum(((-1.0)*pd_xl
  615. * np.power((data_variance + EPSLON), (-0.5))),
  616. * reduce_axis, keepdims=True)
  617. * + pd_var*(1.0/m)
  618. * np.sum(((-2.0)*(data_x - data_mean)), reduce_axis, keepdims=True)
  619. * pd_x = pd_xl*np.power((data_variance + EPSLON), (-0.5)) +
  620. * pd_var*(2.0/m)*(data_x - data_mean) + pd_mean*(1.0/m)
  621. * pd_gamma = np.sum((data_dy*(data_x - data_mean)
  622. * np.power((data_variance + EPSLON), (-0.5))), param_axis, keepdims=True)
  623. * pd_beta = np.sum(data_dy, param_axis, keepdims=True)
  624. *@par Inputs:
  625. *Three inputs, including:
  626. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  627. * @li x: A Tensor. Must be one of the following types: float16, float32.
  628. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  629. * @li mean: A Tensor. Must be one of the following types: float16, float32 . \n
  630. *@par Outputs:
  631. *Three outputs, including:
  632. * @li pd_gamma: A Tensor. Must be one of the following types: float16, float32.
  633. * @li pd_beta: A Tensor. Must be one of the following types: float16, float32.
  634. *@par Restrictions:
  635. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  636. */
  637. REG_OP(LayerNormBetaGammaBackprop)
  638. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  639. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  640. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  641. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  642. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  643. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  644. .REQUIRED_ATTR(shape_gamma, ListInt)
  645. .OP_END_FACTORY_REG(LayerNormBetaGammaBackprop)
  646. /**
  647. *@brief LayerNormBetaGammaBackpropV2 operator interface implementation
  648. * calculating: dy, x, variance, mean
  649. * pd_gamma = np.sum((data_dy*res_for_gamma), param_axis, keepdims=True)
  650. * pd_beta = np.sum(data_dy, param_axis, keepdims=True)
  651. *@par Inputs:
  652. *Three inputs, including:
  653. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  654. * @li x: A Tensor. Must be one of the following types: float16, float32.
  655. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  656. * @li mean: A Tensor. Must be one of the following types: float16, float32 . \n
  657. *@par Outputs:
  658. *Three outputs, including:
  659. * @li pd_gamma: A Tensor. Must be one of the following types: float16, float32.
  660. * @li pd_beta: A Tensor. Must be one of the following types: float16, float32.
  661. *@par Restrictions:
  662. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  663. */
  664. REG_OP(LayerNormBetaGammaBackpropV2)
  665. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  666. .INPUT(res_for_gamma, TensorType({DT_FLOAT}))
  667. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  668. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  669. .REQUIRED_ATTR(shape_gamma, ListInt)
  670. .OP_END_FACTORY_REG(LayerNormBetaGammaBackpropV2)
  671. /**
  672. * @brief LNDropoutGrad operator interface implementation
  673. * calculating: dy, x, variance, mean, gamma
  674. * pd_xl = dy*gamma
  675. * sub_x_mean = x - mean
  676. * var_elta_2 = np.power((variance + EPSLON), (-0.5))
  677. * pd_var = sum(pd_xl * sub_x_mean, reduce_axis, keepdims=True) * var_elta_2 * var_elta_2 * var_elta_2 * (-0.5)
  678. * pd_mean = sum(pd_xl, reduce_axis, keepdims=True) * var_elta_2 * (-1.0)
  679. * pd_x = pd_xl * var_elta_2 + pd_var * (2.0 / m) * sub_x_mean + pd_mean * (1.0 / m)
  680. * pd_x_dropout = pd_x * mask * (1 / keep_prob)
  681. * pd_gamma = sum(dy * sub_x_mean * var_elta_2, param_axis, keepdims=True)
  682. * pd_beta = sum(dy, param_axis, keepdims=True)
  683. * @par Inputs:
  684. * Six inputs, including:
  685. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  686. * @li x: A Tensor. Must be one of the following types: float16, float32.
  687. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  688. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  689. * @li gamma: A Tensor. Must be one of the following types: float16, float32.
  690. * @li mask: A Tensor. Must be one of the following types: uint8.\n
  691. * @par Outputs:
  692. * Four outputs, including:
  693. * @li pd_x: A Tensor. Must be one of the following types: float16, float32.
  694. * @li pd_x_dropout: A Tensor. Must be one of the following types: float16, float32.
  695. * @li pd_gamma: A Tensor. Must be one of the following types: float16, float32.
  696. * @li pd_beta: A Tensor. Must be one of the following types: float16, float32.
  697. * @par Restrictions:
  698. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  699. */
  700. REG_OP(LNDropoutGrad)
  701. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  702. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  703. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  704. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  705. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  706. .INPUT(mask, TensorType({DT_UINT8}))
  707. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  708. .OUTPUT(pd_x_dropout, TensorType({DT_FLOAT, DT_FLOAT16}))
  709. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  710. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  711. .REQUIRED_ATTR(keep_prob, Float)
  712. .OP_END_FACTORY_REG(LNDropoutGrad)
  713. /**
  714. *@brief Return "output" according to the algorithm of dropout_do_mask:
  715. * scale_x = x *(1 / keep_prob)
  716. * output = select(mask == 1, scale_x, 0)
  717. *@par Inputs:
  718. *Three inputs, including:
  719. * @li x: A mutable Tensor. Must be one of the following types:
  720. * float16, float32
  721. * @li mask: A mutable Tensor. Must met all of the following rules:
  722. * shape of mask should be 1D.
  723. * dtype of mask should be uint8.
  724. * value of shape should met the following algorithm:
  725. * value = (size(x) + 128 - 1) // 128 * 128 //8
  726. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  727. * shape of "keep_prob" should be (1,) or [1,].
  728. * Has the same type as "x" . \n
  729. *@par Outputs:
  730. *y: A mutable Tensor. Has the same type as "x".
  731. */
  732. REG_OP(DropOutDoMask)
  733. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  734. .INPUT(mask, TensorType({DT_UINT8}))
  735. .INPUT(keep_prob, TensorType({DT_FLOAT, DT_FLOAT16}))
  736. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  737. .OP_END_FACTORY_REG(DropOutDoMask)
  738. /**
  739. *@brief Return "output" according to the algorithm of dropout_do_mask:
  740. * scale_x = x *(1 / keep_prob)
  741. * output = select(mask == 1, scale_x, 0)
  742. *@par Inputs:
  743. *Three inputs, including:
  744. * @li x: A mutable Tensor. Must be one of the following types:
  745. * float16, float32
  746. * @li mask: A mutable Tensor. Must met all of the following rules:
  747. * shape of mask should be 1D.
  748. * dtype of mask should be uint8.
  749. * value of shape should met the following algorithm:
  750. * value = (size(x) + 128 - 1) // 128 * 128
  751. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  752. * shape of "keep_prob" should be (1,) or [1,].
  753. * Has the same type as "x" . \n
  754. *@par Outputs:
  755. *y: A mutable Tensor. Has the same type as "x".
  756. *@par Restrictions:
  757. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  758. */
  759. REG_OP(DropOutDoMaskV3)
  760. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  761. .INPUT(mask, TensorType({DT_UINT8}))
  762. .INPUT(keep_prob, TensorType({DT_FLOAT, DT_FLOAT16}))
  763. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  764. .OP_END_FACTORY_REG(DropOutDoMaskV3)
  765. /**
  766. *@brief Return "output" according to the algorithm of dropout_do_mask:
  767. * scale_x = x *(1 / keep_prob)
  768. * output = select(mask == 1, scale_x, 0)
  769. *@par Inputs:
  770. *Two inputs, including:
  771. * @li x: A mutable Tensor. Must be one of the following types:
  772. * float16, float32
  773. * @li mask: A mutable Tensor. Must met all of the following rules:
  774. * shape of mask should be 1D.
  775. * dtype of mask should be uint8.
  776. * value of shape should met the following algorithm:
  777. * value = (size(x) + 128 - 1) // 128 * 128
  778. *@par Attributes:
  779. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  780. * shape of "keep_prob" should be (1,) or [1,].
  781. * Has the same type as "x" . \n
  782. *@par Output:
  783. *y: A mutable Tensor. Has the same type as "x".
  784. *@par Restrictions:
  785. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  786. */
  787. REG_OP(DropOutDoMaskV3D)
  788. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  789. .INPUT(mask, TensorType({DT_UINT8}))
  790. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  791. .REQUIRED_ATTR(keep_prob, Float)
  792. .OP_END_FACTORY_REG(DropOutDoMaskV3D)
  793. /**
  794. *@brief Scales the input . \n
  795. *@par Inputs:
  796. * Three inputs, including:
  797. *@li x: An ND tensor of type float16 or float32.
  798. *@li scale: An ND tensor of type float16 or float32.
  799. *@li bias: An optional ND tensor of type float16 or float32 . \n
  800. *@par Attributes:
  801. *@li axis: An optional int32 used to compute the shape of scale and bias input from the online bottoms. Defaults to "1".
  802. *@li num_axes: An optional int32 used to compute the shape of scale and bias input from a Caffe model trained offline. Defaults to "1".
  803. *@li scale_from_blob: An optional bool. If "true", scale and bias are input from a Caffe model trained offline. If "false", scale and bias are input from online bottoms. Defaults to "true" . \n
  804. *@par Outputs:
  805. *y: An ND tensor of type float16 or float32 . \n
  806. *@attention Constraints:
  807. * Assume that the shape length of "x" is "n" and that of "scale" is "m".
  808. *@li "axis" is within the range [-n, n-1]. num_axes >= -1.
  809. *@li If "scale_from_blob = true", "num_axes = -1", and "axis >= 0", the ith axis of "scale" and the (i+"axis")th axis of "x" must have the same size (0 <= i < n-axis).
  810. * If "axis < 0", the ith axis of "scale" and the (i+n+"axis")th axis of "x" must have the same size (0 <= i < -axis).
  811. *@li If "scale_from_blob = true" and "num_axes = 0", "scale" is a scalar with shape length 1 and dimension size 1.
  812. *@li If "scale_from_blob = true", "num_axes > 0, and "axis >= 0", "axis + num_axes" must be less than or equal to "n" and the ith axis of "scale" and the (i+"axis")th axis of "x" must have the same size (0 <= i < num_axes).
  813. * If "axis < 0", "n + axis + num_axes" must be less than or equal to "n" and the ith axis of "scale" and the (i+n+"axis")th axis of "x" must have the same size (0 <= i < num_axes).
  814. *@li If "scale_from_blob = false", "scale" is not a scalar, and "axis >= 0","axis + m" must be less than or equal to "n" and the ith axis of "scale" and the (i+"axis")th axis of "x" must have the same size (0 <= i < m).
  815. * If "axis < 0", "n + axis + m" must be less than or equal to "n" and the ith axis of "scale" and the (i+n+"axis")th axis of "x" must have the same size (0 <= i < m).
  816. *@li If "bias" is not None, the constraints for "bias" is the same as that for "scale".
  817. *@par Third-party framework compatibility
  818. * Compatible with the Caffe operator Scale.
  819. */
  820. REG_OP(Scale)
  821. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16})) /* "First operand." */
  822. .INPUT(scale, TensorType({DT_FLOAT, DT_FLOAT16})) /* "Second operand." */
  823. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16})) /* "Third operand." */
  824. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16})) /* "Result, has same element type as x" */
  825. .ATTR(axis, Int, 1)
  826. .ATTR(num_axes, Int, 1)
  827. .ATTR(scale_from_blob, Bool, true)
  828. .OP_END_FACTORY_REG(Scale)
  829. /**
  830. *@brief Local Response Normalization . \n
  831. *@par Inputs:
  832. *One input, including:
  833. *x: A Tensor. Must be 4-D shape, and only support the following types: float16, float32 . \n
  834. *@par Attributes:
  835. *@li depth_radius: An optional int32, specifying the half-width of the normalization window. Defaults to "5".
  836. * under the caffe framework, if local_size is provided and is an odd number,
  837. * depth_radius = (local_size - 1) / 2. local_size is the number of channels to sum over (for ACROSS_CHANNELS)
  838. * or the side length of the square region to sum over (for WITHIN_CHANNEL).
  839. *@li bias: An optional float32. An offset, usually > 0 to avoid dividing by 0.
  840. * Defaults to "1.0".
  841. *@li alpha: An optional float32. A scaling factor, usually positive.
  842. * Defaults to "1.0".
  843. *@li beta: An optional float32. An exponent. Defaults to "0.75" for the caffe framework, Defaults to "0.5" for others.
  844. *@li norm_region: An optional string. A mode option. "ACROSS_CHANNELS":0. Defaults to "ACROSS_CHANNELS" . \n
  845. *@par Outputs:
  846. *y: A Tensor. Has the same data type and shape as "x" . \n
  847. *@par Third-party framework compatibility:
  848. * Compatible with the TensorFlow operator LRN.
  849. */
  850. REG_OP(LRN)
  851. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  852. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  853. .ATTR(depth_radius, Int, 5)
  854. .ATTR(bias, Float, 1.0)
  855. .ATTR(alpha, Float, 1.0)
  856. .ATTR(beta, Float, 0.5)
  857. .ATTR(norm_region, String, "ACROSS_CHANNELS")
  858. .OP_END_FACTORY_REG(LRN)
  859. /**
  860. * @brief Computes the gradient for Local Response Normalization . \n
  861. * @par Inputs:
  862. * @li grads: A 4D Tensor of type float16 or float32.
  863. * @li x: A 4D Tensor of type float16 or float32.
  864. * @li y: A 4D Tensor of type float16 or float32 . \n
  865. * @par Attributes:
  866. * @li depth_radius: An optional int, specifying the half-width of the
  867. * normalization window. Defaults to "5".
  868. * @li bias: An optional float32. An offset, usually > 0 to avoid dividing by 0.
  869. * Defaults to "1".
  870. * @li alpha: An optional float32. A scaling factor, usually positive.
  871. * Defaults to "1".
  872. * @li beta: An optional float32. An exponent. Defaults to "0.5" . \n
  873. * @par Outputs:
  874. * z: A Tensor. Has the same type and shape as "grads" . \n
  875. * @attention Constraints:
  876. * "x" and "y" must have the same shape and type as "grads" . \n
  877. * @par Third-party framework compatibility
  878. * Compatible with the TensorFlow operator LRNGrad.
  879. */
  880. REG_OP(LRNGrad)
  881. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  882. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  883. .INPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  884. .OUTPUT(z, TensorType({DT_FLOAT16,DT_FLOAT}))
  885. .ATTR(depth_radius, Int, 5)
  886. .ATTR(bias, Float, 1.0)
  887. .ATTR(alpha, Float, 1.0)
  888. .ATTR(beta, Float, 0.5)
  889. .OP_END_FACTORY_REG(LRNGrad)
  890. /**
  891. *@brief Calculates the RNNT Loss (log probability) for each batch entry.
  892. Also calculates the gradient.
  893. *@par Inputs:
  894. *@li acts: 4-D, shape: `(batch x seqLength x labelLength x outputDim)`, the logits.
  895. *@li labels: 2-D Tensor containing all the targets of the batch with zero padded.
  896. *@li input_lengths: Tensor of size (batch) containing size of each output sequence.
  897. *@li label_lengths: Tensor of (batch) containing label length of each example.
  898. *@par Outputs:
  899. *@li costs: 1-D Tensor, the cost of each example in the batch.
  900. *@li grads: A Tensor. Has the same type as acts.
  901. *@par Attributes:
  902. *blank_label: An optional attribute. Defaults to 0.
  903. *@par Third-party framework compatibility
  904. * Compatible with TensorFlow RNNTLoss operator.
  905. */
  906. REG_OP(RNNTLoss)
  907. .INPUT(acts, TensorType({DT_FLOAT}))
  908. .INPUT(labels, TensorType({DT_INT32}))
  909. .INPUT(input_lengths, TensorType({DT_INT32}))
  910. .INPUT(label_lengths, TensorType({DT_INT32}))
  911. .ATTR(blank_label, Int, 0)
  912. .OUTPUT(costs, TensorType({DT_FLOAT}))
  913. .OUTPUT(grads, TensorType({DT_FLOAT}))
  914. .OP_END_FACTORY_REG(RNNTLoss)
  915. /**
  916. * @brief Performs group normalization . \n
  917. * @par Inputs:
  918. * Three inputs
  919. * @li x: A ND Tensor of type float16 or float32, with format NCHW for 4D.
  920. * @li gamma: A Tensor of type float16 or float32. Must be 1D. Specifies the scaling factor.
  921. * @li beta: A Tensor of type float16 or float32. Must be 1D. Specifies the offset. \n
  922. * @par Attributes:
  923. * @li num_groups: An required int32, specifying the number of group.
  924. * @li eps: An optional float32, specifying the small value added to
  925. variance to avoid dividing by zero. Defaults to "0.0001".
  926. * @li data_format: An optional string, specifying the format of "x".
  927. Defaults to "NHWC".
  928. * @li is_training: An optional bool, specifying if the operation is used for
  929. training or inference. Defaults to "True" . \n
  930. * @par Outputs:
  931. * Three outputs
  932. * @li y: A ND Tensor of type float16 or float32 for the normalized "x",
  933. with format NCHW for 4D.
  934. * @li mean: A Tensor of type float16 or float32. Must be 1D. Specifies the mean of "x".
  935. * @li variance: A Tensor of type float16 or float32. Must be 1D. Specifies the variance of "x". \n
  936. * @attention Constraints:
  937. * @li For Ascend 310, only support NCHW which can be trans to 5HD. \n
  938. * @par Third-party framework compatibility
  939. * @li Compatible with the PyTorch operator GroupNorm.
  940. */
  941. REG_OP(GroupNorm)
  942. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  943. .INPUT(gamma, TensorType({DT_FLOAT16, DT_FLOAT}))
  944. .INPUT(beta, TensorType({DT_FLOAT16, DT_FLOAT}))
  945. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  946. .OUTPUT(mean, TensorType({DT_FLOAT16, DT_FLOAT}))
  947. .OUTPUT(variance, TensorType({DT_FLOAT16, DT_FLOAT}))
  948. .REQUIRED_ATTR(num_groups, Int)
  949. .ATTR(data_format, String, "NHWC")
  950. .ATTR(eps, Float, 0.0001)
  951. .ATTR(is_training, Bool, true)
  952. .OP_END_FACTORY_REG(GroupNorm)
  953. /**
  954. *@brief Performs instance normalization . \n
  955. *@par Inputs:
  956. * Five inputs, including:
  957. *@li x: A 5D Tensor of type float16 or float32.
  958. *@li gamma: A Tensor of type float32.
  959. A 5D Tensor for scaling factor, to scale the normalized x.
  960. *@li beta: A Tensor of type float32.
  961. A 5D Tensor for offset, to shift to the normalized x.
  962. *@li mean: A Tensor of type float32.
  963. A 5D Tensor Specifies the mean used for inference. Reserved.
  964. *@li variance: A Tensor of type float32.
  965. A 5D Tensor Specifies the variance used for inference. Reserved . \n
  966. *@par Attributes:
  967. *@li is_training: An optional bool, specifying if the operation is used for
  968. training or inference. Defaults to "True".
  969. *@li momentum: An optional float32,
  970. the value used for the running_mean and running_var computation. Default: "0.1".
  971. *@li epsilon: An optional float32, specifying the small value added to
  972. variance to avoid dividing by zero. Defaults to "0.00001" . \n
  973. *@par Outputs:
  974. * Three outputs, including: (NHWC, NCHW supported)
  975. *@li y: A 5D tensor of type float16 or float32 for the normalized "x",
  976. *@li batch_mean: A Tensor of type float32.
  977. Specifies the mean of "x".
  978. *@li batch_variance: A Tensor of type float32.
  979. Specifies the variance of "x" . \n
  980. *@par Third-party framework compatibility
  981. *@li Compatible with the PyTorch operator InstanceNorm.
  982. *@par Restrictions:
  983. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  984. */
  985. REG_OP(InstanceNormV2)
  986. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  987. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  988. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  989. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  990. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  991. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  992. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  993. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  994. .ATTR(is_training, Bool, true)
  995. .ATTR(momentum, Float, 0.1)
  996. .ATTR(epsilon, Float, 0.00001)
  997. .OP_END_FACTORY_REG(InstanceNormV2)
  998. /**
  999. *@brief Performs instance normalization for inference.
  1000. *@par Inputs:\n
  1001. * Five inputs, including:
  1002. *@li x: A Tensor of type float16 or float32.
  1003. *@li gamma: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling gamma.
  1004. *@li beta: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling beta.
  1005. *@li mean: A [N, C1, 1, 1, C0] ensor of type float32, for the mean.
  1006. *@li variance: A [N, C1, 1, 1, C0] Tensor of type float32, for the variance.
  1007. *@li variance_sqrt: A [N, C1, 1, 1, C0] Tensor of type float32, for the variance_sqrt.
  1008. *@par Outputs:\n
  1009. *y: A Tensor of type float16 or float32 for the normalized "x".
  1010. *batch_mean: A Tensor of type float32 for the result mean.
  1011. *batch_ variance: A Tensor of type float32 for the result variance.
  1012. *@attention Constraints:
  1013. *For Ascend 310, the result accuracy fails to reach 1<89> due to the square root instruction.
  1014. * @par Restrictions:
  1015. * Warning: THIS FUNCTION IS DEPRECATED. Please use INInferV2 instead.
  1016. */
  1017. REG_OP(INInferV2D)
  1018. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1019. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  1020. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  1021. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  1022. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  1023. .OPTIONAL_INPUT(variance_sqrt, TensorType({DT_FLOAT}))
  1024. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1025. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  1026. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  1027. .OP_END_FACTORY_REG(INInferV2D)
  1028. /**
  1029. * @brief InstanceNorm operator interface implementation.
  1030. * @par Inputs:
  1031. * Three inputs, including:
  1032. * @li x: A Tensor. Must be one of the following types: float16, float32.
  1033. * @li gamma: A Tensor. Must be one of the following types: float16, float32.
  1034. * @li beta: A Tensor. Must be one of the following types: float16, float32.
  1035. * @par Attributes:
  1036. * @li data_format: An attribute of type String \n
  1037. * @li epsilon: An attribute of type Float. \n
  1038. * @par Outputs:
  1039. * Three outputs, including:
  1040. * @li y: A Tensor. Has the same type as "x". \n
  1041. * @li mean: A Tensor. Has the same type as "x". \n
  1042. * @li variance: A Tensor. Has the same type as "x". \n
  1043. */
  1044. REG_OP(InstanceNorm)
  1045. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1046. .INPUT(gamma, TensorType({DT_FLOAT16, DT_FLOAT}))
  1047. .INPUT(beta, TensorType({DT_FLOAT16, DT_FLOAT}))
  1048. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1049. .OUTPUT(mean, TensorType({DT_FLOAT16, DT_FLOAT}))
  1050. .OUTPUT(variance, TensorType({DT_FLOAT16, DT_FLOAT}))
  1051. .ATTR(data_format, String, "NDHWC")
  1052. .ATTR(epsilon, Float, 1e-6)
  1053. .OP_END_FACTORY_REG(InstanceNorm)
  1054. /**
  1055. * @brief InstanceNormGrad operator interface implementation.
  1056. * @par Inputs:
  1057. * Five inputs, including:
  1058. * @li dy: A Tensor. Must be one of the following types: float16, float32.
  1059. * @li x: A Tensor. Must be one of the following types: float16, float32.
  1060. * @li variance: A Tensor. Must be one of the following types: float16, float32.
  1061. * @li mean: A Tensor. Must be one of the following types: float16, float32.
  1062. * @li gamma: A Tensor. Must be one of the following types: float16, float32 . \n
  1063. * @par Outputs:
  1064. * Three outputs, including:
  1065. * @li pd_x: A Tensor. Must be one of the following types: float16, float32.
  1066. * @li pd_gamma: A Tensor. Must be one of the following types: float16, float32.
  1067. * @li pd_beta: A Tensor. Must be one of the following types: float16, float32.
  1068. */
  1069. REG_OP(InstanceNormGrad)
  1070. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  1071. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1072. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  1073. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  1074. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  1075. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1076. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  1077. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  1078. .OP_END_FACTORY_REG(InstanceNormGrad)
  1079. /**
  1080. * @brief Computes Kl_div_loss_grad or Kl_div_loss_backward. \n
  1081. * @par Inputs:
  1082. * Three inputs, including:
  1083. * @li grad: A Tensor. Must be one of the following types: float16, float32.
  1084. * Required.
  1085. * @li input: A Tensor. Has the same type as "grad". Required.
  1086. * @li target: A Tensor. Has the same type as "grad". Required. \n
  1087. * @par Attributes:
  1088. * @li reduction: An optional attribute of type String. Defaults to "mean". \n
  1089. * @li log_target: An optional attribute of type Bool. Defaults to false. \n
  1090. * @par Outputs:
  1091. * @li y: A Tensor. Has the same type as "grad". \n
  1092. * @par Third-party framework compatibility
  1093. * Compatible with the Pytorch operator KlDivLossGrad.
  1094. */
  1095. REG_OP(KlDivLossGrad)
  1096. .INPUT(grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  1097. .INPUT(input, TensorType({DT_FLOAT16, DT_FLOAT}))
  1098. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  1099. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1100. .ATTR(reduction, String, "mean")
  1101. .ATTR(log_target, Bool, false)
  1102. .OP_END_FACTORY_REG(KlDivLossGrad)
  1103. /**
  1104. * @brief Computes l1_loss_grad or l1_loss_backward. \n
  1105. * @par Inputs:
  1106. * Three inputs, including:
  1107. * @li grads: A Tensor. Must be one of the following types: float16, float32.
  1108. * Required.
  1109. * @li predict: A Tensor. Has the same type as "grads". Required.
  1110. * @li label: A Tensor. Has the same type as "grads". Required. \n
  1111. * @par Attributes:
  1112. * reduction: An optional attribute of type String. Defaults to "mean". \n
  1113. * @par Outputs:
  1114. * y: A Tensor. Has the same type as "x". \n
  1115. * @par Third-party framework compatibility
  1116. * Compatible with the Pytorch operator L1LossGrad.
  1117. */
  1118. REG_OP(L1LossGrad)
  1119. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  1120. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  1121. .INPUT(label, TensorType({DT_FLOAT16, DT_FLOAT}))
  1122. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1123. .ATTR(reduction, String, "mean")
  1124. .OP_END_FACTORY_REG(L1LossGrad)
  1125. /**
  1126. * @brief Computes loss of lp, p=1,2,3....
  1127. * @par Inputs:
  1128. * @li predict: An ND tensor of type float16, float32.
  1129. * @li label: An ND tensor of type float16, float32. \n
  1130. * @par Attributes:
  1131. * @li p: A required int attribute that decides which loss to compute, now the p only can be 1 to compute l1_loss.
  1132. * @li reduction: An optional string.Defaults to "mean". \n
  1133. * @par Outputs:
  1134. * y: An ND tensor tensor with the same shape and type as "predict". \n
  1135. * @par Third-party framework compatibility
  1136. * Compatible with the Pytorch operator LpLoss.
  1137. */
  1138. REG_OP(LpLoss)
  1139. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  1140. .INPUT(label, TensorType({DT_FLOAT16, DT_FLOAT}))
  1141. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1142. .REQUIRED_ATTR(p, Int)
  1143. .ATTR(reduction, String, "mean")
  1144. .OP_END_FACTORY_REG(LpLoss)
  1145. /**
  1146. * @brief Computes gradients of mse loss.
  1147. * @par Inputs:
  1148. * @li predict: An ND tensor of type float16, float32.
  1149. * @li label: An ND tensor of type float16, float32.
  1150. * @li dout: An ND tensor of type float16, float32. \n
  1151. * @par Attributes:
  1152. * reduction: An optional string.Defaults to "mean". \n
  1153. * @par Outputs:
  1154. * y: An ND tensor tensor with the same shape and type as "predict". \n
  1155. * @par Third-party framework compatibility
  1156. * Compatible with the Pytorch operator MseLossGrad.
  1157. */
  1158. REG_OP(MseLossGrad)
  1159. .INPUT(predict, TensorType({DT_FLOAT32, DT_FLOAT16}))
  1160. .INPUT(label, TensorType({DT_FLOAT32, DT_FLOAT16}))
  1161. .INPUT(dout, TensorType({DT_FLOAT32, DT_FLOAT16}))
  1162. .OUTPUT(y, TensorType({DT_FLOAT32, DT_FLOAT16}))
  1163. .ATTR(reduction, String, "mean")
  1164. .OP_END_FACTORY_REG(MseLossGrad)
  1165. /**
  1166. * @brief Computes mse loss.
  1167. * @par Inputs:
  1168. * two inputs, including:
  1169. * @li predict: An ND Tensor of dtype float16 or float32.
  1170. * @li label: An ND Tensor of dtype float16 or float32.\n
  1171. *
  1172. * @par Attributes:
  1173. * reduction:An optional str from sum, none, mean, Defaults to "mean".\n
  1174. *
  1175. * @par Outputs:
  1176. * y: when reduction=sum/mean, y is scale. when reduction=none, y has
  1177. * same type and shape as "predict".\n
  1178. */
  1179. REG_OP(MseLoss)
  1180. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  1181. .INPUT(label, TensorType({DT_FLOAT16, DT_FLOAT}))
  1182. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1183. .ATTR(reduction, String, "mean")
  1184. .OP_END_FACTORY_REG(MseLoss)
  1185. /**
  1186. * @brief Calculates the reversed outputs of the function "smooth_l1_loss_v2". \n
  1187. * @par Inputs:
  1188. * Three Inputs, including:
  1189. * @li predict: A Tensor. Must be one of the following types:
  1190. * float16, float32.
  1191. * @li label: A Tensor. Has the same type as "predict".
  1192. * @li dout: A Tensor. Has the same type as "predict". \n
  1193. * @par Attributes:
  1194. * Two Attributes, including:
  1195. * @li sigma: An optional float. Defaults to 1.0. \n
  1196. * @li reduction: An optional string. Defaults to "mean",
  1197. * Must be one of the following: "none", "mean", "sum". \n
  1198. * @par Outputs:
  1199. * gradient: A Tensor. Has the same type as "predict". \n
  1200. * @par Third-party framework compatibility
  1201. * Compatible with the Pytorch operator SmoothL1LossBackward.
  1202. */
  1203. REG_OP(SmoothL1LossGradV2)
  1204. .INPUT(predict, TensorType({DT_FLOAT, DT_FLOAT16}))
  1205. .INPUT(label, TensorType({DT_FLOAT, DT_FLOAT16}))
  1206. .INPUT(dout, TensorType({DT_FLOAT, DT_FLOAT16}))
  1207. .OUTPUT(gradient, TensorType({DT_FLOAT, DT_FLOAT16}))
  1208. .ATTR(sigma, Float, 1.0)
  1209. .ATTR(reduction, String, "mean")
  1210. .OP_END_FACTORY_REG(SmoothL1LossGradV2)
  1211. /**
  1212. * @brief Creates a criterion that uses a squared term if the absolute
  1213. * element-wise error falls below beta and an L1 term otherwise. It is
  1214. * less sensitive to outliers than the MSELoss and in some cases prevents
  1215. * exploding gradients.
  1216. * @par Inputs:
  1217. * @li predict: A multi-dimensional Tensor of type float16 or float32,
  1218. * specifying the predictive value. \n
  1219. * @li label: A multi-dimensional Tensor of type float16 or float32,
  1220. * specifying the target value. \n
  1221. * @par Attributes:
  1222. * @li sigma: An optional int. Specifies the threshold of loss. Defaults
  1223. * to "1.0". \n
  1224. * @li reduction: An optional str. Specifies the reduction to apply to
  1225. * the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied,
  1226. * 'mean': the sum of the output will be divided by the number of elements in
  1227. * the output,'sum': the output will be summed. Default: 'mean'. \n
  1228. * @par Outputs:
  1229. * loss: Indicates the loss between the predictive value and target value.
  1230. * Has the same dimensions as "predict". \n
  1231. * @par Third-party framework compatibility
  1232. * Compatible with the Pytorch operator smooth_l1_loss. \n
  1233. */
  1234. REG_OP(SmoothL1LossV2)
  1235. .INPUT(predict, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  1236. .INPUT(label, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  1237. .OUTPUT(loss, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  1238. .ATTR(sigma, Float, 1.0)
  1239. .ATTR(reduction, String, "mean")
  1240. .OP_END_FACTORY_REG(SmoothL1LossV2)
  1241. /**
  1242. * @brief Computes Centralization. result = x - mean(x, axes)
  1243. * @par Inputs:
  1244. * x: An ND tensor of type float16, float32.
  1245. * @par Attributes:
  1246. * axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.
  1247. * Must be in the range [-rank(x), rank(x)).
  1248. * @par Outputs:
  1249. * y: A Tensor. Has the same type as "x". \n
  1250. * @par Third-party framework compatibility
  1251. * custom operator \n
  1252. */
  1253. REG_OP(Centralization)
  1254. .INPUT(x, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  1255. .OUTPUT(y, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  1256. .ATTR(axes, ListInt, {-1})
  1257. .OP_END_FACTORY_REG(Centralization)
  1258. /**
  1259. *@brief Roll the tensor along the given dimension(s).
  1260. * Elements that are shifted beyond the last position are re-introduced at the first position.
  1261. * If a dimension is not specified, the tensor will be flattened before rolling and then restored to the original shape. \n
  1262. *@par Inputs:
  1263. *One inputs, including:
  1264. * x: A tensor . Must be one of the following types:
  1265. * float16, float32, int32, uint32, int8, uint8. \n
  1266. *@par Attributes:
  1267. * @li shifts: The number of places by which the elements of the tensor are shifted. \n
  1268. * @li dims: Axis along which to roll. \n
  1269. *@par Outputs:
  1270. * y: A Tensor with the same type and shape of x's. \n
  1271. *@par Third-party framework compatibility
  1272. *Compatible with the Pytorch operator Roll. \n
  1273. */
  1274. REG_OP(Roll)
  1275. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_UINT32,DT_INT8,DT_UINT8}))
  1276. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_UINT32,DT_INT8,DT_UINT8}))
  1277. .REQUIRED_ATTR(shifts, ListInt)
  1278. .ATTR(dims, ListInt, {})
  1279. .OP_END_FACTORY_REG(Roll)
  1280. /**
  1281. * @brief Roll the tensor along the given dimension(s).
  1282. * @par Inputs:
  1283. * One inputs, including:
  1284. * x: A tensor
  1285. * @par Attributes:
  1286. * @li shift: The number of places by which the elements of the tensor are shifted. \n
  1287. * @li axes: Axis along which to roll. \n
  1288. * @par Outputs:
  1289. * y: A Tensor with the same type and shape of x's. \n
  1290. * @par Third-party framework compatibility
  1291. * Compatible with the Pytorch operator Roll. \n
  1292. */
  1293. REG_OP(RollV2)
  1294. .INPUT(input, TensorType({DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_INT64,DT_FLOAT16, \
  1295. DT_FLOAT,DT_DOUBLE}))
  1296. .INPUT(shift, TensorType({DT_INT32,DT_INT64}))
  1297. .INPUT(axes, TensorType({DT_INT32,DT_INT64}))
  1298. .OUTPUT(output, TensorType({DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_INT64,DT_FLOAT16, \
  1299. DT_FLOAT,DT_DOUBLE}))
  1300. .OP_END_FACTORY_REG(RollV2)
  1301. /**
  1302. * @brief Calculate the loss. Creates a criterion that optimizes a two-class classification
  1303. * logistic loss between input_x and input_y (containing 1 or -1). \n
  1304. * @par Inputs:
  1305. * Tow inputs, including:
  1306. * @li input_x: A tensor. Must be one of the following types:
  1307. * float16, float32. \n
  1308. * @li input_y: A tensor. Must be one of the following types:
  1309. * float16, float32. \n
  1310. * @par Attributes:
  1311. * reduction: An optional string.Defaults to "mean". \n
  1312. * @par Outputs:
  1313. * output_z: while reduction == "none", A Tensor with the same type and shape of input_x's. \n
  1314. * while reduction == "sum" or "mean", A Tensor with the same type of input_x , shape of which is (1,)
  1315. * @par Third-party framework compatibility
  1316. * Compatible with the Pytorch operator SoftMarginLoss. \n
  1317. */
  1318. REG_OP(SoftMarginLoss)
  1319. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1320. .INPUT(input_y, TensorType({DT_FLOAT, DT_FLOAT16}))
  1321. .ATTR(reduction, String, "mean")
  1322. .OUTPUT(output_z, TensorType({DT_FLOAT, DT_FLOAT16}))
  1323. .OP_END_FACTORY_REG(SoftMarginLoss)
  1324. /**
  1325. * @brief Computes gradients of sigmoid_cross_entropy_with_logits_v2.
  1326. * @par Inputs:
  1327. * @li predict: An ND tensor of type float16, float32.
  1328. * @li target: An ND tensor of type float16, float32.
  1329. * @li dout: An ND tensor of type float16, float32.
  1330. * @li weight: An optional ND tensor of type float16, float32.
  1331. * @li pos_weight: An optional ND tensor of type float16, float32. \n
  1332. * @par Attributes:
  1333. * reduction: An optional string.Defaults to "mean". \n
  1334. * @par Outputs:
  1335. * gradient: An ND tensor tensor with the same shape and type as "predict". \n
  1336. * @par Third-party framework compatibility
  1337. * Compatible with the Pytorch operator SigmoidCrossEntropyWithLogitsGrad.
  1338. */
  1339. REG_OP(SigmoidCrossEntropyWithLogitsGradV2)
  1340. .INPUT(predict, TensorType({DT_FLOAT16, DT_FLOAT}))
  1341. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  1342. .INPUT(dout, TensorType({DT_FLOAT16, DT_FLOAT}))
  1343. .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT16, DT_FLOAT}))
  1344. .OPTIONAL_INPUT(pos_weight, TensorType({DT_FLOAT16, DT_FLOAT}))
  1345. .OUTPUT(gradient, TensorType({DT_FLOAT16, DT_FLOAT}))
  1346. .ATTR(reduction, String, "mean")
  1347. .OP_END_FACTORY_REG(SigmoidCrossEntropyWithLogitsGradV2)
  1348. /**
  1349. * @brief Calculate the PoissonNllLoss function.
  1350. * target∼Poisson(input)loss(input,target)=input−target∗log(input)+log(target!) \n
  1351. * @par Inputs:
  1352. * Two inputs, including:
  1353. * @li input_x: A tensor. Must be one of the following types: float16, float32.
  1354. * @li target: A tensor. Must be one of the following types: float16, float32. \n
  1355. * @par Attributes:
  1356. * four Attributes, including:
  1357. * @li log_input: An optional bool. Defaults to "True"
  1358. * @li full: An optional bool. Defaults to "False"
  1359. * @li eps: An optional float. Defaults to "1e-8"
  1360. * @li reduction: An optional string. Defaults to "mean" \n
  1361. * @par Outputs:
  1362. * loss: A Tensor has same element type as two inputs. \n
  1363. * @par Third-party framework compatibility
  1364. * Compatible with the Pytorch operator PoissonNllLoss. \n
  1365. */
  1366. REG_OP(PoissonNllLoss)
  1367. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1368. .INPUT(target, TensorType({DT_FLOAT16, DT_FLOAT}))
  1369. .OUTPUT(loss, TensorType({DT_FLOAT16, DT_FLOAT}))
  1370. .ATTR(log_input, Bool, true)
  1371. .ATTR(full, Bool, false)
  1372. .ATTR(eps, Float, 1e-8)
  1373. .ATTR(reduction, String, "mean")
  1374. .OP_END_FACTORY_REG(PoissonNllLoss)
  1375. /**
  1376. *@brief rnn_gen_mask
  1377. * @par Inputs:
  1378. * seq_length: A ND Tensor of type int32. Recoed the current length of each batch.\n
  1379. *
  1380. * @par Attributes:
  1381. * @li num_step: A required int.\n
  1382. * @li hidden_size: A required int. \n
  1383. *
  1384. *
  1385. * @par Ouputs:
  1386. * y: A mutable Tensor of type float16, with the shape of [num_step, batch_size, hidden_size]. \n
  1387. *
  1388. */
  1389. REG_OP(RnnGenMask)
  1390. .INPUT(seq_length, TensorType({DT_INT32}))
  1391. .OUTPUT(seq_mask, TensorType({DT_FLOAT16}))
  1392. .REQUIRED_ATTR(num_step, Int)
  1393. .REQUIRED_ATTR(hidden_size, Int)
  1394. .OP_END_FACTORY_REG(RnnGenMask)
  1395. /**
  1396. * @brief Creates a criterion that optimizes a multi-class multi-classification hinge loss (margin-based loss)
  1397. * between input x (a 2D mini-batch Tensor) and output y (which is a 2D Tensor of target class indices) \n
  1398. * @par Inputs:
  1399. * Two inputs, including:
  1400. * @li x: A tensor. Must be one of the following types:
  1401. * float16, float32.
  1402. * @li target: A tensor. Must be the following types:
  1403. * int32. \n
  1404. * @par Attributes:
  1405. * reduction: An optional string. Defaults to "mean" \n
  1406. * @par Outputs:
  1407. * @li y: A Tensor has same element type as input x. \n
  1408. * @li is_target: A Tensor has same element type as input target. \n
  1409. * @par Third-party framework compatibility
  1410. * Compatible with the Pytorch operator MultiLabelMarginLoss. \n
  1411. */
  1412. REG_OP(MultilabelMarginLoss)
  1413. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1414. .INPUT(target, TensorType({DT_INT32}))
  1415. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  1416. .OUTPUT(is_target, TensorType({DT_INT32}))
  1417. .ATTR(reduction, String, "mean")
  1418. .OP_END_FACTORY_REG(MultilabelMarginLoss)
  1419. /**
  1420. * @brief Performs batch normalization . \n
  1421. * @par Inputs:
  1422. * Two inputs
  1423. * @li input_x: A Tensor. Support float32. shape (n, c, d).
  1424. * @li seq_len: A Tensor. Each batch normalize data num. Support Int32. Shape (n, ). \n
  1425. * @par Attributes:
  1426. * @li normalize_type: Str. Support "per_feature" or "all_features".
  1427. * @li epsilon: An optional float32, specifying the small value added to
  1428. * variance to avoid dividing by zero. Defaults to "0.00001" . \n
  1429. * @par Outputs:
  1430. * One outputs
  1431. * @li output_y: A Tensor for the normalized "x".Support float32. shape (n, c, d).\n
  1432. */
  1433. REG_OP(NormalizeBatch)
  1434. .INPUT(input_x, TensorType({ DT_FLOAT }))
  1435. .INPUT(seq_len, TensorType({ DT_INT32 }))
  1436. .OUTPUT(output_y, TensorType({ DT_FLOAT }))
  1437. .REQUIRED_ATTR(normalize_type, String)
  1438. .ATTR(epsilon, Float, 0.00001)
  1439. .OP_END_FACTORY_REG(NormalizeBatch)
  1440. /**
  1441. *@brief GroupNorm and Reul operator
  1442. * calculating: x, gamma, beta
  1443. * y = relu(gamma*((x - mean) / np.sqrt(variance + 0.001)) + beta)
  1444. * @par Inputs:
  1445. * Three inputs, including:
  1446. * @li x: A Tensor. Must be one of the following types: float16, float32.
  1447. * @li gamma: A Tensor. Must be one of the following types: float16, float32.
  1448. * @li beta: A Tensor. Must be one of the following types: float16, float32 . \n
  1449. * @par Attributes:
  1450. * @li num_groups: A require attribute, the type is int32.
  1451. * @li eps: A optional attribute, the type is float32. Defaults to 0.00001. \n
  1452. * @par Outputs:
  1453. * One outputs, including:
  1454. * @li y: A Tensor. Must be one of the following types: float16, float32.
  1455. * @par Restrictions:
  1456. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use/
  1457. */
  1458. REG_OP(GroupNormRelu)
  1459. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1460. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  1461. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  1462. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  1463. .REQUIRED_ATTR(num_groups, Int)
  1464. .ATTR(eps, Float, 0.00001)
  1465. .OP_END_FACTORY_REG(GroupNormRelu)
  1466. /**
  1467. * @brief Function dropout with softmaxgrad and muls
  1468. * @par Inputs:
  1469. * Two inputs, including:
  1470. * @li y_grad: A mutable Tensor. The type only support float16.
  1471. * @li mask: A mutable Tensor. Must met all of the following rules:
  1472. * shape of mask should be 1D.
  1473. * dtype of mask should be uint8.
  1474. * value of shape should met the following algorithm:
  1475. * value = (size(x) + 128 - 1) // 128 * 128
  1476. * @li softmax_output: A mutable Tensor. Must met all of the following rules:
  1477. * shape of softmax_output should be NZ.
  1478. * dtype of softmax_output should be float16.
  1479. * it is the output of softmax
  1480. * @par Attributes:
  1481. * @li input_keep_prob:A attribute used to judge which units should be keep.
  1482. * Has the same type as "x" . \n
  1483. * @li alpha: A attribute used to scale tensor.
  1484. * Has the same type as "x" . \n
  1485. * @li axes: A list of int. The dimension softmax would be performed on. Defaults
  1486. * to "[-1]" . \n
  1487. * @par Outputs:
  1488. * x_grad: A mutable Tensor. Has the same type as "x". \n
  1489. * @par Restrictions:
  1490. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1491. */
  1492. REG_OP(DropoutWithMulsAndSoftmaxGrad)
  1493. .INPUT(y_grad, TensorType({ DT_FLOAT16 }))
  1494. .INPUT(mask, TensorType({ DT_UINT8 }))
  1495. .INPUT(softmax_output, TensorType({ DT_FLOAT16 }))
  1496. .OUTPUT(x_grad, TensorType({ DT_FLOAT16 }))
  1497. .REQUIRED_ATTR(input_keep_prob, Float)
  1498. .REQUIRED_ATTR(alpha, Float)
  1499. .ATTR(axes, ListInt, { -1 })
  1500. .OP_END_FACTORY_REG(DropoutWithMulsAndSoftmaxGrad)
  1501. /**
  1502. * @brief Loss function that measures the softmax cross entropy. \n
  1503. * @par Inputs:
  1504. * Three inputs, including:
  1505. * @li scores: A Tensor. Must be one of the following types: half, float32, double.
  1506. * A "batch_size * num_classes" matrix.
  1507. * @li labels: A Tensor. Must be one of the following types: "int32", "int64".
  1508. * @li weights: A manual rescaling weight given to each class.
  1509. * If given, it has to be a 1D Tensor assigning weight to each of the classes.
  1510. * Otherwise, it is treated as if having all ones. \n
  1511. * @par Attributes:
  1512. * ignore_index:Specifies a target value that is ignored and does not contribute to the input gradient.
  1513. * It's an optional value.
  1514. * reduction: A character string from "none", "mean", and "sum", specifying the gradient output mode. Defaults to "mean" . \n
  1515. * @par Outputs:
  1516. * @li loss: A Tensor for per example loss (a "batch_size" vector). Has the same type as "scores".
  1517. * @li log_prop: A Tensor. Has the same type as "scores" . \n
  1518. * @par Third-party framework compatibility
  1519. * Compatible with the ONNX operator SoftmaxCrossEntropyLoss.
  1520. */
  1521. REG_OP(SoftmaxCrossEntropyLoss)
  1522. .INPUT(scores, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT,DT_BFLOAT16}))
  1523. .INPUT(labels, TensorType({DT_INT32, DT_INT64}))
  1524. .OPTIONAL_INPUT(weights, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT,DT_BFLOAT16}))
  1525. .ATTR(ignore_index, Int, 0)
  1526. .ATTR(reduction, String, "mean")
  1527. .OUTPUT(loss, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT,DT_BFLOAT16}))
  1528. .OUTPUT(log_prop, TensorType({DT_DOUBLE,DT_FLOAT16,DT_FLOAT,DT_BFLOAT16}))
  1529. .OP_END_FACTORY_REG(SoftmaxCrossEntropyLoss)
  1530. /**
  1531. * @brief Function axpy with softmax and dropoutdomask . \n
  1532. * @par Inputs:
  1533. * Three inputs, including:
  1534. * @li x1: A mutable Tensor. The type only support float16.
  1535. * @li x2: A mutable Tensor. The type only support float16.
  1536. * @li mask: A mutable Tensor. Must meet all of the following rules:
  1537. * shape of mask should be 1D.
  1538. * dtype of mask should be uint8.
  1539. * value of shape should meet the following algorithm:
  1540. * value = (size(x) + 128 - 1) // 128 * 128 . \n
  1541. * @par Attributes:
  1542. * @li alpha: A attribute used to scale tensor. The type is float . \n
  1543. * @li input_keep_prob: A attribute used to judge which units should be keep.
  1544. * The type is float . \n
  1545. * @li axis: A list of int. The dimension softmax would be performed on. Defaults
  1546. * to "[-1]" . \n
  1547. * @par Outputs:
  1548. * y1: A mutable Tensor. Has the same type as "x1". \n
  1549. * y2: A mutable Tensor. Has the same type as "x1". \n
  1550. * @par Restrictions:
  1551. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1552. */
  1553. REG_OP(AxpyWithSoftmaxAndDropOutDoMask)
  1554. .INPUT(x1, TensorType({DT_FLOAT16}))
  1555. .INPUT(x2, TensorType({DT_FLOAT16}))
  1556. .INPUT(mask, TensorType({DT_UINT8}))
  1557. .OUTPUT(y1, TensorType({DT_FLOAT16}))
  1558. .OUTPUT(y2, TensorType({DT_FLOAT16}))
  1559. .REQUIRED_ATTR(alpha, Float)
  1560. .REQUIRED_ATTR(input_keep_prob, Float)
  1561. .ATTR(axis, ListInt, {-1})
  1562. .OP_END_FACTORY_REG(AxpyWithSoftmaxAndDropOutDoMask)
  1563. } // namespace ge
  1564. #endif // OPS_BUILT_IN_OP_PROTO_INC_NN_NORM_OPS_H_

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