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 39 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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: A ND Tensor of type float16 or float32.
  360. * @li features: A 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 softsignGrad: y_grad / (1 + abs(x)) ** 2 .
  387. *
  388. * @par Inputs:
  389. * Two inputs, including:
  390. * @li y_grad: A Tensor.Must be one of the following types:float16, float32,
  391. * @li x: A Tensor of the same type and shape as "gradients".
  392. * @par x_grad:
  393. * output:A Tensor. Has the same type as "y_grad".
  394. * @par Third-party framework compatibility
  395. * Compatible with the TensorFlow operator SoftsignGrad.
  396. */
  397. REG_OP(SoftsignGrad)
  398. .INPUT(y_grad, TensorType::FloatingDataType())
  399. .INPUT(x, TensorType::FloatingDataType())
  400. .OUTPUT(x_grad, TensorType::FloatingDataType())
  401. .OP_END_FACTORY_REG(SoftsignGrad)
  402. /**
  403. *@brief Computes scaled exponential linear: scale * alpha * (exp(x) - 1) . \n
  404. *@par Inputs:
  405. * One input:
  406. *x: A Tensor. Must be one of the following types: float16, float, double
  407. * int32, int8. format:ND. \n
  408. *@par Outputs:
  409. *y: A Tensor. Has the same type and format as input "x". format:ND. \n
  410. *@see Region()
  411. *@par Third-party framework compatibility
  412. * Compatible with the TensorFlow operator Selu.
  413. */
  414. REG_OP(Selu)
  415. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  416. DT_INT8,DT_INT32}))
  417. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  418. DT_INT8,DT_INT32}))
  419. .OP_END_FACTORY_REG(Selu)
  420. /**
  421. * @brief Computes SeluGrad backprops: y_grad * (y + scale * alpha)
  422. * if y < 0, scale * y_grad otherwise .
  423. * @par Inputs:
  424. * Two inputs, including:
  425. * @li y_grad: A Tensor of type RealNumberType .
  426. * @li y: A Tensor of type RealNumberType .
  427. * @par Outputs:
  428. * x_grad: A Tensor. Must have the same type as "y_grad" .
  429. * @par Third-party framework compatibility
  430. * Compatible with the TensorFlow operator SeluGrad.
  431. */
  432. REG_OP(SeluGrad)
  433. .INPUT(y_grad, TensorType::RealNumberType())
  434. .INPUT(y, TensorType::RealNumberType())
  435. .OUTPUT(x_grad, TensorType::RealNumberType())
  436. .OP_END_FACTORY_REG(SeluGrad)
  437. /**
  438. *@brief Computes rectified linear gradients for a ReLU operation . \n
  439. *@par Inputs:
  440. * Two inputs, including:
  441. *@li gradients: A Tensor. Must be one of the following types: float32, double,
  442. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  443. *@li features: A Tensor. Must be one of the following types: float32, double,
  444. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  445. *@par Outputs:
  446. *backprops: A Tensor. Must have the same type as"gradients" . \n
  447. *@attention Constraints:
  448. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  449. *@see Relu
  450. *@par Third-party framework compatibility
  451. * Compatible with TensorFlow operator ReluGrad.
  452. */
  453. REG_OP(ReluGrad)
  454. .INPUT(gradients, TensorType::RealNumberType())
  455. .INPUT(features, TensorType::RealNumberType())
  456. .OUTPUT(backprops, TensorType::RealNumberType())
  457. .OP_END_FACTORY_REG(ReluGrad)
  458. /**
  459. *@brief Computes rectified linear gradients for a ReLU operation . \n
  460. *@par Inputs:
  461. * Two inputs, including:
  462. *@li gradients: A Tensor. Must be one of the following types: float32, double, int32, int8, int16, int8, int64, uint16, float16, uint32, uint64
  463. *@li mask: A Tensor. Must be the following types: uint8
  464. *@par Outputs:
  465. *backprops: A Tensor. Must have the same type as"gradients" . \n
  466. *@attention Constraints:
  467. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  468. *@see Relu
  469. *@par Third-party framework compatibility
  470. * Compatible with TensorFlow operator ReluGradV2.
  471. */
  472. REG_OP(ReluGradV2)
  473. .INPUT(gradients, TensorType::RealNumberType())
  474. .INPUT(mask, TensorType({DT_UINT8}))
  475. .OUTPUT(backprops, TensorType::RealNumberType())
  476. .OP_END_FACTORY_REG(ReluGradV2)
  477. /**
  478. *@brief Computes rectified linear: "max(x, 0)".
  479. *
  480. *@attention Constraints:
  481. * The last dimension must be divisible by 8.
  482. * The second output "mask" is "1" (for y >= 0) or "0" ( for y < 0).
  483. *
  484. *@par Inputs:
  485. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  486. * int16, int8, int64, uint16, float16, qint8.
  487. *
  488. *@par Outputs:
  489. *@li y: A tensor. Has the same type as "x".
  490. *@li mask: A tensor of type uint8.
  491. *
  492. *@par Third-party framework compatibility
  493. * Incompatible with TensorFlow or Caffe.
  494. *
  495. */
  496. REG_OP(ReluV2)
  497. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  498. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  499. .OUTPUT(mask, TensorType({DT_UINT8}))
  500. .OP_END_FACTORY_REG(ReluV2)
  501. /**
  502. *@brief Performs parametric ReLU . \n
  503. *@par Inputs:
  504. * Two inputs, including:
  505. *@li x: A multi-dimensional Tensor of type float16 or float32.
  506. *@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
  507. *@par Outputs:
  508. *y: An activated Tensor. Has the same dimensions with "x" . \n
  509. *@par Third-party framework compatibility
  510. * Compatible with PyTorch and Caffe operator PReLU.
  511. */
  512. REG_OP(PRelu)
  513. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  514. .INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  515. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  516. .OP_END_FACTORY_REG(PRelu)
  517. /**
  518. *@brief Performs the backpropagation of PRelu for training scenarios . \n
  519. *@par Inputs:
  520. * Three inputs, including:
  521. *@li grads: Input gradient. Multi-dimensional Tensors are supported. The data type can be float16 or float32.
  522. *@li features: A multi-dimensional Tensor of type float16 or float32.
  523. *@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
  524. *@par Outputs:
  525. *@li dx: Reverse gradient of "features". Has the same dimensions and type as "features".
  526. *@li da: Reverse gradient of "weight". Has the same dimensions and type as "features" . \n
  527. *@par Third-party framework compatibility
  528. * Compatible with PyTorch operator PReluGrad.
  529. */
  530. REG_OP(PReluGrad)
  531. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  532. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  533. .INPUT(weights, TensorType({DT_FLOAT16, DT_FLOAT}))
  534. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  535. .OUTPUT(da, TensorType({DT_FLOAT16, DT_FLOAT}))
  536. .OP_END_FACTORY_REG(PReluGrad)
  537. /**
  538. *@brief Activation function fused from sigmoid and ReLU, with soft saturation
  539. * on the left and no saturation on the right . \n
  540. *@par Inputs:
  541. *x: A float16, float32 or double, for the input data type . \n
  542. *@par Attributes:
  543. *alpha: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" . \n
  544. *@par Outputs:
  545. *y: A float16, float32 or double, for the normalized result . \n
  546. *@attention Constraints:
  547. *@li The input is of type float16 or float32 . \n
  548. *@par Multiple batches supported or not
  549. *Supported
  550. *@par Third-party framework compatibility
  551. *@li Compatible with Tensorflow's Elu operator
  552. *@li Compatible with Caffe's ELULayer operator
  553. *
  554. *@since V100R001C33
  555. */
  556. REG_OP(Elu)
  557. .INPUT(x, TensorType::FloatingDataType())
  558. .OUTPUT(y, TensorType::FloatingDataType())
  559. .ATTR(alpha, Float, 1.0)
  560. .OP_END_FACTORY_REG(Elu)
  561. /**
  562. *@brief Continuously Differentiable Exponential Linear Uints:
  563. * Perform the linear uint element-wise on the input tensor X using formula:
  564. * max(0, x) + min(0, alpha * (exp(x/alpha) - 1)). \n
  565. *@par Inputs:
  566. *x: A float16, float32, for the input data type . \n
  567. *@par Attributes:
  568. *@li alpha1: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  569. *@li alpha2: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  570. *@li alpha3: A float32. Defines at which positive value the ELU saturates. Defaults to "1.0" . \n
  571. *@par Outputs:
  572. *y: A float16, float32, for the normalized result . \n
  573. *@attention Constraints:
  574. *@li The input is of type float16 or float32 . \n
  575. *@par Multiple batches supported or not
  576. *Supported
  577. *@par Third-party framework compatibility
  578. *@li Compatible with ONNX's Celu operator
  579. */
  580. REG_OP(Celu)
  581. .INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16}))
  582. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16}))
  583. .ATTR(alpha1, Float, 1.0)
  584. .ATTR(alpha2, Float, 1.0)
  585. .ATTR(alpha3, Float, 1.0)
  586. .OP_END_FACTORY_REG(Celu)
  587. /**
  588. *@brief Continuously Differentiable Exponential Linear Uints:
  589. * Perform the linear uint element-wise on the input tensor X using formula:
  590. * max(0, x) + min(0, alpha * (exp(x/alpha) - 1)). \n
  591. *@par Inputs:
  592. *x: A float16, float32, for the input data type . \n
  593. *@par Attributes:
  594. *li alpha: A float32. Defines at which negative value the CELU saturates. Defaults to "1.0" .
  595. *@par Outputs:
  596. *y: A float16, float32, for the normalized result . \n
  597. *@attention Constraints:
  598. *@li The input is of type float16 or float32 . \n
  599. *@par Multiple batches supported or not
  600. *Supported
  601. *@par Third-party framework compatibility
  602. *@li Compatible with ONNX's Celu operator
  603. */
  604. REG_OP(CeluV2)
  605. .INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16}))
  606. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16}))
  607. .ATTR(alpha, Float, 1.0)
  608. .OP_END_FACTORY_REG(CeluV2)
  609. /**
  610. *@brief Computes gradients for the exponential linear (Elu) operation.
  611. *
  612. *@par Inputs:
  613. *@li grads: A tensor. Must be one of the following types: float16, float32, float64.
  614. * The backpropagated gradients to the corresponding Elu operation.
  615. *@li activations: A tensor. Has the same type as "grads".
  616. * The outputs of the corresponding Elu operation.
  617. *
  618. *@par Outputs:
  619. * y: A tensor. Has the same type as "grads".
  620. *
  621. *@par Third-party framework compatibility
  622. *Compatible with the TensorFlow operator EluGrad.
  623. *
  624. */
  625. REG_OP(EluGrad)
  626. .INPUT(grads, TensorType::FloatingDataType())
  627. .INPUT(activations, TensorType::FloatingDataType())
  628. .OUTPUT(y, TensorType::FloatingDataType())
  629. .OP_END_FACTORY_REG(EluGrad)
  630. /**
  631. *@brief Computes the output as x if x > 0 and negative_slope * x if x <= 0 . \n
  632. *@par Inputs:
  633. * One input:
  634. * x: A Tensor. Must be one of the following types: float32, float16, double.
  635. *
  636. *@par Attributes:
  637. *negative_slope: A float32. Defaults to "0.0".
  638. *
  639. *@par Outputs:
  640. *y: A Tensor. Has the same type as "x".
  641. *@par Third-party framework compatibility
  642. * Compatible with the Caffe operator ReLU.
  643. */
  644. REG_OP(LeakyRelu)
  645. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  646. .ATTR(negative_slope, Float, 0.0)
  647. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  648. .OP_END_FACTORY_REG(LeakyRelu)
  649. /**
  650. *@brief Computes the output as gradients if features > 0 and negative_slope * gradients if features <= 0 . \n
  651. *@par Inputs:
  652. * Two inputs, including:
  653. * @li gradients: A Tensor. Must be one of the following types: float16, float32, double.
  654. * @li features: A Tensor. Has the same type as "gradients" . \n
  655. *@par Attributes:
  656. *negative_slope: A float32. Defaults to "0.0" . \n
  657. *@par Outputs:
  658. *backprops: A Tensor. Has the same type as "gradients" . \n
  659. *@par Third-party framework compatibility
  660. * Compatible with the TensorFlow operator LeakyReluGrad.
  661. */
  662. REG_OP(LeakyReluGrad)
  663. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  664. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  665. .ATTR(negative_slope, Float, 0.0)
  666. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  667. .OP_END_FACTORY_REG(LeakyReluGrad)
  668. /**
  669. *@brief Thresholds grad each element of the input Tensor . \n
  670. *@par Inputs:
  671. * @li gradients: A Tensor shape and dtype of input gradients. Support float16, int32.
  672. * @li features: A Tensor shape and dtype of input features. Support float16, int32 . \n
  673. *@par Attributes:
  674. *threshold: A float32 scale value to threshold at . \n
  675. *@par Outputs:
  676. *backprops: A Tensor of shape and dtype of output backprops, should be same shape and type as inputs . \n
  677. *@par Restrictions:
  678. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  679. */
  680. REG_OP(ThresholdGradV2D)
  681. .INPUT(gradients, TensorType({DT_INT32, DT_FLOAT16}))
  682. .INPUT(features, TensorType({DT_INT32, DT_FLOAT16}))
  683. .OUTPUT(backprops, TensorType({DT_INT32, DT_FLOAT16}))
  684. .REQUIRED_ATTR(threshold, Float)
  685. .OP_END_FACTORY_REG(ThresholdGradV2D)
  686. /**
  687. *@brief Thresholds each element of the input Tensor y = (x > threshold) ? x : value . \n
  688. *@par Inputs:
  689. *x: A Tensor dtype of real number . \n
  690. *@par Attributes:
  691. *@li threshold: A float32 scale value to threshold at.
  692. *@li value: A float32 scale value to replace with . \n
  693. *@par Outputs:
  694. *y: A Tensor of shape and dtype of output, should be same shape and type as input . \n
  695. *@par Restrictions:
  696. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  697. */
  698. REG_OP(ThresholdV2D)
  699. .INPUT(x, TensorType::RealNumberType())
  700. .OUTPUT(y, TensorType::RealNumberType())
  701. .REQUIRED_ATTR(threshold, Float)
  702. .REQUIRED_ATTR(value, Float)
  703. .OP_END_FACTORY_REG(ThresholdV2D)
  704. /**
  705. *@brief: Computes hyperbolic tangent of "x" element-wise . \n
  706. *@par Inputs:
  707. *One input:
  708. *x: A Tensor. Must be one of the following types: float16, float32 . \n
  709. *@par Outputs:
  710. *y: A Tensor. Has the same type as "x" . \n
  711. *@par Third-party framework compatibility
  712. * Compatible with TensorFlow operator Mish.
  713. */
  714. REG_OP(Mish)
  715. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  716. .OUTPUT(y, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  717. .OP_END_FACTORY_REG(Mish)
  718. /**
  719. * @brief: pytorch mish_grad operator.
  720. * @par Inputs:
  721. * three input, including:
  722. * @li grad: A Tensor. shape, datatype and format is same as x
  723. * @li x: A Tensor. Must be one of the following types: float16, float32
  724. * @li tanhx: A Tensor. shape, datatype and format is same as x
  725. * @par Outputs:
  726. * One output, including:
  727. * x_grad: A Tensor. shape, datatype and format is same as x
  728. */
  729. REG_OP(MishGrad)
  730. .INPUT(grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  731. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  732. .OPTIONAL_INPUT(tanhx, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  733. .OUTPUT(x_grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  734. .OP_END_FACTORY_REG(MishGrad)
  735. /**
  736. * @brief pytorch hardtanh_backward operator.
  737. *
  738. * @par Inputs:
  739. * Two inputs, including:
  740. * @li result, minimum tensor of the linear region range,
  741. * datatype: float16/float32, format:ND/5HD.
  742. * @li grad, maximum tensor of the linear region range,
  743. * datatype:float16/float32, format:ND/5HD. \n
  744. * @par Attributes:
  745. * Two attributes, including:
  746. * @li min_val, minimum value of the linear region range, datatype:float.
  747. * @li max_val, maximum value of the linear region range, datatype:float. \n
  748. * @par Outputs:
  749. * One output, including:
  750. * y, hardtanh_backward output tensor, datatype and format is same as
  751. * input result. \n
  752. * @attention Constraints:
  753. * This operator only supports dataType: float16/float32, format: ND/5HD. \n
  754. * @par Third-party framework compatibility
  755. * Compatible with the Pytorch operator HardtanhGrad.
  756. */
  757. REG_OP(HardtanhGrad)
  758. .INPUT(result, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "First operand." */
  759. .INPUT(grad, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Second operand." */
  760. .OUTPUT(y, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Result, has same element type as two inputs" */
  761. .ATTR(min_val, Float, -1.0)
  762. .ATTR(max_val, Float, 1.0)
  763. .OP_END_FACTORY_REG(HardtanhGrad)
  764. /**
  765. * @brief Calculates the softplus loss function with attributes of beta and threshold. \n
  766. * @par Inputs:
  767. * One inputs, including:
  768. * x: A mutable Tensor. Must be one of the following types:
  769. * float16, float32. \n
  770. * @par Attributes:
  771. * @li beta: An optional float. Defaults to "1.0" \n
  772. * @li threshold: An optional float. Defaults to "20.0" \n
  773. * @par Outputs:
  774. * y: A mutable Tensor. Has the same type as "x" \n
  775. * @par Third-party framework compatibility
  776. * Compatible with the Pytorch operator Softplus.
  777. */
  778. REG_OP(SoftplusV2)
  779. .INPUT(x, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  780. .OUTPUT(y, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  781. .ATTR(beta, Float, 1.0)
  782. .ATTR(threshold, Float, 20.0)
  783. .OP_END_FACTORY_REG(SoftplusV2)
  784. /**
  785. * @brief Calculates the reversed outputs of the function "softplus_v2". \n
  786. * @par Inputs:
  787. * Two inputs, including:
  788. * @li input_gradients: A mutable Tensor. Must be one of the following types:
  789. * float16, float32.
  790. * @li input_features: A mutable Tensor of the same type as "input_gradients" \n
  791. * @par Attributes:
  792. * @li beta: An optional float. Defaults to "1.0" \n
  793. * @li threshold: An optional float. Defaults to "20.0" \n
  794. * @par Outputs:
  795. * output_backprops: A mutable Tensor. Has the same type as "input_gradients" \n
  796. * @par Third-party framework compatibility
  797. * Compatible with the Pytorch operator SoftplusGrad.
  798. */
  799. REG_OP(SoftplusV2Grad)
  800. .INPUT(input_gradients, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  801. .INPUT(input_features, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  802. .OUTPUT(output_backprops, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  803. .ATTR(beta, Float, 1.0)
  804. .ATTR(threshold, Float, 20.0)
  805. .OP_END_FACTORY_REG(SoftplusV2Grad)
  806. /**
  807. * @brief ThresholdedRelu takes one input data (Tensor) and produces one output data (Tensor)
  808. * where the rectified linear function, y = x for x > alpha, y = 0 otherwise, is applied to the tensor elementwise.
  809. *
  810. * @par Inputs:
  811. * one input including:
  812. * x: input A Tensor. Must be one of the following types: float32, float16
  813. *
  814. * @par Attributes:
  815. * alpha: An optional float. Defaults to 1.0. \n
  816. * @par Outputs:
  817. * one output including:
  818. * y:A Tensor of the same type as x
  819. *
  820. */
  821. REG_OP(ThresholdedRelu)
  822. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  823. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  824. .ATTR(alpha, Float, 1.0)
  825. .OP_END_FACTORY_REG(ThresholdedRelu)
  826. /**
  827. * @brief Calculate the hard shrinkage function. \n
  828. * @par Inputs:
  829. * One inputs, including:
  830. * input_x: A tensor. Must be one of the following types:
  831. * float16, float32. \n
  832. * @par Attributes:
  833. * lambd: An optional float. Defaults to 0.5. \n
  834. * @par Outputs:
  835. * output_y: A Tensor with the same dtype and shape of input_x's. \n
  836. * @par Third-party framework compatibility
  837. * Compatible with the Pytorch operator Hardshrink. \n
  838. */
  839. REG_OP(HardShrink)
  840. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  841. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  842. .ATTR(lambd, Float, 0.5)
  843. .OP_END_FACTORY_REG(HardShrink)
  844. /**
  845. *@brief Calculate the hard shrink grad function. \n
  846. *
  847. * Computes the gradient for the HardShrink: if x > lambda or x < -lambda, x,otherwise 0
  848. *
  849. *@par Inputs:
  850. *Two inputs, including:
  851. * @li gradients: A tensor. Must be one of the following types:
  852. * float16, float32. \n
  853. * @li features: A tensor. Must be one of the following types:
  854. * float16, float32. \n
  855. *
  856. *@par Outputs:
  857. *backprops: A Tensor with the same type and shape of features's. \n
  858. *
  859. *@par Attributes:
  860. *lambd: An optional float.Defaults to 0.5. \n
  861. *
  862. *@par Third-party framework compatibility
  863. *Compatible with the Pytorch operator Hardshrink_backward. \n
  864. */
  865. REG_OP(HardShrinkGrad)
  866. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT}))
  867. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  868. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  869. .ATTR(lambd, Float, 0.5)
  870. .OP_END_FACTORY_REG(HardShrinkGrad)
  871. /**
  872. * @brief Calculate the hard sigmoid function. \n
  873. * @par Inputs:
  874. * One inputs, including:
  875. * input_x: A tensor. Must be one of the following types:
  876. * float16, float32, int32. \n
  877. * @par Attributes:
  878. * @li alpha: An optional float. Defaults to 0.16666666. \n
  879. * @li beta: An optional float. Defaults to 0.5. \n
  880. * @par Outputs:
  881. * y: A Tensor with the same dtype and shape of input_x's. \n
  882. * @par Third-party framework compatibility
  883. * Compatible with the Pytorch operator Hardsigmoid. \n
  884. */
  885. REG_OP(HardSigmoid)
  886. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  887. .OUTPUT(output_y, TensorType({DT_FLOAT, DT_FLOAT16}))
  888. .ATTR(alpha, Float, 0.16666666)
  889. .ATTR(beta, Float, 0.5)
  890. .OP_END_FACTORY_REG(HardSigmoid)
  891. /**
  892. * @brief Calculate the soft shrinkage function. \n
  893. * @par Inputs:
  894. * One inputs, including:
  895. * input_x: A tensor. Must be one of the following types:
  896. * float16, float32. \n
  897. * @par Attributes:
  898. * lambd: An optional float. Defaults to 0.5. \n
  899. * @par Outputs:
  900. * y: A Tensor with the same dtype and shape of input_x's. \n
  901. * @par Third-party framework compatibility
  902. * Compatible with the Pytorch operator Softshrink. \n
  903. */
  904. REG_OP(SoftShrink)
  905. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  906. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  907. .ATTR(lambd, Float, 0.5)
  908. .OP_END_FACTORY_REG(SoftShrink)
  909. /**
  910. * @brief Calculate the reversed outputs of the function "soft_shrink". \n
  911. * @par Inputs:
  912. * Two inputs, including:
  913. * @li input_grad: A tensor. Must be one of the following types:
  914. * float16, float32. \n
  915. * @li input_x: A tensor of the same dtype as "input_grad". \n
  916. * @par Attributes:
  917. * lambd: An optional float. Defaults to 0.5. \n
  918. * @par Outputs:
  919. * y: A Tensor of the same dtype and shape as "input_graxd". \n
  920. * @par Third-party framework compatibility
  921. * Compatible with the Pytorch operator SoftShrinkGrad. \n
  922. */
  923. REG_OP(SoftShrinkGrad)
  924. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  925. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  926. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  927. .ATTR(lambd, Float, 0.5)
  928. .OP_END_FACTORY_REG(SoftShrinkGrad)
  929. /**
  930. *@brief Calculate the gradient of log simoid. \n
  931. *@par Inputs:
  932. *Two inputs, including:
  933. * @li grads: A tensor, gradient of previous layer. Must be one of the following types:
  934. * float16, float32. \n
  935. * @li features: A tensor, input of log sigmoid. Must be one of the following types:
  936. * float16, float32. \n
  937. *@par Outputs:
  938. *One outputs, including:
  939. * @li backprops: A tensor with the same type of and shape of grads. \n
  940. *@par Third-party framework compatibility
  941. *Compatible with the Pytorch operator LogSigmoidBackward. \n
  942. */
  943. REG_OP(LogSigmoidGrad)
  944. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  945. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  946. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  947. .OP_END_FACTORY_REG(LogSigmoidGrad)
  948. /**
  949. *@brief Calculate -ln(1+e^(-x)). \n
  950. *@par Inputs:
  951. *One inputs, including:
  952. * x: A tensor. Must be one of the following types:
  953. * float16, float32. \n
  954. *@par Outputs:
  955. *One outputs, including:
  956. * y: A tensor with the same type and shape of x's. \n
  957. *@par Third-party framework compatibility
  958. *Compatible with the Pytorch operator LogSigmoid. \n
  959. */
  960. REG_OP(LogSigmoid)
  961. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT})) /* "input:x" */
  962. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT})) /* "output:y" */
  963. .OP_END_FACTORY_REG(LogSigmoid)
  964. /**
  965. *@brief Calculate the backward outputs of the function "hard_sigmoid" \n
  966. *@par Inputs:
  967. *One inputs, including:
  968. * @li grads: A tensor. Must be one of the following types:
  969. * float16, float32. \n
  970. * @li input_x: A tensor. Must be one of the following types:
  971. * float16, float32. \n
  972. *@par Outputs:
  973. *One outputs, including:
  974. * y: A tensor with the same type and shape of x's. \n
  975. * @par Attributes:
  976. * @li alpha: An optional float. Defaults to 0.16666666. \n
  977. * @li beta: An optional float. Defaults to 0.5. \n
  978. *@par Third-party framework compatibility
  979. *Compatible with the Pytorch operator LogSigmoidGrad. \n
  980. */
  981. REG_OP(HardSigmoidGrad)
  982. .INPUT(grads, TensorType({DT_FLOAT, DT_FLOAT16}))
  983. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  984. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  985. .ATTR(alpha, Float, 0.16666666)
  986. .ATTR(beta, Float, 0.5)
  987. .OP_END_FACTORY_REG(HardSigmoidGrad)
  988. /**
  989. * @brief Calculate the shrink function. \n
  990. * @par Inputs:
  991. * One inputs, including:
  992. * @li input_x: A tensor. Must be one of the following types:
  993. * float16, float32. \n
  994. * @par Attributes:
  995. * @li lambd: An optional float. Defaults to 0.5. \n
  996. * @li bias: An optional float. Defaults to 0.0. \n
  997. * @par Outputs:
  998. * y: A Tensor with the same dtype and shape of input_x's. \n
  999. * @par Third-party framework compatibility
  1000. * Compatible with the ONNX operator Shrink. \n
  1001. */
  1002. REG_OP(Shrink)
  1003. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1004. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1005. .ATTR(lambd, Float, 0.5)
  1006. .ATTR(bias, Float, 0.0)
  1007. .OP_END_FACTORY_REG(Shrink)
  1008. /**
  1009. * @brief Thresholds each element of the input Tensor: y = (x > threshold) ? x : value \n
  1010. * @par Inputs:
  1011. * Three inputs, including:
  1012. * @li x: A Tensor.
  1013. * Must be one of the following types on Ascend310: float16, int8, int32, uint8.
  1014. * Must be one of the following types on Ascend710 or Ascend910: float16, float32, int8, int32, uint8. \n
  1015. * @li threshold: A Tensor which should have the shape (1,), the value to threshold at.
  1016. * Must be one of the following types on Ascend310: float16, int8, int32, uint8.
  1017. * Must be one of the following types on Ascend710 or Ascend910: float16, float32, int8, int32, uint8. \n
  1018. * @li value: A Tensor which should have the shape (1,), the value to replace with. default value is 0.
  1019. * Must be one of the following types on Ascend310: float16, int8, int32, uint8.
  1020. * Must be one of the following types on Ascend710 or Ascend910: float16, float32, int8, int32, uint8. \n
  1021. * @par Outputs:
  1022. * y: A Tensor which has the same shape and type as the input x. \n
  1023. * @par Third-party framework compatibility
  1024. * Compatible with the Pytorch operator Threshold.
  1025. */
  1026. REG_OP(ThresholdV2)
  1027. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8, DT_INT32, DT_UINT8}))
  1028. .INPUT(threshold, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8, DT_INT32, DT_UINT8}))
  1029. .OPTIONAL_INPUT(value, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8, DT_INT32, DT_UINT8}))
  1030. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8, DT_INT32, DT_UINT8}))
  1031. .OP_END_FACTORY_REG(ThresholdV2)
  1032. } // namespace ge
  1033. #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两部分组成,详细的架构图如下所示