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.

test_ops.py 54 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """ test ops """
  16. import functools
  17. import numpy as np
  18. import mindspore.nn as nn
  19. import mindspore.ops.composite as C
  20. from mindspore import Tensor
  21. from mindspore import ops, Parameter, context
  22. from mindspore.common import dtype as mstype
  23. from mindspore.ops import functional as F
  24. from mindspore.ops import operations as P
  25. from mindspore.ops.operations import _grad_ops as G
  26. from ..ut_filter import non_graph_engine
  27. from ....mindspore_test_framework.mindspore_test import mindspore_test
  28. from ....mindspore_test_framework.pipeline.forward.compile_forward \
  29. import (pipeline_for_compile_forward_ge_graph_for_case_by_case_config,
  30. pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  31. from ....mindspore_test_framework.pipeline.gradient.compile_gradient \
  32. import pipeline_for_compile_grad_ge_graph_for_case_by_case_config
  33. class InputBackward(nn.Cell):
  34. def __init__(self, network):
  35. super(InputBackward, self).__init__()
  36. self.network = network
  37. self.network.set_train()
  38. self.grad = C.grad_all_with_sens
  39. def construct(self, x1, x2, x3, sens):
  40. return self.grad(self.network)(x1, x2, x3, sens)
  41. class NetForTupleInput(nn.Cell):
  42. def __init__(self, op):
  43. super(NetForTupleInput, self).__init__()
  44. self.op = op
  45. def construct(self, x1, x2):
  46. return self.op((x1, x2))
  47. class StridedSlicessdNet(nn.Cell):
  48. def __init__(self):
  49. super(StridedSlicessdNet, self).__init__()
  50. self.rank = P.Rank()
  51. def construct(self, x1):
  52. return P.StridedSlice(1, 1, 0, self.rank(x1), 0)(x1, (0, 0), (0, 0), (1, 1))
  53. class NetForConcat(nn.Cell):
  54. def __init__(self):
  55. super(NetForConcat, self).__init__()
  56. self.concat = P.Concat()
  57. def construct(self, x1):
  58. return self.concat((x1, x1))
  59. class NetForConcat1(nn.Cell):
  60. def __init__(self):
  61. super(NetForConcat1, self).__init__()
  62. self.concat = P.Concat()
  63. def construct(self, x1, x2):
  64. return self.concat((x1, x2))
  65. class NetForPackInput(nn.Cell):
  66. def __init__(self, op):
  67. super(NetForPackInput, self).__init__()
  68. self.op = op
  69. self.mul = P.Mul()
  70. def construct(self, *args):
  71. t = ()
  72. for element in args:
  73. t = t + (self.mul(element, element),)
  74. return self.op(t)
  75. class NetForUnpackInput(nn.Cell):
  76. def __init__(self, op):
  77. super(NetForUnpackInput, self).__init__()
  78. self.op = op
  79. self.mul = P.Mul()
  80. def construct(self, x1):
  81. return self.op((self.mul(x1, x1)))
  82. class NetForFlatten(nn.Cell):
  83. def __init__(self):
  84. super(NetForFlatten, self).__init__()
  85. self.flatten = P.Flatten()
  86. def construct(self, x, y):
  87. return self.flatten(x) + y
  88. class NetForFlatten0D(nn.Cell):
  89. def __init__(self):
  90. super(NetForFlatten0D, self).__init__()
  91. self.flatten = P.Flatten()
  92. def construct(self, x):
  93. return self.flatten(x)
  94. class NetForFlattenComposed(nn.Cell):
  95. # make flatten op together with other ops for testing flatten grad
  96. def __init__(self):
  97. super(NetForFlattenComposed, self).__init__()
  98. self.flatten = P.Flatten()
  99. def construct(self, x, y):
  100. return self.flatten(x+x) + y
  101. class ArgmaxNet(nn.Cell):
  102. def __init__(self):
  103. super(ArgmaxNet, self).__init__()
  104. self.argmax = P.Argmax(axis=1)
  105. def construct(self, input_):
  106. return self.argmax(input_)
  107. class ArgminNet(nn.Cell):
  108. def __init__(self):
  109. super(ArgminNet, self).__init__()
  110. self.argmin = P.Argmin(axis=1)
  111. def construct(self, input_):
  112. return self.argmin(input_)
  113. class CumSumNet(nn.Cell):
  114. def __init__(self):
  115. super(CumSumNet, self).__init__()
  116. self.cumsum = P.CumSum()
  117. self.axis = 1
  118. def construct(self, input_):
  119. return self.cumsum(input_, self.axis)
  120. class SummaryNet(nn.Cell):
  121. def __init__(self):
  122. super(SummaryNet, self).__init__()
  123. self.s = P.ScalarSummary()
  124. self.add = P.TensorAdd()
  125. def construct(self, x, y):
  126. self.s("x1", x)
  127. return self.add(x, y)
  128. class HistogramSummaryNet(nn.Cell):
  129. def __init__(self):
  130. super(HistogramSummaryNet, self).__init__()
  131. self.summary = P.HistogramSummary()
  132. self.add = P.TensorAdd()
  133. def construct(self, x, y):
  134. out = self.add(x, y)
  135. string_in = "out"
  136. self.summary(string_in, out)
  137. return out
  138. class ScatterMax(nn.Cell):
  139. """ScatterMax net definition"""
  140. def __init__(self):
  141. super(ScatterMax, self).__init__()
  142. self.scatter_max = P.ScatterMax()
  143. self.ref = Parameter(Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], np.float32)), name="ref")
  144. def construct(self, indices, updates):
  145. out = self.scatter_max(self.ref, indices, updates)
  146. return out
  147. class ScatterAdd(nn.Cell):
  148. """ScatterAdd net definition"""
  149. def __init__(self, ref_shape):
  150. super(ScatterAdd, self).__init__()
  151. self.scatter_add = P.ScatterAdd()
  152. self.ref = Parameter(Tensor(np.ones(ref_shape, np.float32)), name="ref")
  153. def construct(self, indices, updates):
  154. out = self.scatter_add(self.ref, indices, updates)
  155. return out
  156. class ApplyFtrlNet(nn.Cell):
  157. def __init__(self):
  158. super(ApplyFtrlNet, self).__init__()
  159. self.apply_ftrl = P.ApplyFtrl()
  160. self.lr = 0.001
  161. self.l1 = 0.0
  162. self.l2 = 0.0
  163. self.lr_power = -0.5
  164. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  165. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  166. self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")
  167. def construct(self, grad):
  168. out = self.apply_ftrl(self.var, self.accum, self.linear, grad, self.lr, self.l1, self.l2, self.lr_power)
  169. return out
  170. class ApplyRMSNet(nn.Cell):
  171. def __init__(self):
  172. super(ApplyRMSNet, self).__init__()
  173. self.apply_rms = P.ApplyRMSProp()
  174. self.lr = 0.001
  175. self.rho = 0.0
  176. self.momentum = 0.0
  177. self.epsilon = 1e-10
  178. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  179. self.ms = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="ms")
  180. self.moment = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="moment")
  181. def construct(self, grad):
  182. out = self.apply_rms(self.var, self.ms, self.moment, self.lr, grad, self.rho, self.momentum, self.epsilon)
  183. return out
  184. test_case_math_ops = [
  185. ('BitwiseAnd', {
  186. 'block': P.BitwiseAnd(),
  187. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  188. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  189. 'skip': ['backward']}),
  190. ('BitwiseAnd_1', {
  191. 'block': P.BitwiseAnd(),
  192. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  193. Tensor(np.array([1, 1, 1]), mstype.int16)],
  194. 'skip': ['backward']}),
  195. ('BitwiseOr', {
  196. 'block': P.BitwiseOr(),
  197. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  198. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  199. 'skip': ['backward']}),
  200. ('BitwiseOr_1', {
  201. 'block': P.BitwiseOr(),
  202. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  203. Tensor(np.array([1, 1, 1]), mstype.int16)],
  204. 'skip': ['backward']}),
  205. ('BitwiseXor', {
  206. 'block': P.BitwiseXor(),
  207. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  208. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  209. 'skip': ['backward']}),
  210. ('BitwiseXor_1', {
  211. 'block': P.BitwiseXor(),
  212. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  213. Tensor(np.array([1, 1, 1]), mstype.int16)],
  214. 'skip': ['backward']}),
  215. ('Neg', {
  216. 'block': P.Neg(),
  217. 'desc_inputs': [[1, 3, 4, 4]],
  218. 'desc_bprop': [[1, 3, 4, 4]]}),
  219. ('Sub', {
  220. 'block': P.Sub(),
  221. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  222. 'desc_bprop': [[2, 3, 3, 5]]}),
  223. ('TensorAdd', {
  224. 'block': P.TensorAdd(),
  225. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  226. 'desc_bprop': [[2, 3, 3, 5]]}),
  227. ('Mul0', {
  228. 'block': P.Mul(),
  229. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  230. 'desc_bprop': [[2, 3, 3, 5]]}),
  231. ('Mul1', {
  232. 'block': P.Mul(),
  233. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  234. 'desc_bprop': [[2, 3, 3, 5]]}),
  235. ('Mul2', {
  236. 'block': P.Mul(),
  237. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  238. 'desc_bprop': [[2, 3, 3, 5]],
  239. 'skip': ['backward']}),
  240. ('Mul3', {
  241. 'block': P.Mul(),
  242. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  243. 'desc_bprop': [[2, 3, 3, 5]],
  244. 'skip': ['backward']}),
  245. ('Mul4', {
  246. 'block': P.Mul(),
  247. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  248. 'desc_bprop': [[2, 3, 3, 5]],
  249. 'skip': ['backward']}),
  250. ('Add0', {
  251. 'block': P.TensorAdd(),
  252. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  253. 'desc_bprop': [[2, 3, 3, 5]]}),
  254. ('Add1', {
  255. 'block': P.TensorAdd(),
  256. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  257. 'desc_bprop': [[2, 3, 3, 5]],
  258. 'skip': ['backward']}),
  259. ('Add2', {
  260. 'block': P.TensorAdd(),
  261. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  262. 'desc_bprop': [[2, 3, 3, 5]],
  263. 'skip': ['backward']}),
  264. ('Add3', {
  265. 'block': P.TensorAdd(),
  266. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  267. 'desc_bprop': [[2, 3, 3, 5]],
  268. 'skip': ['backward']}),
  269. ('Add4', {
  270. 'block': P.TensorAdd(),
  271. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  272. 'desc_bprop': [[2, 3, 3, 5]],
  273. 'skip': ['backward']}),
  274. ('Minimum', {
  275. 'block': P.Minimum(),
  276. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  277. 'desc_bprop': [[2, 3, 3, 5]]}),
  278. ('Pow_0', {
  279. 'block': P.Pow(),
  280. 'desc_const': [2.0],
  281. 'desc_inputs': [[2, 3, 3, 5]],
  282. 'desc_bprop': [[2, 3, 3, 5]]}),
  283. ('Pow_1', {
  284. 'block': P.Pow(),
  285. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  286. 'desc_bprop': [[2, 3, 3, 5]]}),
  287. ('Exp', {
  288. 'block': P.Exp(),
  289. 'desc_inputs': [[2, 3]],
  290. 'desc_bprop': [[2, 3]]}),
  291. ('Expm1', {
  292. 'block': P.Expm1(),
  293. 'desc_inputs': [[2, 3]],
  294. 'desc_bprop': [[2, 3]]}),
  295. ('Erf', {
  296. 'block': P.Erf(),
  297. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  298. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  299. ('Floor', {
  300. 'block': P.Floor(),
  301. 'desc_inputs': [[2, 512, 56, 56]],
  302. 'desc_bprop': [[2, 512, 56, 56]],
  303. 'skip': ['backward']}),
  304. ('ACos', {
  305. 'block': P.ACos(),
  306. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  307. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  308. ('ACosGrad', {
  309. 'block': G.ACosGrad(),
  310. 'desc_inputs': [[2, 3], [2, 3]],
  311. 'skip': ['backward']}),
  312. ('Acosh', {
  313. 'block': P.Acosh(),
  314. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  315. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  316. ('AcoshGrad', {
  317. 'block': G.AcoshGrad(),
  318. 'desc_inputs': [[2, 3], [2, 3]],
  319. 'skip': ['backward']}),
  320. ('Sin', {
  321. 'block': P.Sin(),
  322. 'desc_inputs': [[2, 3]],
  323. 'desc_bprop': [[2, 3]]}),
  324. ('Asin', {
  325. 'block': P.Asin(),
  326. 'desc_inputs': [[2, 3]],
  327. 'desc_bprop': [[2, 3]]}),
  328. ('Asinh', {
  329. 'block': P.Asinh(),
  330. 'desc_inputs': [[3, 4, 5]],
  331. 'desc_bprop': [[3, 4, 5]]}),
  332. ('Reciprocal', {
  333. 'block': P.Reciprocal(),
  334. 'desc_inputs': [[2, 3, 3, 5]],
  335. 'desc_bprop': [[2, 3, 3, 5]]}),
  336. ('Minimum_0', {
  337. 'block': P.Minimum(),
  338. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  339. 'desc_bprop': [[2, 3, 3, 5]]}),
  340. ('Maximum', {
  341. 'block': P.Maximum(),
  342. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  343. 'desc_bprop': [[2, 3, 3, 5]]}),
  344. ('Maximum_0', {
  345. 'block': P.Maximum(),
  346. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  347. 'desc_bprop': [[2, 3, 3, 5]]}),
  348. ('MaximumGrad', {
  349. 'block': G.MaximumGrad(),
  350. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  351. 'skip': ['backward']}),
  352. ('MinimumGrad', {
  353. 'block': G.MinimumGrad(),
  354. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  355. 'skip': ['backward']}),
  356. ('StridedSlice', {
  357. 'block': P.StridedSlice(),
  358. 'desc_const': [(0, 1, 2, 1),
  359. (2, 3, 3, 4),
  360. (1, 1, 1, 1)],
  361. 'desc_inputs': [[2, 3, 3, 5]],
  362. 'desc_bprop': [[2, 2, 1, 3]]}),
  363. ('Slice_1', {
  364. 'block': P.Slice(),
  365. 'desc_const': [(0, 1, 2, 1),
  366. (1, 1, 1, 2)],
  367. 'desc_inputs': [[2, 3, 3, 5]],
  368. 'desc_bprop': [[1, 1, 1, 2]]}),
  369. ('StridedSliceGrad', {
  370. 'block': G.StridedSliceGrad(),
  371. 'desc_const': [(64, 1, 1024),
  372. (0, 1, 0),
  373. (64, 2, 1024),
  374. (1, 1, 1)],
  375. 'desc_inputs': [[64, 128, 1024]],
  376. 'skip': ['backward']}),
  377. ('RandomChoiceWithMask', {
  378. 'block': P.RandomChoiceWithMask(256),
  379. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  380. 'desc_bprop': [[256, 4], [256, 4]],
  381. 'skip': ['backward']}),
  382. ('LessEqual', {
  383. 'block': P.LessEqual(),
  384. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  385. Tensor(np.random.rand(4).astype(np.float16))],
  386. 'skip': ['backward']}),
  387. ('Less', {
  388. 'block': P.Less(),
  389. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  390. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  391. 'skip': ['backward']}),
  392. ('RealDiv_0', {
  393. 'block': P.RealDiv(),
  394. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  395. 'desc_inputs': [],
  396. 'skip': ['backward']}),
  397. ('RealDiv', {
  398. 'block': P.RealDiv(),
  399. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  400. 'desc_bprop': [[4]]}),
  401. ('RealDiv_1', {
  402. 'block': P.RealDiv(),
  403. 'desc_inputs': [[512, 1024], [512, 1024]],
  404. 'desc_bprop': [[512, 1024]]}),
  405. ('FloorDiv', {
  406. 'block': P.FloorDiv(),
  407. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  408. Tensor(np.random.rand(4).astype(np.float16))],
  409. 'skip': ['backward']}),
  410. ('FloorMod', {
  411. 'block': P.FloorMod(),
  412. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  413. 'desc_bprop': [[2, 3, 4, 5]]}),
  414. ('identity', {
  415. 'block': ops.functional.identity,
  416. 'desc_inputs': [[2, 2]],
  417. 'skip': ['backward']}),
  418. ('MatMul_1', {
  419. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  420. 'desc_inputs': [[1024, 160], [160, 1024]],
  421. 'desc_bprop': [[1024, 1024]]}),
  422. ('MatMul_2', {
  423. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  424. 'desc_inputs': [[160, 1024], [1024, 160]],
  425. 'desc_bprop': [[1024, 1024]]}),
  426. ('Sub', {
  427. 'block': P.Sub(),
  428. 'desc_inputs': [[3], [3]],
  429. 'desc_bprop': [[3]]}),
  430. ('TruncatedNormal', {
  431. 'block': P.TruncatedNormal(),
  432. 'desc_const': [(1, 2, 3)],
  433. 'desc_inputs': [],
  434. 'skip': ['backward'],
  435. 'add_fake_input': True}),
  436. ('Select', {
  437. 'block': P.Select(),
  438. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  439. [2, 3], [2, 3]],
  440. 'desc_bprop': [[2, 3]]}),
  441. ('Rank', {
  442. 'block': P.Rank(),
  443. 'desc_inputs': [[2, 3]],
  444. 'skip': ['backward']}),
  445. ('InvertPermutation', {
  446. 'block': P.InvertPermutation(),
  447. 'desc_const': [(0, 3, 1, 2)],
  448. 'desc_inputs': [],
  449. 'skip': ['backward']}),
  450. ('Square', {
  451. 'block': P.Square(),
  452. 'desc_inputs': [[4]],
  453. 'desc_bprop': [[4]]}),
  454. ('Rsqrt', {
  455. 'block': P.Rsqrt(),
  456. 'desc_inputs': [[4]],
  457. 'desc_bprop': [[4]]}),
  458. ('Sqrt', {
  459. 'block': P.Sqrt(),
  460. 'desc_inputs': [[4]],
  461. 'desc_bprop': [[4]]}),
  462. ('RealDiv', {
  463. 'block': P.RealDiv(),
  464. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  465. 'desc_bprop': [[2, 3, 4, 5]]}),
  466. ('Div', {
  467. 'block': P.Div(),
  468. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  469. 'desc_bprop': [[2, 3, 4, 5]]}),
  470. ('Equal', {
  471. 'block': P.Equal(),
  472. 'desc_inputs': [[3, 4, 5], [4, 5]],
  473. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  474. ('NotEqual', {
  475. 'block': P.NotEqual(),
  476. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  477. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  478. ('NotEqual_0', {
  479. 'block': P.NotEqual(),
  480. 'desc_inputs': [1, [2, 3, 4, 5]],
  481. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  482. 'skip': ['backward']}),
  483. ('Greater', {
  484. 'block': P.Greater(),
  485. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  486. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  487. ('GreaterEqual', {
  488. 'block': P.GreaterEqual(),
  489. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  490. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  491. ('LogicalNot', {
  492. 'block': P.LogicalNot(),
  493. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  494. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  495. ('LogicalAnd', {
  496. 'block': P.LogicalAnd(),
  497. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  498. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  499. ('LogicalOr', {
  500. 'block': P.LogicalOr(),
  501. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  502. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  503. ('NpuAllocFloatStatus', {
  504. 'block': P.NPUAllocFloatStatus(),
  505. 'desc_inputs': [],
  506. 'add_fack_input': True,
  507. 'fack_input_type': np.float32,
  508. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  509. 'skip': ['backward']}),
  510. ('NpuGetFloatStatus', {
  511. 'block': P.NPUGetFloatStatus(),
  512. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  513. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  514. 'skip': ['backward']}),
  515. ('NpuClearFloatStatus', {
  516. 'block': P.NPUClearFloatStatus(),
  517. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  518. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  519. 'skip': ['backward']}),
  520. ('CheckValid', {
  521. 'block': P.CheckValid(),
  522. 'desc_inputs': [[20000, 4], [3]],
  523. 'desc_bprop': [[20000]],
  524. 'skip': ['backward']}),
  525. ('NMSWithMask', {
  526. 'block': P.NMSWithMask(0.5),
  527. 'desc_inputs': [[128, 5]],
  528. 'desc_bprop': [[128, 5], [128], [128]],
  529. 'skip': ['backward']}),
  530. ('Abs', {
  531. 'block': P.Abs(),
  532. 'desc_inputs': [[4]],
  533. 'desc_bprop': [[4]]}),
  534. ('CumSum', {
  535. 'block': CumSumNet(),
  536. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  537. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  538. [1, 3, 7, 9]]).astype(np.float32))]}),
  539. ('ReduceSum_3', {
  540. 'block': P.ReduceSum(),
  541. 'desc_const': [0],
  542. 'desc_inputs': [[3, 2]],
  543. 'desc_bprop': [[2]]}),
  544. ('ReduceSum_4', {
  545. 'block': P.ReduceSum(keep_dims=True),
  546. 'desc_const': [0],
  547. 'desc_inputs': [[3, 2]],
  548. 'desc_bprop': [[1, 2]]}),
  549. ('ReduceSum_5', {
  550. 'block': P.ReduceSum(keep_dims=True),
  551. 'desc_inputs': [[2, 3, 4]],
  552. 'desc_bprop': [[1, 1, 1]]}),
  553. ('ReduceSum_6', {
  554. 'block': P.ReduceSum(),
  555. 'desc_inputs': [[2, 3, 4]],
  556. 'desc_bprop': [[1]]}),
  557. ('Sum_0', {
  558. 'block': P.ReduceSum(),
  559. 'desc_const': [(1,)],
  560. 'desc_inputs': [[3, 2]],
  561. 'desc_bprop': [[3]]}),
  562. ('Sum_1', {
  563. 'block': P.ReduceSum(keep_dims=True),
  564. 'desc_const': [(1,)],
  565. 'desc_inputs': [[3, 2]],
  566. 'desc_bprop': [[3, 1]]}),
  567. ('Sum_2', {
  568. 'block': P.ReduceSum(),
  569. 'desc_const': [(0, 1)],
  570. 'desc_inputs': [[3, 2]],
  571. 'desc_bprop': [[1]]}),
  572. ('Sum_3', {
  573. 'block': P.ReduceSum(),
  574. 'desc_const': [0],
  575. 'desc_inputs': [[3, 2]],
  576. 'desc_bprop': [[2]]}),
  577. ('Sum_4', {
  578. 'block': P.ReduceSum(keep_dims=True),
  579. 'desc_const': [0],
  580. 'desc_inputs': [[3, 2]],
  581. 'desc_bprop': [[1, 2]]}),
  582. ('Sum_5', {
  583. 'block': P.ReduceSum(keep_dims=True),
  584. 'desc_const': [()],
  585. 'desc_inputs': [[2, 3, 4]],
  586. 'desc_bprop': [[1, 1, 1]]}),
  587. ('Sum_6', {
  588. 'block': P.ReduceSum(),
  589. 'desc_const': [()],
  590. 'desc_inputs': [[2, 3, 4]],
  591. 'desc_bprop': [[1]]}),
  592. ('Sign', {
  593. 'block': P.Sign(),
  594. 'desc_inputs': [[3]],
  595. 'desc_bprop': [[3]]}),
  596. ('Round', {
  597. 'block': P.Round(),
  598. 'desc_inputs': [[3]],
  599. 'desc_bprop': [[3]]}),
  600. ('Atan2', {
  601. 'block': P.Atan2(),
  602. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  603. Tensor(np.array([1, 1]).astype(np.float32))],
  604. 'desc_bprop': [[2]]}),
  605. ('SquareSumAll', {
  606. 'block': P.SquareSumAll(),
  607. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  608. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  609. 'skip': ['backward']}),
  610. ('Cos', {
  611. 'block': P.Cos(),
  612. 'desc_inputs': [[2, 3]],
  613. 'desc_bprop': [[2, 3]]}),
  614. ('ReduceAll', {
  615. 'block': P.ReduceAll(),
  616. 'desc_const': [1],
  617. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  618. 'desc_bprop': []}),
  619. ('BesselI0e', {
  620. 'block': P.BesselI0e(),
  621. 'desc_inputs': [[2, 3]],
  622. 'desc_bprop': [[2, 3]]}),
  623. ('BesselI1e', {
  624. 'block': P.BesselI1e(),
  625. 'desc_inputs': [[2, 3]],
  626. 'desc_bprop': [[2, 3]]}),
  627. ('Atan', {
  628. 'block': P.Atan(),
  629. 'desc_inputs': [[2, 3]],
  630. 'desc_bprop': [[2, 3]]}),
  631. ('AtanGrad', {
  632. 'block': G.AtanGrad(),
  633. 'desc_inputs': [[2, 3], [2, 3]],
  634. 'skip': ['backward']}),
  635. ('Atanh', {
  636. 'block': P.Atanh(),
  637. 'desc_inputs': [[2, 3]],
  638. 'desc_bprop': [[2, 3]]}),
  639. ]
  640. test_case_nn_ops = [
  641. ('BiasAdd', {
  642. 'block': P.BiasAdd(),
  643. 'desc_inputs': [[1, 3, 3, 3], [3]],
  644. 'desc_bprop': [[1, 3, 3, 3]]}),
  645. ('BiasAddGrad', {
  646. 'block': G.BiasAddGrad(),
  647. 'desc_inputs': [[1, 3, 3, 3]],
  648. 'skip': ['backward']}),
  649. ('Gelu', {
  650. 'block': P.Gelu(),
  651. 'desc_inputs': [[1, 3, 4, 4]],
  652. 'desc_bprop': [[1, 3, 4, 4]]}),
  653. ('GeluGrad', {
  654. 'block': G.GeluGrad(),
  655. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  656. 'desc_bprop': [[2, 2]],
  657. 'skip': ['backward']}),
  658. ('Tanh', {
  659. 'block': P.Tanh(),
  660. 'desc_inputs': [[1, 3, 4, 4]],
  661. 'desc_bprop': [[1, 3, 4, 4]]}),
  662. ('TanhGrad', {
  663. 'block': G.TanhGrad(),
  664. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  665. 'desc_bprop': [[1, 3, 4, 4]],
  666. 'skip': ['backward']}),
  667. ('ReLU', {
  668. 'block': P.ReLU(),
  669. 'desc_inputs': [[1, 3, 4, 4]],
  670. 'desc_bprop': [[1, 3, 4, 4]]}),
  671. ('ReLU6', {
  672. 'block': P.ReLU6(),
  673. 'desc_inputs': [[1, 3, 4, 4]],
  674. 'desc_bprop': [[1, 3, 4, 4]]}),
  675. ('ReLUV2', {
  676. 'block': P.ReLUV2(),
  677. 'desc_inputs': [[1, 3, 4, 4]],
  678. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  679. ('ReLUGrad', {
  680. 'block': G.ReluGrad(),
  681. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  682. 'skip': ['backward']}),
  683. ('Softplus', {
  684. 'block': P.Softplus(),
  685. 'desc_inputs': [[1, 3, 4, 4]],
  686. 'desc_bprop': [[1, 3, 4, 4]]}),
  687. ('SoftplusGrad', {
  688. 'block': G.SoftplusGrad(),
  689. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  690. 'skip': ['backward']}),
  691. ('Elu', {
  692. 'block': P.Elu(),
  693. 'desc_inputs': [[2, 3, 4]],
  694. 'desc_bprop': [[2, 3, 4]]}),
  695. ('EluGrad', {
  696. 'block': G.EluGrad(),
  697. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  698. 'desc_bprop': [[2, 3, 4]],
  699. 'skip': ['backward']}),
  700. ('Sigmoid', {
  701. 'block': P.Sigmoid(),
  702. 'desc_inputs': [[1, 3, 4, 4]],
  703. 'desc_bprop': [[1, 3, 4, 4]]}),
  704. ('MaxPool', {
  705. 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  706. 'desc_inputs': [[100, 3, 28, 28]],
  707. 'desc_bprop': [[100, 3, 14, 14]]}),
  708. ('MaxPoolGrad', {
  709. 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  710. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  711. 'desc_bprop': [[3, 4, 6, 6]],
  712. 'skip': ['backward']}),
  713. ('AvgPool', {
  714. 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  715. 'desc_inputs': [[100, 3, 28, 28]],
  716. 'desc_bprop': [[100, 3, 14, 14]]}),
  717. ('AvgPoolGrad', {
  718. 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  719. 'desc_const': [(3, 4, 6, 6)],
  720. 'const_first': True,
  721. 'desc_inputs': [[3, 4, 6, 6]],
  722. 'desc_bprop': [[3, 4, 6, 6]],
  723. 'skip': ['backward']}),
  724. ('MaxPoolWithArgmax', {
  725. 'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
  726. 'desc_inputs': [[128, 32, 32, 64]],
  727. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
  728. ('SoftmaxCrossEntropyWithLogits', {
  729. 'block': P.SoftmaxCrossEntropyWithLogits(),
  730. 'desc_inputs': [[1, 10], [1, 10]],
  731. 'desc_bprop': [[1], [1, 10]],
  732. 'skip': ['backward_exec']}),
  733. ('Flatten', {
  734. 'block': P.Flatten(),
  735. 'desc_inputs': [[128, 32, 32, 64]],
  736. 'desc_bprop': [[128, 65536]]}),
  737. ('LogSoftmax', {
  738. 'block': P.LogSoftmax(),
  739. 'desc_inputs': [[64, 2]],
  740. 'desc_bprop': [[64, 2]]}),
  741. ('LogSoftmaxGrad', {
  742. 'block': G.LogSoftmaxGrad(),
  743. 'desc_inputs': [[16, 1234], [16, 1234]],
  744. 'desc_bprop': [[64, 2]],
  745. 'skip': ['backward']}),
  746. ('L2Normalize', {
  747. 'block': P.L2Normalize(),
  748. 'desc_inputs': [[2, 2]],
  749. 'desc_bprop': [[2, 2]]}),
  750. ('L2NormalizeGrad', {
  751. 'block': G.L2NormalizeGrad(),
  752. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  753. 'desc_bprop': [[2, 2]],
  754. 'skip': ['backward']}),
  755. ('LayerNorm', {
  756. 'block': P.LayerNorm(),
  757. 'desc_inputs': [[2, 16], [16], [16]],
  758. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  759. ('LayerNormGrad', {
  760. 'block': G.LayerNormGrad(),
  761. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  762. 'desc_bprop': [[2, 16], [16], [16]],
  763. 'skip': ['backward']}),
  764. ('FusedBatchNorm', {
  765. 'block': P.FusedBatchNorm(),
  766. 'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
  767. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  768. 'skip': []}),
  769. ('FusedBatchNormGrad', {
  770. 'block': G.FusedBatchNormGrad(),
  771. 'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
  772. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  773. 'skip': ['backward']}),
  774. ('BatchNorm', {
  775. 'block': P.BatchNorm(),
  776. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  777. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  778. 'skip': []}),
  779. ('BatchNormGrad', {
  780. 'block': G.BatchNormGrad(),
  781. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  782. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  783. 'skip': ['backward']}),
  784. ('TopK', {
  785. 'block': P.TopK(),
  786. 'desc_const': [5],
  787. 'desc_inputs': [[20, 20, 10]],
  788. 'desc_bprop': [[20, 20, 5]],
  789. 'skip': ['backward']}),
  790. ('GatherV2_0', {
  791. 'block': P.GatherV2(),
  792. 'desc_const': [0],
  793. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  794. 'desc_bprop': [[2, 1, 2]]}),
  795. ('GatherV2_1', {
  796. 'block': P.GatherV2(),
  797. 'desc_const': [2],
  798. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  799. 'desc_bprop': [[3, 1, 2]]}),
  800. ('GatherV2_2', {
  801. 'block': P.GatherV2(),
  802. 'desc_const': [0],
  803. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  804. 'desc_bprop': [[3, 2, 1, 3]]}),
  805. ('GatherV2_3', {
  806. 'block': P.GatherV2(),
  807. 'desc_const': [2],
  808. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  809. 'desc_bprop': [[3, 1, 3, 2]]}),
  810. ('GatherV2_4', {
  811. 'block': P.GatherV2(),
  812. 'desc_const': [1],
  813. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  814. 'desc_bprop': [[32, 1, 1024]]}),
  815. ('GatherV2_5', {
  816. 'block': P.GatherV2(),
  817. 'desc_const': [-1],
  818. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  819. 'desc_bprop': [[3, 1, 2]]}),
  820. ('GatherV2_6', {
  821. 'block': P.GatherV2(),
  822. 'desc_const': [0],
  823. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  824. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  825. ('Range', {
  826. 'block': P.Range(1.0, 5.0),
  827. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  828. 'desc_bprop': [[10]]}),
  829. ('UnsortedSegmentSum', {
  830. 'block': P.UnsortedSegmentSum(),
  831. 'desc_const': [1280],
  832. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  833. 'desc_bprop': [[8192, 1024]],
  834. 'skip': ['backward']}),
  835. ('UnsortedSegmentSum_1', {
  836. 'block': P.UnsortedSegmentSum(),
  837. 'desc_const': [4],
  838. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  839. 'desc_bprop': [[4, 1, 3]],
  840. 'skip': ['backward']}),
  841. ('UnsortedSegmentMin', {
  842. 'block': P.UnsortedSegmentMin(),
  843. 'desc_const': [4],
  844. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  845. 'desc_bprop': [[4, 2, 1, 3]]}),
  846. ('DropoutGenMask', {
  847. 'block': P.DropoutGenMask(),
  848. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  849. 'desc_inputs': [],
  850. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  851. 'skip': ['backward']}),
  852. ('DropoutDoMask', {
  853. 'block': P.DropoutDoMask(),
  854. 'desc_const': [Tensor(0.5)],
  855. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  856. 'desc_bprop': [[64, 12, 128, 128]]}),
  857. ('Dropout', {
  858. 'block': nn.Dropout(0.5),
  859. 'desc_inputs': [[64, 12, 128, 128]],
  860. 'desc_bprop': [[64, 12, 128, 128]]}),
  861. ('ReduceMean0', {
  862. 'block': P.ReduceMean(),
  863. 'desc_const': [(2,)],
  864. 'desc_inputs': [[3, 2, 2]],
  865. 'desc_bprop': [[3, 2]]}),
  866. ('ReduceMean1', {
  867. 'block': P.ReduceMean(),
  868. 'desc_const': [2],
  869. 'desc_inputs': [[3, 2, 2]],
  870. 'desc_bprop': [[3, 2]]}),
  871. ('All', {
  872. 'block': P.ReduceAll(),
  873. 'desc_const': [(1,)],
  874. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  875. 'desc_bprop': [[3]],
  876. 'skip': ['backward']}),
  877. ('DescConst', {
  878. 'block': Tensor(np.array([2], np.float32)),
  879. 'desc_inputs': [],
  880. 'desc_bprop': [[1]],
  881. 'skip': ['backward'],
  882. 'add_fake_input': True}),
  883. ('Fill', {
  884. 'block': P.Fill(),
  885. 'desc_const': [mstype.float32, (2, 3), 1.0],
  886. 'desc_inputs': [],
  887. 'desc_bprop': [[2, 3]],
  888. 'skip': ['backward'],
  889. 'add_fake_input': True}),
  890. ('OnesLike', {
  891. 'block': P.OnesLike(),
  892. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  893. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  894. }),
  895. ('ZerosLike', {
  896. 'block': P.ZerosLike(),
  897. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  898. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  899. }),
  900. ('Softmax', {
  901. 'block': P.Softmax(),
  902. 'desc_inputs': [[5, 5]],
  903. 'desc_bprop': [[5, 5]]}),
  904. ('DepthwiseConv2dNative_1', {
  905. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  906. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  907. 'desc_bprop': [[10, 32, 16, 16]]}),
  908. ('DepthwiseConv2dNative_2', {
  909. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  910. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  911. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  912. ('SigmoidCrossEntropyWithLogits', {
  913. 'block': P.SigmoidCrossEntropyWithLogits(),
  914. 'desc_inputs': [[128, 10], [128, 10]],
  915. 'desc_bprop': [[128, 10]]}),
  916. ('Pad', {
  917. 'block': P.Pad(((1, 2), (2, 3))),
  918. 'desc_inputs': [[7, 7]],
  919. 'desc_bprop': [[10, 12]]}),
  920. ('BinaryCrossEntropy', {
  921. 'block': P.BinaryCrossEntropy(),
  922. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  923. 'desc_bprop': []}),
  924. ('SparseApplyAdagrad', {
  925. 'block': P.SparseApplyAdagrad(0.5),
  926. 'desc_inputs': [[3, 3], [3, 3], [3, 3], Tensor(np.ones((3,), np.int32))],
  927. 'skip': ['backward']}),
  928. ('Flatten_1', {
  929. 'block': NetForFlatten(),
  930. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  931. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  932. 'skip': ['backward']}),
  933. ('Flatten_2', {
  934. 'block': NetForFlatten(),
  935. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  936. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  937. 'skip': ['backward']}),
  938. ('Flatten_3', {
  939. 'block': NetForFlattenComposed(),
  940. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  941. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  942. 'skip': []}),
  943. ('ArgmaxNet', {
  944. 'block': ArgmaxNet(),
  945. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  946. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  947. 'skip': ['backward']}),
  948. ('ArgminNet', {
  949. 'block': ArgminNet(),
  950. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  951. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  952. 'skip': ['backward']}),
  953. ('OneHot', {
  954. 'block': P.OneHot(),
  955. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  956. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  957. 'desc_bprop': [[1, 3]]}),
  958. ('ReduceProd_0', {
  959. 'block': P.ReduceProd(),
  960. 'desc_const': [0],
  961. 'desc_inputs': [[3, 2]],
  962. 'desc_bprop': [[2]]}),
  963. ('ReduceProd_1', {
  964. 'block': P.ReduceProd(keep_dims=True),
  965. 'desc_const': [0],
  966. 'desc_inputs': [[3, 2]],
  967. 'desc_bprop': [[1, 2]]}),
  968. ('CumProd', {
  969. 'block': P.CumProd(),
  970. 'desc_const': [0],
  971. 'desc_inputs': [[3, 2]],
  972. 'desc_bprop': [[3, 2]]}),
  973. ('ApplyFtrl', {
  974. 'block': ApplyFtrlNet(),
  975. 'desc_inputs': [[3, 3]],
  976. 'desc_bprop': [3, 3],
  977. 'skip': ['backward']}),
  978. ('ApplyRMSProp', {
  979. 'block': ApplyRMSNet(),
  980. 'desc_inputs': [[3, 3]],
  981. 'desc_bprop': [3, 3],
  982. 'skip': ['backward']}),
  983. ('ApplyCenteredRMSProp', {
  984. 'block': P.ApplyCenteredRMSProp(),
  985. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  986. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  987. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  988. 'desc_bprop': [1],
  989. 'skip': ['backward']}),
  990. ('CTCLoss', {
  991. 'block': P.CTCLoss(),
  992. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  993. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  994. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  995. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  996. 'desc_bprop': [[4], [6, 4, 6]]}),
  997. ('L2Loss_1', {
  998. 'block': P.L2Loss(),
  999. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  1000. 'desc_bprop': []}),
  1001. ('L2Loss_2', {
  1002. 'block': P.L2Loss(),
  1003. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  1004. 'desc_bprop': []}),
  1005. ('ResizeBilinear', {
  1006. 'block': P.ResizeBilinear((5, 5)),
  1007. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  1008. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  1009. ('ResizeBilinearGrad', {
  1010. 'block': G.ResizeBilinearGrad(),
  1011. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1012. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1013. 'skip': ['backward']}),
  1014. ('ROIAlign', {
  1015. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  1016. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  1017. 'desc_bprop': [[7, 7]]}),
  1018. ('ROIAlignGrad', {
  1019. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  1020. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  1021. 'desc_bprop': [[1, 1, 2, 2]],
  1022. 'skip': ['backward']}),
  1023. ('LARSUpdate', {
  1024. 'block': P.LARSUpdate(1e-05, 0.001, False),
  1025. 'desc_const': [0.0, 0.001],
  1026. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1027. 'desc_bprop': [3, 3],
  1028. 'skip': ['backward']}),
  1029. ('SGD', {
  1030. 'block': P.SGD(0.0, 0.0, False),
  1031. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  1032. 'desc_bprop': [3, 3],
  1033. 'skip': ['backward']}),
  1034. ('BinaryCrossEntropy', {
  1035. 'block': P.BinaryCrossEntropy(),
  1036. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1037. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1038. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1039. 'desc_bprop': []}),
  1040. ('BinaryCrossEntropyGrad', {
  1041. 'block': G.BinaryCrossEntropyGrad(),
  1042. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1043. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1044. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1045. 'desc_bprop': [],
  1046. 'skip': ['backward']}),
  1047. ('SparseApplyAdagrad', {
  1048. 'block': P.SparseApplyAdagrad(0.5),
  1049. 'desc_inputs': [Tensor([[0.7, 0.2], [0.1, 0.07]], mstype.float32),
  1050. Tensor([[0.2, 0.2], [0.1, 0.4]], mstype.float32),
  1051. Tensor([[0.5, 0.4], [0.6, 0.1]], mstype.float32), Tensor([1, 1], mstype.int32)],
  1052. 'desc_bprop': [Tensor([[0.7, 0.2], [0.1, 0.07]], mstype.float32)],
  1053. 'skip': ['backward']}),
  1054. ]
  1055. test_case_array_ops = [
  1056. ('SpaceToDepth', {
  1057. 'block': P.SpaceToDepth(2),
  1058. 'desc_inputs': [[1, 3, 2, 2]],
  1059. 'desc_bprop': [[1, 12, 1, 1]]}),
  1060. ('DepthToSpace', {
  1061. 'block': P.DepthToSpace(2),
  1062. 'desc_inputs': [[1, 12, 1, 1]],
  1063. 'desc_bprop': [[1, 3, 2, 2]]}),
  1064. ('Split', {
  1065. 'block': P.Split(1, 2),
  1066. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  1067. 'skip': ['backward']}),
  1068. ('Argmax', {
  1069. 'block': P.Argmax(),
  1070. 'desc_inputs': [[128, 32, 32, 64]],
  1071. 'desc_bprop': [0],
  1072. 'skip': ['backward']}),
  1073. ('Argmin', {
  1074. 'block': P.Argmin(),
  1075. 'desc_inputs': [[128, 32, 32, 64]],
  1076. 'desc_bprop': [1],
  1077. 'skip': ['backward']}),
  1078. ('ArgMaxWithValue', {
  1079. 'block': P.ArgMaxWithValue(),
  1080. 'desc_inputs': [[128, 32, 32, 64]],
  1081. 'desc_bprop': [[1], [1]],
  1082. 'skip': ['backward']}),
  1083. ('ArgMinWithValue', {
  1084. 'block': P.ArgMinWithValue(),
  1085. 'desc_inputs': [[128, 32, 32, 64]],
  1086. 'desc_bprop': [[1], [1]],
  1087. 'skip': ['backward']}),
  1088. ('Transpose_dim3', {
  1089. 'block': P.Transpose(),
  1090. 'desc_const': [(0, 2, 1)],
  1091. 'desc_inputs': [[1, 2, 3]],
  1092. 'desc_bprop': [[1, 3, 2]]}),
  1093. ('Transpose_dim4', {
  1094. 'block': P.Transpose(),
  1095. 'desc_const': [(0, 1, 2, 3)],
  1096. 'desc_inputs': [[1, 2, 3, 4]],
  1097. 'desc_bprop': [[1, 2, 4, 3]]}),
  1098. ('AddN', {
  1099. 'block': NetForTupleInput(P.AddN()),
  1100. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1101. 'desc_bprop': [[2, 3, 3, 5]],
  1102. 'skip': ['backward']}),
  1103. ('Shape', {
  1104. 'block': P.Shape(),
  1105. 'desc_inputs': [[3, 3, 2, 2]],
  1106. 'skip': ['backward']}),
  1107. ('Reshape', {
  1108. 'block': P.Reshape(),
  1109. 'desc_const': [(64,)],
  1110. 'desc_inputs': [[64, 1]],
  1111. 'desc_bprop': [[64]]}),
  1112. ('Cast', {
  1113. 'block': P.Cast(),
  1114. 'desc_const': [mstype.int32],
  1115. 'desc_inputs': [[2, 3, 4, 5]],
  1116. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  1117. ('ExpandDims', {
  1118. 'block': P.ExpandDims(),
  1119. 'desc_const': [0],
  1120. 'desc_inputs': [[2, 2]],
  1121. 'desc_bprop': [[1, 2, 2]]}),
  1122. ('ExpandDims_1', {
  1123. 'block': P.ExpandDims(),
  1124. 'desc_const': [-1],
  1125. 'desc_inputs': [[2, 2]],
  1126. 'desc_bprop': [[2, 2, 1]]}),
  1127. ('Squeeze', {
  1128. 'block': P.Squeeze(2),
  1129. 'desc_inputs': [[3, 2, 1]],
  1130. 'desc_bprop': [[3, 2]]}),
  1131. ('Squeeze_0', {
  1132. 'block': P.Squeeze(),
  1133. 'desc_inputs': [[3, 1, 2, 1]],
  1134. 'desc_bprop': [[3, 2]]}),
  1135. ('Squeeze_1', {
  1136. 'block': P.Squeeze(),
  1137. 'desc_inputs': [[1, 1, 1, 1]],
  1138. 'desc_bprop': [1.0],
  1139. 'skip': ['backward']}),
  1140. ('Squeeze_2', {
  1141. 'block': P.Squeeze((2, 3)),
  1142. 'desc_inputs': [[3, 2, 1, 1]],
  1143. 'desc_bprop': [[3, 2]]}),
  1144. ('Size', {
  1145. 'block': P.Size(),
  1146. 'desc_inputs': [[2, 3, 5]],
  1147. 'skip': ['backward']}),
  1148. ('Tile_0', {
  1149. 'block': P.Tile(),
  1150. 'desc_const': [(1, 2)],
  1151. 'desc_inputs': [[64, 1]],
  1152. 'desc_bprop': [[64, 2]]}),
  1153. ('Tile_1', {
  1154. 'block': P.Tile(),
  1155. 'desc_const': [(1, 1)],
  1156. 'desc_inputs': [[64, 1]],
  1157. 'desc_bprop': [[64, 1]]}),
  1158. ('Tile_2', {
  1159. 'block': P.Tile(),
  1160. 'desc_const': [(2, 1, 1, 2)],
  1161. 'desc_inputs': [[2, 2, 2]],
  1162. 'desc_bprop': [[2, 2, 2, 4]]}),
  1163. ('ConcatV2_0', {
  1164. 'block': P.Concat(),
  1165. 'desc_inputs': [
  1166. (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  1167. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
  1168. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  1169. ('ConcatV2_1', {
  1170. 'block': P.Concat(axis=2),
  1171. 'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  1172. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
  1173. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  1174. ('ConcatV2_2', {
  1175. 'block': NetForConcat(),
  1176. 'desc_inputs': [[2, 2]],
  1177. 'desc_bprop': [[4, 2]]}),
  1178. ('ConcatV2_3', {
  1179. 'block': NetForConcat1(),
  1180. 'desc_inputs': [[2, 2], [2, 2]],
  1181. 'desc_bprop': [[4, 2]]}),
  1182. ('ConcatV2_4', {
  1183. 'block': P.Concat(axis=0),
  1184. 'desc_inputs': [
  1185. (Tensor(np.ones((3, 2, 3), np.float32)),
  1186. Tensor(np.ones((5, 2, 3), np.float32)),
  1187. Tensor(np.ones((6, 2, 3), np.float32)))],
  1188. 'desc_bprop': [[14, 2, 3]]}),
  1189. ('ConcatV2_5', {
  1190. 'block': P.Concat(axis=-1),
  1191. 'desc_inputs': [(Tensor(np.array([1], np.float32)),
  1192. Tensor(np.array([1], np.float32)),
  1193. Tensor(np.array([1], np.float32)))],
  1194. 'desc_bprop': [[3,]]}),
  1195. ('Pack_0', {
  1196. 'block': NetForPackInput(P.Pack()),
  1197. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1198. 'desc_bprop': [[3, 2, 2]],
  1199. }),
  1200. ('Pack_1', {
  1201. 'block': NetForPackInput(P.Pack(axis=-2)),
  1202. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  1203. 'desc_bprop': [[3, 2, 3, 3]],
  1204. }),
  1205. ('Pack_2', {
  1206. 'block': NetForPackInput(P.Pack()),
  1207. 'desc_inputs': [[128, 128], [128, 128]],
  1208. 'desc_bprop': [[2, 128, 128]],
  1209. }),
  1210. ('Unpack_0', {
  1211. 'block': NetForUnpackInput(P.Unpack(axis=0)),
  1212. 'desc_inputs': [[2, 4]],
  1213. 'desc_bprop': [[4], [4]],
  1214. }),
  1215. ('Unpack_1', {
  1216. 'block': NetForUnpackInput(P.Unpack(axis=-1)),
  1217. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  1218. 'desc_bprop': [[1], [1], [1]],
  1219. }),
  1220. ('Diag_1', {
  1221. 'block': P.Diag(),
  1222. 'desc_inputs': [[4]],
  1223. 'desc_bprop': [[4, 4]],
  1224. }),
  1225. ('Diag_2', {
  1226. 'block': P.Diag(),
  1227. 'desc_inputs': [[4, 4]],
  1228. 'desc_bprop': [[4, 4, 4, 4]],
  1229. }),
  1230. ('DiagPart_1', {
  1231. 'block': P.DiagPart(),
  1232. 'desc_inputs': [[4, 4]],
  1233. 'desc_bprop': [[4]],
  1234. }),
  1235. ('DiagPart_2', {
  1236. 'block': P.DiagPart(),
  1237. 'desc_inputs': [[4, 4, 4, 4]],
  1238. 'desc_bprop': [[4, 4]],
  1239. }),
  1240. ('SpaceToBatch_1', {
  1241. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  1242. 'desc_inputs': [[1, 3, 2, 2]],
  1243. 'desc_bprop': [[4, 3, 1, 1]],
  1244. }),
  1245. ('SpaceToBatch_2', {
  1246. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  1247. 'desc_inputs': [[1, 3, 2, 2]],
  1248. 'desc_bprop': [[4, 3, 2, 3]],
  1249. }),
  1250. ('BatchToSpace_1', {
  1251. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  1252. 'desc_inputs': [[4, 3, 1, 1]],
  1253. 'desc_bprop': [[1, 3, 2, 2]],
  1254. }),
  1255. ('BatchToSpace_2', {
  1256. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  1257. 'desc_inputs': [[4, 3, 1, 1]],
  1258. 'desc_bprop': [[1, 3, 2, 1]],
  1259. }),
  1260. ('UnsortedSegmentMin_1', {
  1261. 'block': P.UnsortedSegmentMin(),
  1262. 'desc_const': [2],
  1263. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  1264. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  1265. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  1266. ]
  1267. test_case_other_ops = [
  1268. ('ScalarLog', {
  1269. 'block': F.scalar_log,
  1270. 'desc_const': [0.0],
  1271. 'desc_inputs': [],
  1272. 'desc_bprop': [1],
  1273. 'skip': ['backward']}),
  1274. ('BoundingBoxEncode', {
  1275. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  1276. 'desc_inputs': [[256, 4], [256, 4]],
  1277. 'desc_bprop': [[256, 4]],
  1278. 'skip': ['backward']}),
  1279. ('BoundingBoxDecode', {
  1280. 'block': P.BoundingBoxDecode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0), max_shape=(768, 1280)),
  1281. 'desc_inputs': [[256, 4], [256, 4]],
  1282. 'desc_bprop': [[256, 4]],
  1283. 'skip': ['backward']}),
  1284. ('GatherNd', {
  1285. 'block': P.GatherNd(),
  1286. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  1287. Tensor(np.ones((2, 4), np.int32))),
  1288. 'desc_bprop': [[2]]}),
  1289. ('ScatterNd', {
  1290. 'block': P.ScatterNd(),
  1291. 'desc_const': [(3, 3)],
  1292. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  1293. Tensor(np.ones((2,), np.int32))),
  1294. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  1295. ('ScatterMax', {
  1296. 'block': ScatterMax(),
  1297. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1298. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  1299. 'skip': ['backward']}),
  1300. ('ScatterAdd', {
  1301. 'block': ScatterAdd((6,)),
  1302. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1303. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1304. 'skip': ['backward']}),
  1305. ('ScatterAdd2d', {
  1306. 'block': ScatterAdd((3, 4)),
  1307. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1308. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1309. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1310. 'skip': ['backward']}),
  1311. ('SmoothL1Loss', {
  1312. 'block': P.SmoothL1Loss(),
  1313. 'desc_inputs': [[256, 4], [256, 4]],
  1314. 'desc_bprop': [[256, 4]]}),
  1315. ('IOU', {
  1316. 'block': P.IOU(),
  1317. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  1318. 'desc_bprop': [[128, 256]]}),
  1319. ('Summary', {
  1320. 'block': SummaryNet(),
  1321. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1322. Tensor(np.array([1.2]).astype(np.float32))],
  1323. 'skip': ['backward']}),
  1324. ('ConfusionMulGrad_1', {
  1325. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
  1326. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1327. 'desc_bprop': [[3, 2], [2]],
  1328. 'skip': ['backward']}),
  1329. ('ConfusionMulGrad_2', {
  1330. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
  1331. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1332. 'desc_bprop': [[3, 2], [1, 2]],
  1333. 'skip': ['backward']}),
  1334. ('ConfusionMulGrad_3', {
  1335. 'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
  1336. 'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
  1337. 'desc_bprop': [[2, 3, 4], [1, 1, 1]],
  1338. 'skip': ['backward']}),
  1339. ('HistogramSummary', {
  1340. 'block': HistogramSummaryNet(),
  1341. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1342. Tensor(np.array([1.2]).astype(np.float32))],
  1343. 'skip': ['backward']}),
  1344. ]
  1345. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops]
  1346. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  1347. # use -k to select certain testcast
  1348. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  1349. test_exec_case = test_case
  1350. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or
  1351. 'backward' not in x[1]['skip'], test_case)
  1352. @non_graph_engine
  1353. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  1354. def test_exec():
  1355. context.set_context(mode=context.GRAPH_MODE)
  1356. return test_exec_case
  1357. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  1358. def test_backward_exec():
  1359. context.set_context(mode=context.GRAPH_MODE)
  1360. return test_backward_exec_case
  1361. raise_set = [
  1362. ('Cast_Error', {
  1363. 'block': (P.Cast(), {'exception': TypeError}),
  1364. 'desc_const': [mstype.int32],
  1365. 'desc_inputs': ['wrong input'],
  1366. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  1367. ('Maximum_Error', {
  1368. 'block': (P.Maximum(), {'exception': TypeError}),
  1369. 'desc_const': [(1, 2, 3)],
  1370. 'desc_inputs': [[2, 3, 3, 5]],
  1371. 'desc_bprop': [[2, 3, 3, 5]]}),
  1372. ('Shape_error', {
  1373. 'block': (P.Shape(), {'exception': TypeError}),
  1374. 'desc_inputs': [(64, 1)],
  1375. 'desc_bprop': [[64]]}),
  1376. ('Flatten_Error', {
  1377. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  1378. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  1379. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  1380. ('ScatterNdUpdate', {
  1381. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  1382. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  1383. Tensor(np.ones((2, 2), np.float32)),
  1384. Tensor(np.ones((2,), np.float32))),
  1385. 'desc_bprop': [[2, 3]]}),
  1386. ('Pack', {
  1387. 'block': (NetForPackInput(P.Pack()), {'exception': ValueError}),
  1388. 'desc_inputs': [[2, 2]],
  1389. 'desc_bprop': [[1, 2, 2]]}),
  1390. ('PReLU', {
  1391. 'block': (P.PReLU(), {'exception': ValueError}),
  1392. 'desc_inputs': [[2], [1]],
  1393. 'desc_bprop': [[1]]}),
  1394. ]
  1395. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  1396. def test_check_exception():
  1397. return raise_set