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