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

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