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