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

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