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.

random_ops.h 20 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
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /**
  2. * Copyright 2019 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 random_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_RANDOM_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_RANDOM_OPS_H_
  22. #include <vector>
  23. #include "graph/operator_reg.h"
  24. namespace ge {
  25. /**
  26. *@brief Draws samples from a multinomial distribution . \n
  27. *@par Inputs:
  28. *Inputs include:
  29. * @li logits: A Tensor. Must be one of the following types: float16, float, double.
  30. 2-D Tensor with shape [batch_size, num_classes].
  31. * @li num_samples: A Tensor of type int32. 0-D. Number of independent samples to draw for each row slice . \n
  32. *@par Attributes:
  33. *@li output_dtype: An optional type from: int32, int64. Defaults to int64.
  34. *@li seed: An optional int. Defaults to 0.
  35. *@li seed2: An optional int. Defaults to 0 . \n
  36. *@par Outputs:
  37. *y_indices: A Tensor of type output_dtype . \n
  38. *@attention Constraints:
  39. *The implementation for Multinomial on Ascend uses AICPU, with bad performance.
  40. *@par Third-party framework compatibility
  41. *@li compatible with tensorflow Multinomial operator.
  42. */
  43. REG_OP(Multinomial)
  44. .INPUT(logits, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  45. .INPUT(num_samples, TensorType({DT_INT32}))
  46. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  47. .ATTR(dtype, Type, DT_INT64)
  48. .ATTR(seed, Int, 0)
  49. .ATTR(seed2, Int, 0)
  50. .OP_END_FACTORY_REG(Multinomial)
  51. /**
  52. *@brief Outputs random values from a normal distribution . \n
  53. *@par Inputs:
  54. *Inputs include:
  55. * @li shape: A Tensor. Must be one of the following types: int32, int64.
  56. The shape of the output tensor. Batches are indexed by the 0th dimension.
  57. * @li means: A Tensor. Must be one of the following types: half, bfloat16, float32, float64.
  58. * @li stdevs: A Tensor. Must have the same type as means.
  59. * @li min: A Tensor. Must have the same type as means. The minimum cutoff. May be -infinity.
  60. * @li max: A Tensor. Must have the same type as means . \n
  61. *@par Attributes:
  62. *@li seed: An optional int. Defaults to 0.
  63. *@li seed2: An optional int. Defaults to 0 . \n
  64. *@par Outputs:
  65. *y: A Tensor. Has the same type as means . \n
  66. *@attention Constraints:
  67. *The implementation for ParameterizedTruncatedNormal on Ascend uses AICPU, with bad performance.
  68. *@par Third-party framework compatibility
  69. *@li compatible with tensorflow ParameterizedTruncatedNormal operator.
  70. */
  71. REG_OP(ParameterizedTruncatedNormal)
  72. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  73. .INPUT(means, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  74. .INPUT(stdevs, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  75. .INPUT(min, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  76. .INPUT(max, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  77. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  78. .ATTR(seed, Int, 0)
  79. .ATTR(seed2, Int, 0)
  80. .OP_END_FACTORY_REG(ParameterizedTruncatedNormal)
  81. /**
  82. *@brief Computes the derivative of a Gamma random sample w.r.t. alpha . \n
  83. *@par Inputs:
  84. *Inputs include:
  85. * @li alpha: A Tensor. Must be one of the following types: float32, float64.
  86. * @li sample: A Tensor. Must have the same type as alpha . \n
  87. *@par Outputs:
  88. *y: A Tensor. Has the same type as alpha . \n
  89. *@attention Constraints:
  90. *The implementation for RandomGammaGrad on Ascend uses AICPU, with bad performance.
  91. *@par Third-party framework compatibility
  92. *@li compatible with tensorflow RandomGammaGrad operator.
  93. */
  94. REG_OP(RandomGammaGrad)
  95. .INPUT(alpha, TensorType({DT_FLOAT, DT_DOUBLE}))
  96. .INPUT(sample, TensorType({DT_FLOAT, DT_DOUBLE}))
  97. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
  98. .OP_END_FACTORY_REG(RandomGammaGrad)
  99. /**
  100. *@brief Outputs random values from the Gamma distribution(s) described by alpha . \n
  101. *@par Inputs:
  102. *Inputs include:
  103. * @li shape: A Tensor. Must be one of the following types: int32, int64. 1-D integer tensor.
  104. * @li alpha: A Tensor. Must be one of the following types: half, float32, float64 . \n
  105. *@par Attributes:
  106. *@li seed: An optional int. Defaults to 0.
  107. *@li seed2: An optional int. Defaults to 0 . \n
  108. *@par Outputs:
  109. *y: A Tensor. Has the same type as alpha . \n
  110. *@attention Constraints:
  111. *The implementation for RandomGamma on Ascend uses AICPU, with bad performance.
  112. *@par Third-party framework compatibility
  113. *@li compatible with tensorflow RandomGamma operator.
  114. */
  115. REG_OP(RandomGamma)
  116. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  117. .INPUT(alpha, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  118. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  119. .ATTR(seed, Int, 0)
  120. .ATTR(seed2, Int, 0)
  121. .OP_END_FACTORY_REG(RandomGamma)
  122. /**
  123. *@brief Outputs random values from the Poisson distribution(s) described by rate . \n
  124. *@par Inputs:
  125. *Inputs include:
  126. * @li shape: A Tensor. Must be one of the following types: int32, int64. 1-D integer tensor.
  127. * @li rate: A Tensor. Must be one of the following types: half, float32, float64, int32, int64 . \n
  128. *@par Attributes:
  129. *@li dtype: An optional type from: half, float32, float64, int32, int64. Defaults to int64.
  130. *@li seed: An optional int. Defaults to 0.
  131. *@li seed2: An optional int. Defaults to 0 . \n
  132. *@par Outputs:
  133. *y: A Tensor of type dtype . \n
  134. *@attention Constraints:
  135. *The implementation for RandomPoisson on Ascend uses AICPU, with bad performance.
  136. *@par Third-party framework compatibility
  137. *@li compatible with tensorflow RandomPoisson operator.
  138. */
  139. REG_OP(RandomPoisson)
  140. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  141. .INPUT(rate, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  142. DT_INT32, DT_INT64}))
  143. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  144. DT_INT32, DT_INT64}))
  145. .ATTR(dtype, Type, DT_INT64)
  146. .ATTR(seed, Int, 0)
  147. .ATTR(seed2, Int, 0)
  148. .OP_END_FACTORY_REG(RandomPoisson)
  149. /**
  150. *@brief Randomly shuffles a tensor along its first dimension . \n
  151. *@par Inputs:
  152. *Inputs include:
  153. *x: A Tensor. The tensor to be shuffled . \n
  154. *@par Attributes:
  155. *@li seed: An optional int. Defaults to 0.
  156. *@li seed2: An optional int. Defaults to 0 . \n
  157. *@par Outputs:
  158. *y: A Tensor. Has the same type as x . \n
  159. *@attention Constraints:
  160. *The implementation for RandomShuffle on Ascend uses AICPU, with bad performance.
  161. *@par Third-party framework compatibility
  162. *@li compatible with tensorflow RandomShuffle operator.
  163. */
  164. REG_OP(RandomShuffle)
  165. .INPUT(x, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16,
  166. DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64,
  167. DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  168. .OUTPUT(y, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16,
  169. DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64,
  170. DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  171. .ATTR(seed, Int, 0)
  172. .ATTR(seed2, Int, 0)
  173. .OP_END_FACTORY_REG(RandomShuffle)
  174. /**
  175. *@brief Outputs random values from a normal distribution . \n
  176. *@par Inputs:
  177. *Inputs include:
  178. *shape: A Tensor. Must be one of the following types: int32, int64. The shape of the output tensor . \n
  179. *@par Attributes:
  180. *@li dtype: A type from: half, float16, float32, float64. The type of the output.
  181. *@li seed: An optional int. Defaults to 0.
  182. *@li seed2: An optional int. Defaults to 0 . \n
  183. *@par Outputs:
  184. *y: A Tensor of type dtype . \n
  185. *@attention Constraints:
  186. *The implementation for RandomStandardNormal on Ascend uses AICPU, with bad performance.
  187. *@par Third-party framework compatibility
  188. *@li compatible with tensorflow RandomStandardNormal operator.
  189. */
  190. REG_OP(RandomStandardNormal)
  191. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  192. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  193. .REQUIRED_ATTR(dtype, Type)
  194. .ATTR(seed, Int, 0)
  195. .ATTR(seed2, Int, 0)
  196. .OP_END_FACTORY_REG(RandomStandardNormal)
  197. /**
  198. *@brief Outputs random integers from a uniform distribution . \n
  199. *@par Inputs:
  200. *Inputs include:
  201. * @li shape: A Tensor. Must be one of the following types: int32, int64. The shape of the output tensor.
  202. * @li min: A Tensor. Must be one of the following types: int32, int64. 0-D.
  203. * @li max: A Tensor. Must have the same type as minval. 0-D . \n
  204. *@par Attributes:
  205. *@li seed: An optional int. Defaults to 0.
  206. *@li seed2: An optional int. Defaults to 0 . \n
  207. *@par Outputs:
  208. *y: A Tensor. Has the same type as min . \n
  209. *@attention Constraints:
  210. *The implementation for RandomUniformInt on Ascend uses AICPU, with bad performance.
  211. *@par Third-party framework compatibility
  212. *@li compatible with tensorflow RandomUniformInt operator.
  213. */
  214. REG_OP(RandomUniformInt)
  215. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  216. .INPUT(min, TensorType({DT_INT32, DT_INT64}))
  217. .INPUT(max, TensorType({DT_INT32, DT_INT64}))
  218. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  219. .ATTR(seed, Int, 0)
  220. .ATTR(seed2, Int, 0)
  221. .OP_END_FACTORY_REG(RandomUniformInt)
  222. /**
  223. *@brief Outputs random values from a uniform distribution . \n
  224. *@par Inputs:
  225. *Inputs include:
  226. *shape: A Tensor. Must be one of the following types: int32, int64. The shape of the output tensor . \n
  227. *@par Attributes:
  228. *@li dtype: A type from: half, float16, float32, float64. The type of the output.
  229. *@li seed: An optional int. Defaults to 0.
  230. *@li seed2: An optional int. Defaults to 0 . \n
  231. *@par Outputs:
  232. *y: A Tensor of type dtype . \n
  233. *@attention Constraints:
  234. *The implementation for RandomUniform on Ascend uses AICPU, with bad performance.
  235. *@par Third-party framework compatibility
  236. *@li compatible with tensorflow RandomUniform operator.
  237. */
  238. REG_OP(RandomUniform)
  239. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  240. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  241. .REQUIRED_ATTR(dtype, Type)
  242. .ATTR(seed, Int, 0)
  243. .ATTR(seed2, Int, 0)
  244. .OP_END_FACTORY_REG(RandomUniform)
  245. /**
  246. *@brief Outputs random values from a truncated normal distribution . \n
  247. *@par Inputs:
  248. *Inputs include:
  249. *shape: A Tensor. Must be one of the following types: int32, int64 . \n
  250. *@par Attributes:
  251. *@li seed: An optional int. Defaults to 0.
  252. *@li seed2: An optional int. Defaults to 0 . \n
  253. *@par Outputs:
  254. *size: A Tensor of types: float16, float32, double . \n
  255. *@attention Constraints:
  256. *The implementation for TruncatedNormal on Ascend uses AICPU, with bad performance.
  257. *@par Third-party framework compatibility
  258. *@li compatible with tensorflow TruncatedNormal operator.
  259. */
  260. REG_OP(TruncatedNormal)
  261. .INPUT(shape, TensorType({ DT_INT32, DT_INT64 }))
  262. .OUTPUT(y, TensorType({ DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  263. .ATTR(seed, Int, 0)
  264. .ATTR(seed2, Int, 0)
  265. .OP_END_FACTORY_REG(TruncatedNormal)
  266. /**
  267. *@brief Generate random bit mask for dropout . \n
  268. *@par Inputs:
  269. include:
  270. *@li shape:The shape of the output tensor.
  271. *@li prob:0-D. Number of bit 1 . \n
  272. *@par Attributes:
  273. *@li seed:If either seed or seed2 are set to be non-zero, the random number
  274. *generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
  275. *@li seed2:A second seed to avoid seed collision . \n
  276. *@par Outputs:
  277. *y:Output (1-D) random number using uint data format . \n
  278. *@attention Constraints:
  279. *The output is aligned with 128 bits
  280. *@see DropOutGenMask()
  281. */
  282. REG_OP(DropOutGenMask)
  283. .INPUT(shape, TensorType({ DT_INT32, DT_INT64 }))
  284. .INPUT(prob, TensorType({ DT_FLOAT16, DT_FLOAT }))
  285. .OUTPUT(y, TensorType({ DT_UINT8 }))
  286. .ATTR(seed, Int, 0)
  287. .ATTR(seed2, Int, 0)
  288. .OP_END_FACTORY_REG(DropOutGenMask)
  289. /**
  290. *@brief Generate random uint8 mask for dropout v3 . \n
  291. *@par Inputs:
  292. include:
  293. *@li shape:The shape of the output tensor.
  294. *@li prob:0-D. Prob of 1 . \n
  295. *@par Attributes:
  296. *@li seed:If either seed or seed2 are set to be non-zero, the random number
  297. *generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
  298. *@li seed2:A second seed to avoid seed collision . \n
  299. *@par Outputs:
  300. *y:Output (1-D) random number using uint8 data format . \n
  301. *@attention Constraints:
  302. *The output is aligned with 16
  303. *@par Restrictions:
  304. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  305. *@see DropOutGenMaskV3()
  306. */
  307. REG_OP(DropOutGenMaskV3)
  308. .INPUT(shape, TensorType({ DT_INT32, DT_INT64 }))
  309. .INPUT(prob, TensorType({ DT_FLOAT16, DT_FLOAT }))
  310. .OUTPUT(y, TensorType({ DT_UINT8 }))
  311. .ATTR(seed, Int, 0)
  312. .ATTR(seed2, Int, 0)
  313. .OP_END_FACTORY_REG(DropOutGenMaskV3)
  314. /**
  315. *@brief Generates values in an interval . \n
  316. *@par Inputs:
  317. * Four ND inputs, including:
  318. *@li assist: A 1D Tensor of type float32.
  319. *@li start: A 1D Tensor of type float32, for the first entry in the range.
  320. *@li stop: A 1D Tensor of type float32, for the last entry in the range.
  321. *@li num: A 1D Tensor of type int32 or int64, for the common difference of the entries . \n
  322. *@par Outputs:
  323. *output_op: A 1D Tensor of type float32 . \n
  324. *@attention Constraints:
  325. * "input_assist" is a sequence of "input_num" evenly-spaced values beginning at 0 with an common difference of 1 . \n
  326. *@par Third-party framework compatibility
  327. * Compatible with the TensorFlow operator lin_space.
  328. *
  329. * @par Restrictions:
  330. * Warning: THIS FUNCTION IS DEPRECATED. Please use LinSpace instead.
  331. */
  332. REG_OP(LinSpaceD)
  333. .INPUT(assist, TensorType({DT_FLOAT}))
  334. .INPUT(start, TensorType({DT_FLOAT}))
  335. .INPUT(stop, TensorType({DT_FLOAT}))
  336. .INPUT(num, TensorType::IndexNumberType())
  337. .OUTPUT(output, TensorType({DT_FLOAT}))
  338. .OP_END_FACTORY_REG(LinSpaceD)
  339. /**
  340. *@brief Generates values in an interval . \n
  341. *@par Inputs:
  342. * Four ND inputs, including:
  343. *@li start: A 1D Tensor of type float32, for the first entry in the range.
  344. *@li stop: A 1D Tensor of type float32, for the last entry in the range.
  345. *@li num: A 1D Tensor of type int32 or int64, for the common difference of the entries . \n
  346. *@par Outputs:
  347. *output_op: A 1D Tensor of type float32 . \n
  348. *@attention Constraints:
  349. * "input_assist" is a sequence of "input_num" evenly-spaced values beginning at 0 with an common difference of 1 . \n
  350. *@par Third-party framework compatibility
  351. * Compatible with the TensorFlow operator lin_space.
  352. */
  353. REG_OP(LinSpace)
  354. .INPUT(start, TensorType({DT_FLOAT, DT_DOUBLE}))
  355. .INPUT(stop, TensorType({DT_FLOAT, DT_DOUBLE}))
  356. .INPUT(num, TensorType::IndexNumberType())
  357. .OUTPUT(output, TensorType({DT_FLOAT, DT_DOUBLE}))
  358. .OP_END_FACTORY_REG(LinSpace)
  359. /**
  360. *@brief The dropout operator randomly sets (according to the given dropout probability)
  361. *the outputs of some units to zero, while others are remain unchanged. . \n
  362. *@par Inputs:
  363. *One input, including:
  364. *@li x:The input tensor variable. The data type is float32. \n
  365. *@par Attributes:
  366. *@li dropout_ratio:Float between 0 and 1. Fraction of the input units to drop.Defaults to "0.5".
  367. *@li scale_train: Bool,default to true.
  368. *@li alpha: An optional float32. A scaling factor. Defaults to "1.0".
  369. *@li beta: An optional float32. An exponent. Defaults to "0.0". \n
  370. *@par Outputs:
  371. *y: A Variable holding Tensor representing the dropout, has same shape and data type with x. \n
  372. */
  373. REG_OP(Dropout)
  374. .INPUT(x, TensorType{DT_FLOAT})
  375. .OUTPUT(y, TensorType{DT_FLOAT})
  376. .ATTR(dropout_ratio, Float, 0.5)
  377. .ATTR(scale_train, Bool, true)
  378. .ATTR(alpha, Float, 1.0)
  379. .ATTR(beta, Float, 0.0)
  380. .OP_END_FACTORY_REG(Dropout)
  381. /**
  382. *@brief Shuffle index of no-zero element . \n
  383. *@par Inputs:
  384. include:
  385. *x:A tensor <= 5-D . \n
  386. *@par Attributes:
  387. *@li count:the count of output, if 0, out all no-zero elements.
  388. *@li seed:If either seed or seed2 are set to be non-zero, the random number generator is seeded by the given seed.
  389. Otherwise, it is seeded by a random seed.
  390. *@li seed2:A second seed to avoid seed collision . \n
  391. *@par Outputs:
  392. *@li y:2-D tensor, no-zero element index.
  393. *@li mask:1-D, whether the corresponding index is valid . \n
  394. *@see RandomChoiceWithMask()
  395. */
  396. REG_OP(RandomChoiceWithMask)
  397. .INPUT(x, TensorType({DT_BOOL}))
  398. .OUTPUT(y, TensorType({DT_INT32}))
  399. .OUTPUT(mask, TensorType({DT_BOOL}))
  400. .ATTR(count, Int, 0)
  401. .ATTR(seed, Int, 0)
  402. .ATTR(seed2, Int, 0)
  403. .OP_END_FACTORY_REG(RandomChoiceWithMask)
  404. /**
  405. *@brief Permutes data in the channel dimension of the input
  406. *@par Inputs:
  407. *Inputs including:
  408. * @li x: A required Tensor. Must be one of the following types:
  409. float16, float32, int8, uint8, int16, uint16, int32, uint32, int64, uint64 . \n
  410. *@par Attributes:
  411. *@li group: A required int32, specifying the number of groups to split the channel dimension into. Defaults to "1" . \n
  412. *@par Outputs:
  413. *y: A required Tensor. Has same type and shape as "x". Must be one of the following types:
  414. float16, float32, int8, uint8, int16, uint16, int32, uint32, int64, uint64 . \n
  415. *@attention Constraints:
  416. *@li "group" must be greater than 0 and must evenly divide the channel dimension size.
  417. *@li The format of input "x" must be NCHW.
  418. *@par Third-party framework compatibility
  419. * Compatible with the Caffe operator ShuffleChannel.
  420. */
  421. REG_OP(ShuffleChannel)
  422. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT8, DT_UINT8, DT_INT16,
  423. DT_UINT16, DT_INT32, DT_UINT32,DT_INT64,DT_UINT64}))
  424. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT8, DT_UINT8, DT_INT16,
  425. DT_UINT16, DT_INT32, DT_UINT32,DT_INT64,DT_UINT64}))
  426. .ATTR(group, Int, 1)
  427. .OP_END_FACTORY_REG(ShuffleChannel)
  428. /**
  429. * @briefGenerate a tensor of samples from a multinomial
  430. * distribution according to the probabilities of each of
  431. * the possible outcomes.
  432. *
  433. * @par inputs
  434. * one input including:
  435. * @li x:Input tensor with shape [batch_size, class_size],
  436. * where class_size is the number of all possible outcomes.
  437. * Each value along the axis zero represents the unnormalized
  438. * log-probability of each corresponding outcome in a batch.
  439. *
  440. * @par output
  441. * one output including:
  442. * @li y:Output tensor with shape [batch_size, sample_size],
  443. * where sample_size is the number of times to sample.
  444. * Each value along the axis zero represents the outcome of
  445. * the corresponding sample in a batch.
  446. *
  447. * @par Restrictions:
  448. * Warning:THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  449. */
  450. REG_OP(MultinomialFuss)
  451. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_FLOAT64}))
  452. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  453. .ATTR(dtype, Int, 6)
  454. .ATTR(sample_size, Int, 1)
  455. .ATTR(seed, Float, 0)
  456. .OP_END_FACTORY_REG(MultinomialFuss)
  457. /**
  458. * @brief During training, randomly zeroes some of the elements of the input tensor
  459. * with probability
  460. *
  461. * @par Inputs:
  462. * @li x: A ND Tensor. Must be one of the following data types: Float, Float16
  463. * @li seed: A ND Tensor. Must be one of the following data types: Float
  464. *
  465. * @par Attributes:
  466. * @li p: probability of an element to be zeroed
  467. *
  468. * @par Outputs:
  469. * @li y: A tensor with the same shape and type as "x".
  470. * @li mask: A tensor with the same shape and type as "x".
  471. * @li new_seed: A tensor with the same shape and type as "seed".
  472. */
  473. REG_OP(DropoutV2)
  474. .INPUT(x, TensorType({ DT_FLOAT16, DT_FLOAT }))
  475. .INPUT(seed, TensorType({ DT_FLOAT }))
  476. .OUTPUT(y, TensorType({ DT_FLOAT16, DT_FLOAT }))
  477. .OUTPUT(mask, TensorType({ DT_FLOAT }))
  478. .OUTPUT(seed, TensorType({ DT_FLOAT }))
  479. .REQUIRED_ATTR(p, Float)
  480. .OP_END_FACTORY_REG(DropoutV2)
  481. } // namespace ge
  482. #endif // OPS_BUILT_IN_OP_PROTO_INC_RANDOM_OPS_H_

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