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.

nonlinear_fuc_ops.h 32 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
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
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
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
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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. /**
  2. * Copyright 2020 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 nonlinear_fuc_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Computes the for the gelu of "x" . \n
  26. *@par Inputs:
  27. *One input, including:
  28. *x: A Tensor. Must be one of the following types: float16, float32
  29. *@par Outputs:
  30. *y: A Tensor. Has the same type as "x".
  31. *@par Third-party framework compatibility
  32. *Compatible with the TensorFlow operator Gelu
  33. */
  34. REG_OP(Gelu)
  35. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  36. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  37. .OP_END_FACTORY_REG(Gelu)
  38. /**
  39. *@brief Computes the gradient for the gelu of "x" . \n
  40. *@par Inputs:
  41. *Three inputs, including:
  42. * @li dy: A Tensor. Must be one of the following types: float16, float32
  43. * @li x: A Tensor of the same type as "dy".
  44. * @li y: A Tensor of the same type as "dy" . \n
  45. *@par Outputs:
  46. *z: A Tensor. Has the same type as "dy".
  47. *@par Third-party framework compatibility
  48. *Compatible with the TensorFlow operator GeluGrad
  49. */
  50. REG_OP(GeluGrad)
  51. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  52. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  53. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  54. .OUTPUT(z, TensorType({DT_FLOAT16, DT_FLOAT}))
  55. .OP_END_FACTORY_REG(GeluGrad)
  56. /**
  57. *@brief Computes the for the fast_gelu of "x" . \n
  58. *@par Inputs:
  59. *One input, including:
  60. *x: A Tensor. Must be one of the following types: float16, float32
  61. *@par Outputs:
  62. *y: A Tensor. Has the same type as "x".
  63. *@par Third-party framework compatibility
  64. *Compatible with the TensorFlow operator FastGelu
  65. */
  66. REG_OP(FastGelu)
  67. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  68. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  69. .OP_END_FACTORY_REG(FastGelu)
  70. /**
  71. *@brief Computes the gradient for the fast_gelu of "x" . \n
  72. *@par Inputs:
  73. *Two inputs, including:
  74. * @li dy: A Tensor. Must be one of the following types: float16, float32
  75. * @li x: A Tensor of the same type as "dy" . \n
  76. *@par Outputs:
  77. *z: A Tensor. Has the same type as "dy".
  78. *@par Third-party framework compatibility
  79. *Compatible with the TensorFlow operator FastGeluGrad
  80. */
  81. REG_OP(FastGeluGrad)
  82. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  83. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  84. .OUTPUT(z, TensorType({DT_FLOAT16, DT_FLOAT}))
  85. .OP_END_FACTORY_REG(FastGeluGrad)
  86. /**
  87. *@brief Computes the gradient for the tanh of "x" . \n
  88. *@par Inputs:
  89. *Two inputs, including:
  90. * @li y: A Tensor. Must be one of the following types: float16, float32,
  91. * double, complex64, complex128.
  92. * @li dy: A Tensor of the same type as "y" . \n
  93. *@par Outputs:
  94. *z: A Tensor. Has the same type as "y".
  95. *@par Third-party framework compatibility
  96. *Compatible with the TensorFlow operator TanhGrad.
  97. */
  98. REG_OP(TanhGrad)
  99. .INPUT(y, TensorType::UnaryDataType())
  100. .INPUT(dy, TensorType::UnaryDataType())
  101. .OUTPUT(z, TensorType::UnaryDataType())
  102. .OP_END_FACTORY_REG(TanhGrad)
  103. /**
  104. *@brief: Computes hyperbolic tangent of "x" element-wise . \n
  105. *@par Inputs:
  106. *One input:
  107. *x: A Tensor. Must be one of the following types: float16, float32, complex64, complex128, double . \n
  108. *@par Outputs:
  109. *y: A Tensor. Has the same type as "x" . \n
  110. *@par Third-party framework compatibility
  111. * Compatible with TensorFlow operator Tanh.
  112. */
  113. REG_OP(Tanh)
  114. .INPUT(x, TensorType::UnaryDataType())
  115. .OUTPUT(y, TensorType::UnaryDataType())
  116. .OP_END_FACTORY_REG(Tanh)
  117. /**
  118. * @brief Computes rectified linear: "max(x, 0)".
  119. *
  120. * @par Inputs:
  121. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  122. * int16, int8, int64, uint16, float16, qint8.
  123. *
  124. * @par Outputs:
  125. * y: A tensor. Has the same type as "x".
  126. *
  127. * @par Third-party framework compatibility
  128. * @li Compatible with the TensorFlow operator Relu.
  129. * @li Compatible with the Caffe operator ReLULayer.
  130. *
  131. */
  132. REG_OP(Relu)
  133. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  134. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  135. DT_UINT8, DT_UINT16, DT_QINT8}))
  136. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  137. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  138. DT_UINT8, DT_UINT16, DT_QINT8}))
  139. .OP_END_FACTORY_REG(Relu)
  140. /**
  141. * @brief Computes rectified linear 6.
  142. * activations = min(max(x, 0), 6) . \n
  143. * @par Inputs:
  144. * x: A Tensor of type RealNumberType . \n
  145. * @par Outputs:
  146. * y: A Tensor of type RealNumberType . \n
  147. * @par Third-party framework compatibility
  148. * Compatible with the TensorFlow operator Relu6.
  149. */
  150. REG_OP(Relu6)
  151. .INPUT(x, TensorType::RealNumberType())
  152. .OUTPUT(y, TensorType::RealNumberType())
  153. .OP_END_FACTORY_REG(Relu6)
  154. /**
  155. * @brief Computes rectified linear 6*scale.
  156. * activations = min(max(x, 0), 6*scale) . \n
  157. * @par Inputs:
  158. * x: A Tensor of type RealNumberType . \n
  159. * @par Attributes:
  160. * epsilon: A required scalar. The data type is float32 . \n
  161. * @par Outputs:
  162. * y: A Tensor of type RealNumberType . \n
  163. * @par Third-party framework compatibility
  164. * Compatible with the TensorFlow operator Relu6.
  165. *
  166. *@par Restrictions:
  167. *Warning: THIS FUNCTION IS DEPRECATED. Please use Relu6 instead.
  168. */
  169. REG_OP(Relu6D)
  170. .INPUT(x, TensorType::RealNumberType())
  171. .OUTPUT(y, TensorType::RealNumberType())
  172. .ATTR(scale, Float, 1.0)
  173. .OP_END_FACTORY_REG(Relu6D)
  174. /**
  175. * @brief Computes rectified linear 6 gradients for a Relu6 operation.
  176. * backprops = gradients * (features > 0) * (features < 6) . \n
  177. * @par Inputs:
  178. * @li features: A Tensor of type RealNumberType.
  179. * @li gradients: A Tensor of type RealNumberType . \n
  180. * @par Outputs:
  181. * backprops: A Tensor of type RealNumberType . \n
  182. * @par Third-party framework compatibility
  183. * Compatible with the TensorFlow operator Relu6Grad.
  184. */
  185. REG_OP(Relu6Grad)
  186. .INPUT(gradients, TensorType::RealNumberType())
  187. .INPUT(features, TensorType::RealNumberType())
  188. .OUTPUT(backprops, TensorType::RealNumberType())
  189. .OP_END_FACTORY_REG(Relu6Grad)
  190. /**
  191. *@brief Calculate the elu_grad_v2 function.
  192. *Applies the element-wise function:
  193. * Computes the backward for the elu: if x>0, 1; otherwise elu() + alpha .
  194. *@par Inputs:
  195. *One inputs, including:
  196. * @li grads: A tensor. Must be one of the following types:
  197. * float16, float32.
  198. * @li activations: A tensor. Must be one of the following types:
  199. * float16, float32.
  200. *
  201. *@par Outputs:
  202. *y: A Tensor with the same type and shape of grads's.
  203. *
  204. *@par Attributes:
  205. *@li alpha: scalar parameter, default value = 1.0
  206. */
  207. REG_OP(EluGradV2)
  208. .INPUT(grads, TensorType({DT_FLOAT, DT_FLOAT16}))
  209. .INPUT(activations, TensorType({DT_FLOAT, DT_FLOAT16}))
  210. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  211. .ATTR(alpha, Float, 1.0)
  212. .OP_END_FACTORY_REG(EluGradV2)
  213. /**
  214. * @brief Compute sigmoid of "x" element-wise . \n
  215. * @par Inputs:
  216. * A Tensor of type complex64, complex128, float16, float32 or double . \n
  217. * @par Outputs:
  218. * A Tensor. Has the same type as "x" . \n
  219. * @see Relu()
  220. * @par Third-party framework compatibility
  221. * Compatible with the TensorFlow operator Sigmoid.
  222. */
  223. REG_OP(Sigmoid)
  224. .INPUT(x, TensorType::UnaryDataType())
  225. .OUTPUT(y, TensorType::UnaryDataType())
  226. .OP_END_FACTORY_REG(Sigmoid)
  227. /**
  228. * @brief Computes z = (y - y*y)*dy . \n
  229. * @par Inputs:
  230. * @li y: The input is Tensor, dtype is UnaryDataType.
  231. * @li dy: The input is Tensor, dtype is UnaryDataType . \n
  232. * @par Outputs:
  233. * z: The shape of output, dtype is UnaryDataType.
  234. */
  235. REG_OP(SigmoidGrad)
  236. .INPUT(y, TensorType(UnaryDataType))
  237. .INPUT(dy, TensorType(UnaryDataType))
  238. .OUTPUT(z, TensorType(UnaryDataType))
  239. .OP_END_FACTORY_REG(SigmoidGrad)
  240. /**
  241. *@brief Computes the binomial normal log likelihood (BNLL) output:
  242. *if x>0, x+log(1+exp(-x)); otherwise log(1+exp(x)) . \n
  243. *@par Inputs:
  244. *x: A Tensor of type double, float16 or float32 . \n
  245. *@par Outputs:
  246. *y: A tensor. Has the same type and format as input "x" . \n
  247. *@par Third-party framework compatibility
  248. * Compatible with the Caffe operator BNLL.
  249. */
  250. REG_OP(BNLL)
  251. .INPUT(x, TensorType::FloatingDataType())
  252. .OUTPUT(y, TensorType::FloatingDataType())
  253. .OP_END_FACTORY_REG(BNLL)
  254. /**
  255. *@brief Computes softplus: log(exp(x) + 1) . \n
  256. *@par Inputs:
  257. * One input:
  258. *x: A Tensor of type float16 or float32. Up to 8D . \n
  259. *@par Outputs:
  260. *y: The activations tensor. Has the same type and format as input "x"
  261. *@par Third-party framework compatibility
  262. * Compatible with the TensorFlow operator Softplus.
  263. */
  264. REG_OP(Softplus)
  265. .INPUT(x, TensorType::FloatingDataType())
  266. .OUTPUT(y, TensorType::FloatingDataType())
  267. .OP_END_FACTORY_REG(Softplus)
  268. /**
  269. *@brief Computes softplus gradients for a softplus operation . \n
  270. *@par Inputs:
  271. *Two inputs:
  272. * @li gradients: An NC1HWC0 or ND Tensor of type float16 or float32.
  273. * @li features: An NC1HWC0 or ND Tensor of type float16 or float32.
  274. *@par Outputs:
  275. *backprops: A Tensor. Has the same type and format as input "gradients" . \n
  276. *@par Third-party framework compatibility
  277. * Compatible with the TensorFlow operator SoftplusGrad.
  278. */
  279. REG_OP(SoftplusGrad)
  280. .INPUT(gradients, TensorType::FloatingDataType())
  281. .INPUT(features, TensorType::FloatingDataType())
  282. .OUTPUT(backprops, TensorType::FloatingDataType())
  283. .OP_END_FACTORY_REG(SoftplusGrad)
  284. /**
  285. *@brief Computes softsign: x/(abs(x) + 1) . \n
  286. *@par Inputs:
  287. * One input:
  288. *x: A Tensor of type float16 or float32. Up to 8D . \n
  289. *@par Outputs:
  290. *y: The activations tensor. Has the same type and format as "x"
  291. *@par Third-party framework compatibility
  292. * Compatible with the TensorFlow operator Softsign.
  293. */
  294. REG_OP(Softsign)
  295. .INPUT(x, TensorType::FloatingDataType())
  296. .OUTPUT(y, TensorType::FloatingDataType())
  297. .OP_END_FACTORY_REG(Softsign)
  298. /**
  299. *@brief Computes scaled exponential linear: scale * alpha * (exp(x) - 1) . \n
  300. *@par Inputs:
  301. * One input:
  302. *x: A Tensor. Must be one of the following types: float16, float, double
  303. * int32, int8. format:ND, NC1HWC0 . \n
  304. *@par Outputs:
  305. *y: A Tensor. Has the same type and format as input "x". format:ND, NC1HWC0 . \n
  306. *@see Region()
  307. *@par Third-party framework compatibility
  308. * Compatible with the TensorFlow operator Selu.
  309. */
  310. REG_OP(Selu)
  311. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  312. DT_INT8,DT_INT32}))
  313. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  314. DT_INT8,DT_INT32}))
  315. .OP_END_FACTORY_REG(Selu)
  316. /**
  317. *@brief Computes rectified linear gradients for a ReLU operation . \n
  318. *@par Inputs:
  319. * Two inputs, including:
  320. *@li gradients: A Tensor. Must be one of the following types: float32, double,
  321. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  322. *@li features: A Tensor. Must be one of the following types: float32, double,
  323. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  324. *@par Outputs:
  325. *backprops: A Tensor. Must have the same type as"gradients" . \n
  326. *@attention Constraints:
  327. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  328. *@see Relu
  329. *@par Third-party framework compatibility
  330. * Compatible with TensorFlow operator ReluGrad.
  331. */
  332. REG_OP(ReluGrad)
  333. .INPUT(gradients, TensorType::RealNumberType())
  334. .INPUT(features, TensorType::RealNumberType())
  335. .OUTPUT(backprops, TensorType::RealNumberType())
  336. .OP_END_FACTORY_REG(ReluGrad)
  337. /**
  338. *@brief Computes rectified linear gradients for a ReLU operation . \n
  339. *@par Inputs:
  340. * Two inputs, including:
  341. *@li gradients: A Tensor. Must be one of the following types: float32, double, int32, int8, int16, int8, int64, uint16, float16, uint32, uint64
  342. *@li mask: A Tensor. Must be the following types: uint8
  343. *@par Outputs:
  344. *backprops: A Tensor. Must have the same type as"gradients" . \n
  345. *@attention Constraints:
  346. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  347. *@see Relu
  348. *@par Third-party framework compatibility
  349. * Compatible with TensorFlow operator ReluGradV2.
  350. */
  351. REG_OP(ReluGradV2)
  352. .INPUT(gradients, TensorType::RealNumberType())
  353. .INPUT(mask, TensorType({DT_UINT8}))
  354. .OUTPUT(backprops, TensorType::RealNumberType())
  355. .OP_END_FACTORY_REG(ReluGradV2)
  356. /**
  357. *@brief Computes rectified linear: "max(x, 0)".
  358. *
  359. *@attention Constraints:
  360. * The last dimension must be divisible by 8.
  361. * The second output "mask" is "1" (for y >= 0) or "0" ( for y < 0).
  362. *
  363. *@par Inputs:
  364. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  365. * int16, int8, int64, uint16, float16, qint8.
  366. *
  367. *@par Outputs:
  368. *@li y: A tensor. Has the same type as "x".
  369. *@li mask: A tensor of type uint8.
  370. *
  371. *@par Third-party framework compatibility
  372. * Incompatible with TensorFlow or Caffe.
  373. *
  374. */
  375. REG_OP(ReluV2)
  376. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  377. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  378. .OUTPUT(mask, TensorType({DT_UINT8}))
  379. .OP_END_FACTORY_REG(ReluV2)
  380. /**
  381. *@brief Performs parametric ReLU . \n
  382. *@par Inputs:
  383. * Two inputs, including:
  384. *@li x: A multi-dimensional Tensor of type float16 or float32.
  385. *@li weight: A Scalar or 1D Tensor of type float16 or float32, specifying the weight, the initial value of "a". The number of dimensions must be the same as the number of channels . \n
  386. *@par Outputs:
  387. *y: An activated Tensor. Has the same dimensions with "x" . \n
  388. *@par Third-party framework compatibility
  389. * Compatible with PyTorch and Caffe operator PReLU.
  390. */
  391. REG_OP(PRelu)
  392. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  393. .INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  394. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  395. .OP_END_FACTORY_REG(PRelu)
  396. /**
  397. *@brief Performs the backpropagation of PRelu for training scenarios . \n
  398. *@par Inputs:
  399. * Three inputs, including:
  400. *@li grads: Input gradient. Multi-dimensional Tensors are supported. The data type can be float16 or float32.
  401. *@li features: A multi-dimensional Tensor of type float16 or float32.
  402. *@li weights: A Scalar or 1D Tensor of type float16 or float32, specifying the weight. The number of dimensions must be the same as the number of channels . \n
  403. *@par Outputs:
  404. *@li dx: Reverse gradient of "features". Has the same dimensions and type as "features".
  405. *@li da: Reverse gradient of "weight". Has the same dimensions and type as "features" . \n
  406. *@par Third-party framework compatibility
  407. * Compatible with PyTorch operator PReluGrad.
  408. */
  409. REG_OP(PReluGrad)
  410. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  411. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  412. .INPUT(weights, TensorType({DT_FLOAT16, DT_FLOAT}))
  413. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  414. .OUTPUT(da, TensorType({DT_FLOAT16, DT_FLOAT}))
  415. .OP_END_FACTORY_REG(PReluGrad)
  416. /**
  417. *@brief Activation function fused from sigmoid and ReLU, with soft saturation
  418. * on the left and no saturation on the right . \n
  419. *@par Inputs:
  420. *x: A float16, float32 or double, for the input data type . \n
  421. *@par Attributes:
  422. *alpha: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" . \n
  423. *@par Outputs:
  424. *y: A float16, float32 or double, for the normalized result . \n
  425. *@attention Constraints:
  426. *@li The input is of type float16 or float32 . \n
  427. *@par Multiple batches supported or not
  428. *Supported
  429. *@par Third-party framework compatibility
  430. *@li Compatible with Tensorflow's Elu operator
  431. *@li Compatible with Caffe's ELULayer operator
  432. *
  433. *@since V100R001C33
  434. */
  435. REG_OP(Elu)
  436. .INPUT(x, TensorType::FloatingDataType())
  437. .OUTPUT(y, TensorType::FloatingDataType())
  438. .ATTR(alpha, Float, 1.0)
  439. .OP_END_FACTORY_REG(Elu)
  440. /**
  441. *@brief Continuously Differentiable Exponential Linear Uints:
  442. * Perform the linear uint element-wise on the input tensor X using formula:
  443. * max(0, x) + min(0, alpha * (exp(x/alpha) - 1)). \n
  444. *@par Inputs:
  445. *x: A float16, float32, for the input data type . \n
  446. *@par Attributes:
  447. *@li alpha1: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  448. *@li alpha2: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  449. *@li alpha3: A float32. Defines at which positive value the ELU saturates. Defaults to "1.0" . \n
  450. *@par Outputs:
  451. *y: A float16, float32, for the normalized result . \n
  452. *@attention Constraints:
  453. *The input is of type float16 or float32 . \n
  454. *@par Multiple batches supported or not
  455. *Supported
  456. *@par Third-party framework compatibility
  457. *Compatible with ONNX's Celu operator
  458. */
  459. REG_OP(Celu)
  460. .INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16}))
  461. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16}))
  462. .ATTR(alpha1, Float, 1.0)
  463. .ATTR(alpha2, Float, 1.0)
  464. .ATTR(alpha3, Float, 1.0)
  465. .OP_END_FACTORY_REG(Celu)
  466. /**
  467. *@brief Computes gradients for the exponential linear (Elu) operation.
  468. *
  469. *@par Inputs:
  470. *@li grads: A tensor. Must be one of the following types: float16, float32, float64.
  471. * The backpropagated gradients to the corresponding Elu operation.
  472. *@li activations: A tensor. Has the same type as "grads".
  473. * The outputs of the corresponding Elu operation.
  474. *
  475. *@par Outputs:
  476. * y: A tensor. Has the same type as "grads".
  477. *
  478. *@par Third-party framework compatibility
  479. *Compatible with the TensorFlow operator EluGrad.
  480. *
  481. */
  482. REG_OP(EluGrad)
  483. .INPUT(grads, TensorType::FloatingDataType())
  484. .INPUT(activations, TensorType::FloatingDataType())
  485. .OUTPUT(y, TensorType::FloatingDataType())
  486. .OP_END_FACTORY_REG(EluGrad)
  487. /**
  488. *@brief Computes the output as x if x > 0 and negative_slope * x if x <= 0 . \n
  489. *@par Inputs:
  490. * One input:
  491. * x: A Tensor. Must be one of the following types: float32, float16, double.
  492. *
  493. *@par Attributes:
  494. *negative_slope: A float32. Defaults to "0.0".
  495. *
  496. *@par Outputs:
  497. *y: A Tensor. Has the same type as "x".
  498. *@par Third-party framework compatibility
  499. * Compatible with the Caffe operator ReLU.
  500. */
  501. REG_OP(LeakyRelu)
  502. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  503. .ATTR(negative_slope, Float, 0.0)
  504. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  505. .OP_END_FACTORY_REG(LeakyRelu)
  506. /**
  507. *@brief Computes the output as gradients if features > 0 and negative_slope * gradients if features <= 0 . \n
  508. *@par Inputs:
  509. * Two inputs, including:
  510. * @li gradients: A Tensor. Must be one of the following types: float16, float32, double.
  511. * @li features: A Tensor. Has the same type as "gradients" . \n
  512. *@par Attributes:
  513. *negative_slope: A float32. Defaults to "0.0" . \n
  514. *@par Outputs:
  515. *backprops: A Tensor. Has the same type as "gradients" . \n
  516. *@par Third-party framework compatibility
  517. * Compatible with the TensorFlow operator LeakyReluGrad.
  518. */
  519. REG_OP(LeakyReluGrad)
  520. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  521. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  522. .ATTR(negative_slope, Float, 0.0)
  523. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  524. .OP_END_FACTORY_REG(LeakyReluGrad)
  525. /**
  526. *@brief Thresholds grad each element of the input Tensor . \n
  527. *@par Inputs:
  528. * @li gradients: A Tensor shape and dtype of input gradients. Support float16, int32.
  529. * @li features: A Tensor shape and dtype of input features. Support float16, int32 . \n
  530. *@par Attributes:
  531. *threshold: A float32 scale value to threshold at . \n
  532. *@par Outputs:
  533. *backprops: A Tensor of shape and dtype of output backprops, should be same shape and type as inputs . \n
  534. *@par Restrictions:
  535. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  536. */
  537. REG_OP(ThresholdGradV2D)
  538. .INPUT(gradients, TensorType({DT_INT32, DT_FLOAT16}))
  539. .INPUT(features, TensorType({DT_INT32, DT_FLOAT16}))
  540. .OUTPUT(backprops, TensorType({DT_INT32, DT_FLOAT16}))
  541. .REQUIRED_ATTR(threshold, Float)
  542. .OP_END_FACTORY_REG(ThresholdGradV2D)
  543. /**
  544. *@brief Thresholds each element of the input Tensor y = (x > threshold) ? x : value . \n
  545. *@par Inputs:
  546. *x: A Tensor dtype of real number . \n
  547. *@par Attributes:
  548. *@li threshold: A float32 scale value to threshold at.
  549. *@li value: A float32 scale value to replace with . \n
  550. *@par Outputs:
  551. *y: A Tensor of shape and dtype of output, should be same shape and type as input . \n
  552. *@par Restrictions:
  553. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  554. */
  555. REG_OP(ThresholdV2D)
  556. .INPUT(x, TensorType::RealNumberType())
  557. .OUTPUT(y, TensorType::RealNumberType())
  558. .REQUIRED_ATTR(threshold, Float)
  559. .REQUIRED_ATTR(value, Float)
  560. .OP_END_FACTORY_REG(ThresholdV2D)
  561. /**
  562. *@brief: Computes hyperbolic tangent of "x" element-wise . \n
  563. *@par Inputs:
  564. *One input:
  565. *x: A Tensor. Must be one of the following types: float16, float32 . \n
  566. *@par Outputs:
  567. *y: A Tensor. Has the same type as "x" . \n
  568. *@par Third-party framework compatibility
  569. * Compatible with TensorFlow operator Mish.
  570. */
  571. REG_OP(Mish)
  572. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  573. .OUTPUT(y, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  574. .OP_END_FACTORY_REG(Mish)
  575. /**
  576. * @brief: pytorch mish_grad operator.
  577. * @par Inputs:
  578. * three input, including:
  579. * @li grad: A Tensor. shape, datatype and format is same as x
  580. * @li x: A Tensor. Must be one of the following types: float16, float32
  581. * @li tanhx: A Tensor. shape, datatype and format is same as x
  582. * @par Outputs:
  583. * 1 output, including:
  584. * @li x_grad: A Tensor. shape, datatype and format is same as x
  585. */
  586. REG_OP(MishGrad)
  587. .INPUT(grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  588. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  589. .OPTIONAL_INPUT(tanhx, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  590. .OUTPUT(x_grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  591. .OP_END_FACTORY_REG(MishGrad)
  592. /**
  593. * @brief pytorch hardtanh_backward operator.
  594. *
  595. * @par Inputs:
  596. * 2 inputs, including:
  597. * @li result, minimum tensor of the linear region range,
  598. * datatype: float16/float32, format:ND/5HD.
  599. * @li grad, maximum tensor of the linear region range,
  600. * datatype:float16/float32, format:ND/5HD. \n
  601. * @par Attributes:
  602. * 2 attributes, including:
  603. * @li min_val, minimum value of the linear region range, datatype:float.
  604. * @li max_val, maximum value of the linear region range, datatype:float. \n
  605. * @par Outputs:
  606. * 1 output, including:
  607. * @li y, hardtanh_backward output tensor, datatype and format is same as
  608. * input result. \n
  609. * @attention Constraints:
  610. * This operator only supports dataType: float16/float32, format: ND/5HD. \n
  611. * @par Third-party framework compatibility
  612. * Compatible with the Pytorch operator HardtanhGrad.
  613. */
  614. REG_OP(HardtanhGrad)
  615. .INPUT(result, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "First operand." */
  616. .INPUT(grad, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Second operand." */
  617. .OUTPUT(y, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Result, has same element type as two inputs" */
  618. .ATTR(min_val, Float, -1.0)
  619. .ATTR(max_val, Float, 1.0)
  620. .OP_END_FACTORY_REG(HardtanhGrad)
  621. /**
  622. * @brief Calculates the softplus loss function with attributes of beta and threshold. \n
  623. * @par Inputs:
  624. * One inputs, including:
  625. * @li x: A mutable Tensor. Must be one of the following types:
  626. * float16, float32. \n
  627. * @par Attributes:
  628. * @li beta: An optional float. Defaults to "1.0" \n
  629. * @li threshold: An optional float. Defaults to "20.0" \n
  630. * @par Outputs:
  631. * @li y: A mutable Tensor. Has the same type as "x" \n
  632. * @par Third-party framework compatibility
  633. * Compatible with the Pytorch operator Softplus.
  634. */
  635. REG_OP(SoftplusV2)
  636. .INPUT(x, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  637. .OUTPUT(y, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  638. .ATTR(beta, Float, 1.0)
  639. .ATTR(threshold, Float, 20.0)
  640. .OP_END_FACTORY_REG(SoftplusV2)
  641. /**
  642. * @brief Calculates the reversed outputs of the function "softplus_v2". \n
  643. * @par Inputs:
  644. * Two inputs, including:
  645. * @li input_gradients: A mutable Tensor. Must be one of the following types:
  646. * float16, float32.
  647. * @li input_features: A mutable Tensor of the same type as "input_gradients" \n
  648. * @par Attributes:
  649. * @li beta: An optional float. Defaults to "1.0" \n
  650. * @li threshold: An optional float. Defaults to "20.0" \n
  651. * @par Outputs:
  652. * @li output_backprops: A mutable Tensor. Has the same type as "input_gradients" \n
  653. * @par Third-party framework compatibility
  654. * Compatible with the Pytorch operator SoftplusGrad.
  655. */
  656. REG_OP(SoftplusV2Grad)
  657. .INPUT(input_gradients, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  658. .INPUT(input_features, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  659. .OUTPUT(output_backprops, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  660. .ATTR(beta, Float, 1.0)
  661. .ATTR(threshold, Float, 20.0)
  662. .OP_END_FACTORY_REG(SoftplusV2Grad)
  663. /**
  664. * @brief ThresholdedRelu takes one input data (Tensor) and produces one output data (Tensor)
  665. * where the rectified linear function, y = x for x > alpha, y = 0 otherwise, is applied to the tensor elementwise.
  666. *
  667. * @par inputs
  668. * one input including:
  669. * @li x: input A Tensor. Must be one of the following types: float32, float16
  670. *
  671. * @par output
  672. * one output including:
  673. * @li y:A Tensor of the same type as x
  674. *
  675. */
  676. REG_OP(ThresholdedRelu)
  677. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  678. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  679. .ATTR(alpha, Float, 1.0)
  680. .OP_END_FACTORY_REG(ThresholdedRelu)
  681. /**
  682. * @brief Calculate the hard shrinkage function. \n
  683. * @par Inputs:
  684. * One inputs, including:
  685. * @li input_x: A tensor. Must be one of the following types:
  686. * float16, float32. \n
  687. * @par Attributes:
  688. * @li lambd: An optional float. Defaults to 0.5. \n
  689. * @par Outputs:
  690. * y: A Tensor with the same dtype and shape of input_x's. \n
  691. * @par Third-party framework compatibility
  692. * Compatible with the Pytorch operator Hardshrink. \n
  693. */
  694. REG_OP(HardShrink)
  695. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  696. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  697. .ATTR(lambd, Float, 0.5)
  698. .OP_END_FACTORY_REG(HardShrink)
  699. /**
  700. *@brief Calculate the hard shrink grad function. \n
  701. *
  702. * Computes the gradient for the HardShrink: if x > lambda or x < -lambda, x,otherwise 0
  703. *
  704. *@par Inputs:
  705. *Two inputs, including:
  706. * @li gradients: A tensor. Must be one of the following types:
  707. * float16, float32. \n
  708. * @li features: A tensor. Must be one of the following types:
  709. * float16, float32. \n
  710. *
  711. *@par Outputs:
  712. *backprops: A Tensor with the same type and shape of features's. \n
  713. *
  714. *@par Attributes:
  715. *@li lambd: An optional float.Defaults to 0.5. \n
  716. *
  717. *@par Third-party framework compatibility
  718. *Compatible with the Pytorch operator Hardshrink_backward. \n
  719. */
  720. REG_OP(HardShrinkGrad)
  721. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT}))
  722. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  723. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  724. .ATTR(lambd, Float, 0.5)
  725. .OP_END_FACTORY_REG(HardShrinkGrad)
  726. /**
  727. * @brief Calculate the hard sigmoid function. \n
  728. * @par Inputs:
  729. * One inputs, including:
  730. * @li input_x: A tensor. Must be one of the following types:
  731. * float16, float32, int32. \n
  732. * @par Attributes:
  733. * @li alpha: An optional float. Defaults to 0.16666666. \n
  734. * @li beta: An optional float. Defaults to 0.5. \n
  735. * @par Outputs:
  736. * y: A Tensor with the same dtype and shape of input_x's. \n
  737. * @par Third-party framework compatibility
  738. * Compatible with the Pytorch operator Hardsigmoid. \n
  739. */
  740. REG_OP(HardSigmoid)
  741. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  742. .OUTPUT(output_y, TensorType({DT_FLOAT, DT_FLOAT16}))
  743. .ATTR(alpha, Float, 0.16666666)
  744. .ATTR(beta, Float, 0.5)
  745. .OP_END_FACTORY_REG(HardSigmoid)
  746. /**
  747. * @brief Calculate the soft shrinkage function. \n
  748. * @par Inputs:
  749. * One inputs, including:
  750. * @li input_x: A tensor. Must be one of the following types:
  751. * float16, float32. \n
  752. * @par Attributes:
  753. * @li lambd: An optional float. Defaults to 0.5. \n
  754. * @par Outputs:
  755. * y: A Tensor with the same dtype and shape of input_x's. \n
  756. * @par Third-party framework compatibility
  757. * Compatible with the Pytorch operator Softshrink. \n
  758. */
  759. REG_OP(SoftShrink)
  760. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  761. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  762. .ATTR(lambd, Float, 0.5)
  763. .OP_END_FACTORY_REG(SoftShrink)
  764. /**
  765. * @brief Calculate the reversed outputs of the function "soft_shrink". \n
  766. * @par Inputs:
  767. * Two inputs, including:
  768. * @li input_grad: A tensor. Must be one of the following types:
  769. * float16, float32. \n
  770. * @li input_x: A tensor of the same dtype as "input_grad". \n
  771. * @par Attributes:
  772. * @li lambd: An optional float. Defaults to 0.5. \n
  773. * @par Outputs:
  774. * y: A Tensor of the same dtype and shape as "input_graxd". \n
  775. * @par Third-party framework compatibility
  776. * Compatible with the Pytorch operator SoftShrinkGrad. \n
  777. */
  778. REG_OP(SoftShrinkGrad)
  779. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  780. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  781. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  782. .ATTR(lambd, Float, 0.5)
  783. .OP_END_FACTORY_REG(SoftShrinkGrad)
  784. /**
  785. *@brief Calculate the gradient of log simoid. \n
  786. *@par Inputs:
  787. *Two inputs, including:
  788. * @li grads: A tensor, gradient of previous layer. Must be one of the following types:
  789. * float16, float32. \n
  790. * @li features: A tensor, input of log sigmoid. Must be one of the following types:
  791. * float16, float32. \n
  792. *@par Outputs:
  793. *One outputs, including:
  794. * @li backprops: A tensor with the same type of and shape of grads. \n
  795. *@par Third-party framework compatibility
  796. *Compatible with the Pytorch operator LogSigmoidBackward. \n
  797. */
  798. REG_OP(LogSigmoidGrad)
  799. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  800. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  801. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  802. .OP_END_FACTORY_REG(LogSigmoidGrad)
  803. /**
  804. *@brief Calculate -ln(1+e^(-x)). \n
  805. *@par Inputs:
  806. *One inputs, including:
  807. * @li x: A tensor. Must be one of the following types:
  808. * float16, float32. \n
  809. *@par Outputs:
  810. *One outputs, including:
  811. * @li y: A tensor with the same type and shape of x's. \n
  812. *@par Third-party framework compatibility
  813. *Compatible with the Pytorch operator LogSigmoid. \n
  814. */
  815. REG_OP(LogSigmoid)
  816. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT})) /* "input:x" */
  817. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT})) /* "output:y" */
  818. .OP_END_FACTORY_REG(LogSigmoid)
  819. /**
  820. *@brief Calculate the backward outputs of the function "hard_sigmoid" \n
  821. *@par Inputs:
  822. *One inputs, including:
  823. * @li grads: A tensor. Must be one of the following types:
  824. * float16, float32. \n
  825. * @li input_x: A tensor. Must be one of the following types:
  826. * float16, float32. \n
  827. *@par Outputs:
  828. *One outputs, including:
  829. * @li y: A tensor with the same type and shape of x's. \n
  830. * @par Attributes:
  831. * @li alpha: An optional float. Defaults to 0.16666666. \n
  832. * @li beta: An optional float. Defaults to 0.5. \n
  833. *@par Third-party framework compatibility
  834. *Compatible with the Pytorch operator LogSigmoidGrad. \n
  835. */
  836. REG_OP(HardSigmoidGrad)
  837. .INPUT(grads, TensorType({DT_FLOAT, DT_FLOAT16}))
  838. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  839. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  840. .ATTR(alpha, Float, 0.16666666)
  841. .ATTR(beta, Float, 0.5)
  842. .OP_END_FACTORY_REG(HardSigmoidGrad)
  843. /**
  844. * @brief Calculate the shrink function. \n
  845. * @par Inputs:
  846. * One inputs, including:
  847. * @li input_x: A tensor. Must be one of the following types:
  848. * float16, float32. \n
  849. * @par Attributes:
  850. * @li lambd: An optional float. Defaults to 0.5. \n
  851. * @li bias: An optional float. Defaults to 0.0. \n
  852. * @par Outputs:
  853. * y: A Tensor with the same dtype and shape of input_x's. \n
  854. * @par Third-party framework compatibility
  855. * Compatible with the ONNX operator Shrink. \n
  856. */
  857. REG_OP(Shrink)
  858. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  859. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  860. .ATTR(lambd, Float, 0.5)
  861. .ATTR(bias, Float, 0.0)
  862. .OP_END_FACTORY_REG(Shrink)
  863. } // namespace ge
  864. #endif // OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示