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