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

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