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

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