You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nonlinear_fuc_ops.h 32 kB

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