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

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