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 52 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  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. ('Erf', {
  292. 'block': P.Erf(),
  293. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  294. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  295. ('Floor', {
  296. 'block': P.Floor(),
  297. 'desc_inputs': [[2, 512, 56, 56]],
  298. 'desc_bprop': [[2, 512, 56, 56]],
  299. 'skip': ['backward']}),
  300. ('ACos', {
  301. 'block': P.ACos(),
  302. 'desc_inputs': [[2, 3]],
  303. 'desc_bprop': [[2, 3]]}),
  304. ('Acosh', {
  305. 'block': P.Acosh(),
  306. 'desc_inputs': [[3, 4, 5]],
  307. 'desc_bprop': [[3, 4, 5]]}),
  308. ('Sin', {
  309. 'block': P.Sin(),
  310. 'desc_inputs': [[2, 3]],
  311. 'desc_bprop': [[2, 3]]}),
  312. ('Asin', {
  313. 'block': P.Asin(),
  314. 'desc_inputs': [[2, 3]],
  315. 'desc_bprop': [[2, 3]]}),
  316. ('Asinh', {
  317. 'block': P.Asinh(),
  318. 'desc_inputs': [[3, 4, 5]],
  319. 'desc_bprop': [[3, 4, 5]]}),
  320. ('Reciprocal', {
  321. 'block': P.Reciprocal(),
  322. 'desc_inputs': [[2, 3, 3, 5]],
  323. 'desc_bprop': [[2, 3, 3, 5]]}),
  324. ('Minimum_0', {
  325. 'block': P.Minimum(),
  326. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  327. 'desc_bprop': [[2, 3, 3, 5]]}),
  328. ('Maximum', {
  329. 'block': P.Maximum(),
  330. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  331. 'desc_bprop': [[2, 3, 3, 5]]}),
  332. ('Maximum_0', {
  333. 'block': P.Maximum(),
  334. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  335. 'desc_bprop': [[2, 3, 3, 5]]}),
  336. ('MaximumGrad', {
  337. 'block': G.MaximumGrad(),
  338. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  339. 'skip': ['backward']}),
  340. ('MinimumGrad', {
  341. 'block': G.MinimumGrad(),
  342. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  343. 'skip': ['backward']}),
  344. ('StridedSlice', {
  345. 'block': P.StridedSlice(),
  346. 'desc_const': [(0, 1, 2, 1),
  347. (2, 3, 3, 4),
  348. (1, 1, 1, 1)],
  349. 'desc_inputs': [[2, 3, 3, 5]],
  350. 'desc_bprop': [[2, 2, 1, 3]]}),
  351. ('Slice_1', {
  352. 'block': P.Slice(),
  353. 'desc_const': [(0, 1, 2, 1),
  354. (1, 1, 1, 2)],
  355. 'desc_inputs': [[2, 3, 3, 5]],
  356. 'desc_bprop': [[1, 1, 1, 2]]}),
  357. ('StridedSliceGrad', {
  358. 'block': G.StridedSliceGrad(),
  359. 'desc_const': [(64, 1, 1024),
  360. (0, 1, 0),
  361. (64, 2, 1024),
  362. (1, 1, 1)],
  363. 'desc_inputs': [[64, 128, 1024]],
  364. 'skip': ['backward']}),
  365. ('RandomChoiceWithMask', {
  366. 'block': P.RandomChoiceWithMask(256),
  367. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  368. 'desc_bprop': [[256, 4], [256, 4]],
  369. 'skip': ['backward']}),
  370. ('LessEqual', {
  371. 'block': P.LessEqual(),
  372. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  373. Tensor(np.random.rand(4).astype(np.float16))],
  374. 'skip': ['backward']}),
  375. ('Less', {
  376. 'block': P.Less(),
  377. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  378. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  379. 'skip': ['backward']}),
  380. ('RealDiv_0', {
  381. 'block': P.RealDiv(),
  382. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  383. 'desc_inputs': [],
  384. 'skip': ['backward']}),
  385. ('RealDiv', {
  386. 'block': P.RealDiv(),
  387. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  388. 'desc_bprop': [[4]]}),
  389. ('RealDiv_1', {
  390. 'block': P.RealDiv(),
  391. 'desc_inputs': [[512, 1024], [512, 1024]],
  392. 'desc_bprop': [[512, 1024]]}),
  393. ('FloorDiv', {
  394. 'block': P.FloorDiv(),
  395. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  396. Tensor(np.random.rand(4).astype(np.float16))],
  397. 'skip': ['backward']}),
  398. ('FloorMod', {
  399. 'block': P.FloorMod(),
  400. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  401. 'desc_bprop': [[2, 3, 4, 5]]}),
  402. ('identity', {
  403. 'block': ops.functional.identity,
  404. 'desc_inputs': [[2, 2]],
  405. 'skip': ['backward']}),
  406. ('MatMul_1', {
  407. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  408. 'desc_inputs': [[1024, 160], [160, 1024]],
  409. 'desc_bprop': [[1024, 1024]]}),
  410. ('MatMul_2', {
  411. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  412. 'desc_inputs': [[160, 1024], [1024, 160]],
  413. 'desc_bprop': [[1024, 1024]]}),
  414. ('Sub', {
  415. 'block': P.Sub(),
  416. 'desc_inputs': [[3], [3]],
  417. 'desc_bprop': [[3]]}),
  418. ('TruncatedNormal', {
  419. 'block': P.TruncatedNormal(),
  420. 'desc_const': [(1, 2, 3)],
  421. 'desc_inputs': [],
  422. 'skip': ['backward'],
  423. 'add_fake_input': True}),
  424. ('Select', {
  425. 'block': P.Select(),
  426. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  427. [2, 3], [2, 3]],
  428. 'desc_bprop': [[2, 3]]}),
  429. ('Rank', {
  430. 'block': P.Rank(),
  431. 'desc_inputs': [[2, 3]],
  432. 'skip': ['backward']}),
  433. ('InvertPermutation', {
  434. 'block': P.InvertPermutation(),
  435. 'desc_const': [(0, 3, 1, 2)],
  436. 'desc_inputs': [],
  437. 'skip': ['backward']}),
  438. ('Square', {
  439. 'block': P.Square(),
  440. 'desc_inputs': [[4]],
  441. 'desc_bprop': [[4]]}),
  442. ('Rsqrt', {
  443. 'block': P.Rsqrt(),
  444. 'desc_inputs': [[4]],
  445. 'desc_bprop': [[4]]}),
  446. ('Sqrt', {
  447. 'block': P.Sqrt(),
  448. 'desc_inputs': [[4]],
  449. 'desc_bprop': [[4]]}),
  450. ('RealDiv', {
  451. 'block': P.RealDiv(),
  452. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  453. 'desc_bprop': [[2, 3, 4, 5]]}),
  454. ('Div', {
  455. 'block': P.Div(),
  456. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  457. 'desc_bprop': [[2, 3, 4, 5]]}),
  458. ('Equal', {
  459. 'block': P.Equal(),
  460. 'desc_inputs': [[3, 4, 5], [4, 5]],
  461. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  462. ('NotEqual', {
  463. 'block': P.NotEqual(),
  464. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  465. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  466. ('NotEqual_0', {
  467. 'block': P.NotEqual(),
  468. 'desc_inputs': [1, [2, 3, 4, 5]],
  469. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  470. 'skip': ['backward']}),
  471. ('Greater', {
  472. 'block': P.Greater(),
  473. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  474. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  475. ('GreaterEqual', {
  476. 'block': P.GreaterEqual(),
  477. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  478. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  479. ('LogicalNot', {
  480. 'block': P.LogicalNot(),
  481. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  482. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  483. ('LogicalAnd', {
  484. 'block': P.LogicalAnd(),
  485. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  486. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  487. ('LogicalOr', {
  488. 'block': P.LogicalOr(),
  489. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  490. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  491. ('NpuAllocFloatStatus', {
  492. 'block': P.NPUAllocFloatStatus(),
  493. 'desc_inputs': [],
  494. 'add_fack_input': True,
  495. 'fack_input_type': np.float32,
  496. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  497. 'skip': ['backward']}),
  498. ('NpuGetFloatStatus', {
  499. 'block': P.NPUGetFloatStatus(),
  500. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  501. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  502. 'skip': ['backward']}),
  503. ('NpuClearFloatStatus', {
  504. 'block': P.NPUClearFloatStatus(),
  505. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  506. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  507. 'skip': ['backward']}),
  508. ('CheckValid', {
  509. 'block': P.CheckValid(),
  510. 'desc_inputs': [[20000, 4], [3]],
  511. 'desc_bprop': [[20000]],
  512. 'skip': ['backward']}),
  513. ('NMSWithMask', {
  514. 'block': P.NMSWithMask(0.5),
  515. 'desc_inputs': [[128, 5]],
  516. 'desc_bprop': [[128, 5], [128], [128]],
  517. 'skip': ['backward']}),
  518. ('Abs', {
  519. 'block': P.Abs(),
  520. 'desc_inputs': [[4]],
  521. 'desc_bprop': [[4]]}),
  522. ('CumSum', {
  523. 'block': CumSumNet(),
  524. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  525. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  526. [1, 3, 7, 9]]).astype(np.float32))]}),
  527. ('ReduceSum_3', {
  528. 'block': P.ReduceSum(),
  529. 'desc_const': [0],
  530. 'desc_inputs': [[3, 2]],
  531. 'desc_bprop': [[2]]}),
  532. ('ReduceSum_4', {
  533. 'block': P.ReduceSum(keep_dims=True),
  534. 'desc_const': [0],
  535. 'desc_inputs': [[3, 2]],
  536. 'desc_bprop': [[1, 2]]}),
  537. ('ReduceSum_5', {
  538. 'block': P.ReduceSum(keep_dims=True),
  539. 'desc_inputs': [[2, 3, 4]],
  540. 'desc_bprop': [[1, 1, 1]]}),
  541. ('ReduceSum_6', {
  542. 'block': P.ReduceSum(),
  543. 'desc_inputs': [[2, 3, 4]],
  544. 'desc_bprop': [[1]]}),
  545. ('Sum_0', {
  546. 'block': P.ReduceSum(),
  547. 'desc_const': [(1,)],
  548. 'desc_inputs': [[3, 2]],
  549. 'desc_bprop': [[3]]}),
  550. ('Sum_1', {
  551. 'block': P.ReduceSum(keep_dims=True),
  552. 'desc_const': [(1,)],
  553. 'desc_inputs': [[3, 2]],
  554. 'desc_bprop': [[3, 1]]}),
  555. ('Sum_2', {
  556. 'block': P.ReduceSum(),
  557. 'desc_const': [(0, 1)],
  558. 'desc_inputs': [[3, 2]],
  559. 'desc_bprop': [[1]]}),
  560. ('Sum_3', {
  561. 'block': P.ReduceSum(),
  562. 'desc_const': [0],
  563. 'desc_inputs': [[3, 2]],
  564. 'desc_bprop': [[2]]}),
  565. ('Sum_4', {
  566. 'block': P.ReduceSum(keep_dims=True),
  567. 'desc_const': [0],
  568. 'desc_inputs': [[3, 2]],
  569. 'desc_bprop': [[1, 2]]}),
  570. ('Sum_5', {
  571. 'block': P.ReduceSum(keep_dims=True),
  572. 'desc_const': [()],
  573. 'desc_inputs': [[2, 3, 4]],
  574. 'desc_bprop': [[1, 1, 1]]}),
  575. ('Sum_6', {
  576. 'block': P.ReduceSum(),
  577. 'desc_const': [()],
  578. 'desc_inputs': [[2, 3, 4]],
  579. 'desc_bprop': [[1]]}),
  580. ('Sign', {
  581. 'block': P.Sign(),
  582. 'desc_inputs': [[3]],
  583. 'desc_bprop': [[3]]}),
  584. ('Round', {
  585. 'block': P.Round(),
  586. 'desc_inputs': [[3]],
  587. 'desc_bprop': [[3]]}),
  588. ('Atan2', {
  589. 'block': P.Atan2(),
  590. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  591. Tensor(np.array([1, 1]).astype(np.float32))],
  592. 'desc_bprop': [[2]]}),
  593. ('SquareSumAll', {
  594. 'block': P.SquareSumAll(),
  595. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  596. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  597. 'skip': ['backward']}),
  598. ('Cos', {
  599. 'block': P.Cos(),
  600. 'desc_inputs': [[2, 3]],
  601. 'desc_bprop': [[2, 3]]}),
  602. ('ReduceAll', {
  603. 'block': P.ReduceAll(),
  604. 'desc_const': [1],
  605. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  606. 'desc_bprop': []}),
  607. ]
  608. test_case_nn_ops = [
  609. ('BiasAdd', {
  610. 'block': P.BiasAdd(),
  611. 'desc_inputs': [[1, 3, 3, 3], [3]],
  612. 'desc_bprop': [[1, 3, 3, 3]]}),
  613. ('BiasAddGrad', {
  614. 'block': G.BiasAddGrad(),
  615. 'desc_inputs': [[1, 3, 3, 3]],
  616. 'skip': ['backward']}),
  617. ('Gelu', {
  618. 'block': P.Gelu(),
  619. 'desc_inputs': [[1, 3, 4, 4]],
  620. 'desc_bprop': [[1, 3, 4, 4]]}),
  621. ('GeluGrad', {
  622. 'block': G.GeluGrad(),
  623. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  624. 'desc_bprop': [[2, 2]],
  625. 'skip': ['backward']}),
  626. ('Tanh', {
  627. 'block': P.Tanh(),
  628. 'desc_inputs': [[1, 3, 4, 4]],
  629. 'desc_bprop': [[1, 3, 4, 4]]}),
  630. ('TanhGrad', {
  631. 'block': G.TanhGrad(),
  632. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  633. 'desc_bprop': [[1, 3, 4, 4]],
  634. 'skip': ['backward']}),
  635. ('ReLU', {
  636. 'block': P.ReLU(),
  637. 'desc_inputs': [[1, 3, 4, 4]],
  638. 'desc_bprop': [[1, 3, 4, 4]]}),
  639. ('ReLU6', {
  640. 'block': P.ReLU6(),
  641. 'desc_inputs': [[1, 3, 4, 4]],
  642. 'desc_bprop': [[1, 3, 4, 4]]}),
  643. ('ReLUV2', {
  644. 'block': P.ReLUV2(),
  645. 'desc_inputs': [[1, 3, 4, 4]],
  646. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  647. ('ReLUGrad', {
  648. 'block': G.ReluGrad(),
  649. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  650. 'skip': ['backward']}),
  651. ('Softplus', {
  652. 'block': P.Softplus(),
  653. 'desc_inputs': [[1, 3, 4, 4]],
  654. 'desc_bprop': [[1, 3, 4, 4]]}),
  655. ('SoftplusGrad', {
  656. 'block': G.SoftplusGrad(),
  657. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  658. 'skip': ['backward']}),
  659. ('Elu', {
  660. 'block': P.Elu(),
  661. 'desc_inputs': [[2, 3, 4]],
  662. 'desc_bprop': [[2, 3, 4]]}),
  663. ('EluGrad', {
  664. 'block': G.EluGrad(),
  665. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  666. 'desc_bprop': [[2, 3, 4]],
  667. 'skip': ['backward']}),
  668. ('Sigmoid', {
  669. 'block': P.Sigmoid(),
  670. 'desc_inputs': [[1, 3, 4, 4]],
  671. 'desc_bprop': [[1, 3, 4, 4]]}),
  672. ('MaxPool', {
  673. 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  674. 'desc_inputs': [[100, 3, 28, 28]],
  675. 'desc_bprop': [[100, 3, 14, 14]]}),
  676. ('MaxPoolGrad', {
  677. 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  678. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  679. 'desc_bprop': [[3, 4, 6, 6]],
  680. 'skip': ['backward']}),
  681. ('AvgPool', {
  682. 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  683. 'desc_inputs': [[100, 3, 28, 28]],
  684. 'desc_bprop': [[100, 3, 14, 14]]}),
  685. ('AvgPoolGrad', {
  686. 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  687. 'desc_const': [(3, 4, 6, 6)],
  688. 'const_first': True,
  689. 'desc_inputs': [[3, 4, 6, 6]],
  690. 'desc_bprop': [[3, 4, 6, 6]],
  691. 'skip': ['backward']}),
  692. ('MaxPoolWithArgmax', {
  693. 'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
  694. 'desc_inputs': [[128, 32, 32, 64]],
  695. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
  696. ('SoftmaxCrossEntropyWithLogits', {
  697. 'block': P.SoftmaxCrossEntropyWithLogits(),
  698. 'desc_inputs': [[1, 10], [1, 10]],
  699. 'desc_bprop': [[1], [1, 10]],
  700. 'skip': ['backward_exec']}),
  701. ('Flatten', {
  702. 'block': P.Flatten(),
  703. 'desc_inputs': [[128, 32, 32, 64]],
  704. 'desc_bprop': [[128, 65536]]}),
  705. ('LogSoftmax', {
  706. 'block': P.LogSoftmax(),
  707. 'desc_inputs': [[64, 2]],
  708. 'desc_bprop': [[64, 2]]}),
  709. ('LogSoftmaxGrad', {
  710. 'block': G.LogSoftmaxGrad(),
  711. 'desc_inputs': [[16, 1234], [16, 1234]],
  712. 'desc_bprop': [[64, 2]],
  713. 'skip': ['backward']}),
  714. ('L2Normalize', {
  715. 'block': P.L2Normalize(),
  716. 'desc_inputs': [[2, 2]],
  717. 'desc_bprop': [[2, 2]]}),
  718. ('L2NormalizeGrad', {
  719. 'block': G.L2NormalizeGrad(),
  720. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  721. 'desc_bprop': [[2, 2]],
  722. 'skip': ['backward']}),
  723. ('LayerNorm', {
  724. 'block': P.LayerNorm(),
  725. 'desc_inputs': [[2, 16], [16], [16]],
  726. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  727. ('LayerNormGrad', {
  728. 'block': G.LayerNormGrad(),
  729. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  730. 'desc_bprop': [[2, 16], [16], [16]],
  731. 'skip': ['backward']}),
  732. ('FusedBatchNorm', {
  733. 'block': P.FusedBatchNorm(),
  734. 'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
  735. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  736. 'skip': []}),
  737. ('FusedBatchNormGrad', {
  738. 'block': G.FusedBatchNormGrad(),
  739. 'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
  740. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  741. 'skip': ['backward']}),
  742. ('BatchNorm', {
  743. 'block': P.BatchNorm(),
  744. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  745. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  746. 'skip': []}),
  747. ('BatchNormGrad', {
  748. 'block': G.BatchNormGrad(),
  749. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  750. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  751. 'skip': ['backward']}),
  752. ('TopK', {
  753. 'block': P.TopK(),
  754. 'desc_const': [5],
  755. 'desc_inputs': [[20, 20, 10]],
  756. 'desc_bprop': [[20, 20, 5]],
  757. 'skip': ['backward']}),
  758. ('GatherV2_0', {
  759. 'block': P.GatherV2(),
  760. 'desc_const': [0],
  761. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  762. 'desc_bprop': [[2, 1, 2]]}),
  763. ('GatherV2_1', {
  764. 'block': P.GatherV2(),
  765. 'desc_const': [2],
  766. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  767. 'desc_bprop': [[3, 1, 2]]}),
  768. ('GatherV2_2', {
  769. 'block': P.GatherV2(),
  770. 'desc_const': [0],
  771. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  772. 'desc_bprop': [[3, 2, 1, 3]]}),
  773. ('GatherV2_3', {
  774. 'block': P.GatherV2(),
  775. 'desc_const': [2],
  776. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  777. 'desc_bprop': [[3, 1, 3, 2]]}),
  778. ('GatherV2_4', {
  779. 'block': P.GatherV2(),
  780. 'desc_const': [1],
  781. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  782. 'desc_bprop': [[32, 1, 1024]]}),
  783. ('GatherV2_5', {
  784. 'block': P.GatherV2(),
  785. 'desc_const': [-1],
  786. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  787. 'desc_bprop': [[3, 1, 2]]}),
  788. ('GatherV2_6', {
  789. 'block': P.GatherV2(),
  790. 'desc_const': [0],
  791. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  792. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  793. ('Range', {
  794. 'block': P.Range(1.0, 5.0),
  795. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  796. 'desc_bprop': [[10]]}),
  797. ('UnsortedSegmentSum', {
  798. 'block': P.UnsortedSegmentSum(),
  799. 'desc_const': [1280],
  800. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  801. 'desc_bprop': [[8192, 1024]],
  802. 'skip': ['backward']}),
  803. ('UnsortedSegmentSum_1', {
  804. 'block': P.UnsortedSegmentSum(),
  805. 'desc_const': [4],
  806. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  807. 'desc_bprop': [[4, 1, 3]],
  808. 'skip': ['backward']}),
  809. ('UnsortedSegmentMin', {
  810. 'block': P.UnsortedSegmentMin(),
  811. 'desc_const': [4],
  812. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  813. 'desc_bprop': [[4, 2, 1, 3]]}),
  814. ('DropoutGenMask', {
  815. 'block': P.DropoutGenMask(),
  816. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  817. 'desc_inputs': [],
  818. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  819. 'skip': ['backward']}),
  820. ('DropoutDoMask', {
  821. 'block': P.DropoutDoMask(),
  822. 'desc_const': [Tensor(0.5)],
  823. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  824. 'desc_bprop': [[64, 12, 128, 128]]}),
  825. ('Dropout', {
  826. 'block': nn.Dropout(0.5),
  827. 'desc_inputs': [[64, 12, 128, 128]],
  828. 'desc_bprop': [[64, 12, 128, 128]]}),
  829. ('ReduceMean0', {
  830. 'block': P.ReduceMean(),
  831. 'desc_const': [(2,)],
  832. 'desc_inputs': [[3, 2, 2]],
  833. 'desc_bprop': [[3, 2]]}),
  834. ('ReduceMean1', {
  835. 'block': P.ReduceMean(),
  836. 'desc_const': [2],
  837. 'desc_inputs': [[3, 2, 2]],
  838. 'desc_bprop': [[3, 2]]}),
  839. ('All', {
  840. 'block': P.ReduceAll(),
  841. 'desc_const': [(1,)],
  842. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  843. 'desc_bprop': [[3]],
  844. 'skip': ['backward']}),
  845. ('DescConst', {
  846. 'block': Tensor(np.array([2], np.float32)),
  847. 'desc_inputs': [],
  848. 'desc_bprop': [[1]],
  849. 'skip': ['backward'],
  850. 'add_fake_input': True}),
  851. ('Fill', {
  852. 'block': P.Fill(),
  853. 'desc_const': [mstype.float32, (2, 3), 1.0],
  854. 'desc_inputs': [],
  855. 'desc_bprop': [[2, 3]],
  856. 'skip': ['backward'],
  857. 'add_fake_input': True}),
  858. ('OnesLike', {
  859. 'block': P.OnesLike(),
  860. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  861. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  862. }),
  863. ('ZerosLike', {
  864. 'block': P.ZerosLike(),
  865. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  866. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  867. }),
  868. ('Softmax', {
  869. 'block': P.Softmax(),
  870. 'desc_inputs': [[5, 5]],
  871. 'desc_bprop': [[5, 5]]}),
  872. ('DepthwiseConv2dNative_1', {
  873. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  874. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  875. 'desc_bprop': [[10, 32, 16, 16]]}),
  876. ('DepthwiseConv2dNative_2', {
  877. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  878. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  879. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  880. ('SigmoidCrossEntropyWithLogits', {
  881. 'block': P.SigmoidCrossEntropyWithLogits(),
  882. 'desc_inputs': [[128, 10], [128, 10]],
  883. 'desc_bprop': [[128, 10]]}),
  884. ('Pad', {
  885. 'block': P.Pad(((1, 2), (2, 3))),
  886. 'desc_inputs': [[7, 7]],
  887. 'desc_bprop': [[10, 12]]}),
  888. ('BinaryCrossEntropy', {
  889. 'block': P.BinaryCrossEntropy(),
  890. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  891. 'desc_bprop': []}),
  892. ('SparseApplyAdagrad', {
  893. 'block': P.SparseApplyAdagrad(0.5),
  894. 'desc_inputs': [[3, 3], [3, 3], [3, 3], Tensor(np.ones((3,), np.int32))],
  895. 'skip': ['backward']}),
  896. ('Flatten_1', {
  897. 'block': NetForFlatten(),
  898. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  899. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  900. 'skip': ['backward']}),
  901. ('Flatten_2', {
  902. 'block': NetForFlatten(),
  903. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  904. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  905. 'skip': ['backward']}),
  906. ('Flatten_3', {
  907. 'block': NetForFlattenComposed(),
  908. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  909. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  910. 'skip': []}),
  911. ('ArgmaxNet', {
  912. 'block': ArgmaxNet(),
  913. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  914. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  915. 'skip': ['backward']}),
  916. ('ArgminNet', {
  917. 'block': ArgminNet(),
  918. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  919. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  920. 'skip': ['backward']}),
  921. ('OneHot', {
  922. 'block': P.OneHot(),
  923. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  924. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  925. 'desc_bprop': [[1, 3]]}),
  926. ('ReduceProd_0', {
  927. 'block': P.ReduceProd(),
  928. 'desc_const': [0],
  929. 'desc_inputs': [[3, 2]],
  930. 'desc_bprop': [[2]]}),
  931. ('ReduceProd_1', {
  932. 'block': P.ReduceProd(keep_dims=True),
  933. 'desc_const': [0],
  934. 'desc_inputs': [[3, 2]],
  935. 'desc_bprop': [[1, 2]]}),
  936. ('CumProd', {
  937. 'block': P.CumProd(),
  938. 'desc_const': [0],
  939. 'desc_inputs': [[3, 2]],
  940. 'desc_bprop': [[3, 2]]}),
  941. ('ApplyFtrl', {
  942. 'block': ApplyFtrlNet(),
  943. 'desc_inputs': [[3, 3]],
  944. 'desc_bprop': [3, 3],
  945. 'skip': ['backward']}),
  946. ('ApplyRMSProp', {
  947. 'block': ApplyRMSNet(),
  948. 'desc_inputs': [[3, 3]],
  949. 'desc_bprop': [3, 3],
  950. 'skip': ['backward']}),
  951. ('ApplyCenteredRMSProp', {
  952. 'block': P.ApplyCenteredRMSProp(),
  953. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  954. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3]],
  955. 'desc_bprop': [3, 3],
  956. 'skip': ['backward']}),
  957. ('CTCLoss', {
  958. 'block': P.CTCLoss(),
  959. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  960. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  961. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  962. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  963. 'desc_bprop': [[4], [6, 4, 6]]}),
  964. ('L2Loss_1', {
  965. 'block': P.L2Loss(),
  966. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  967. 'desc_bprop': []}),
  968. ('L2Loss_2', {
  969. 'block': P.L2Loss(),
  970. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  971. 'desc_bprop': []}),
  972. ('ResizeBilinear', {
  973. 'block': P.ResizeBilinear((5, 5)),
  974. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  975. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  976. ('ResizeBilinearGrad', {
  977. 'block': G.ResizeBilinearGrad(),
  978. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  979. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  980. 'skip': ['backward']}),
  981. ('ROIAlign', {
  982. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  983. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  984. 'desc_bprop': [[7, 7]]}),
  985. ('ROIAlignGrad', {
  986. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  987. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  988. 'desc_bprop': [[1, 1, 2, 2]],
  989. 'skip': ['backward']}),
  990. ('LARSUpdate', {
  991. 'block': P.LARSUpdate(1e-05, 0.001, False),
  992. 'desc_const': [0.0, 0.001],
  993. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  994. 'desc_bprop': [3, 3],
  995. 'skip': ['backward']}),
  996. ('SGD', {
  997. 'block': P.SGD(0.0, 0.0, False),
  998. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  999. 'desc_bprop': [3, 3],
  1000. 'skip': ['backward']}),
  1001. ('BinaryCrossEntropy', {
  1002. 'block': P.BinaryCrossEntropy(),
  1003. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1004. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1005. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1006. 'desc_bprop': []}),
  1007. ('BinaryCrossEntropyGrad', {
  1008. 'block': G.BinaryCrossEntropyGrad(),
  1009. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1010. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1011. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1012. 'desc_bprop': [],
  1013. 'skip': ['backward']}),
  1014. ('SparseApplyAdagrad', {
  1015. 'block': P.SparseApplyAdagrad(0.5),
  1016. 'desc_inputs': [Tensor([[0.7, 0.2], [0.1, 0.07]], mstype.float32),
  1017. Tensor([[0.2, 0.2], [0.1, 0.4]], mstype.float32),
  1018. Tensor([[0.5, 0.4], [0.6, 0.1]], mstype.float32), Tensor([1, 1], mstype.int32)],
  1019. 'desc_bprop': [Tensor([[0.7, 0.2], [0.1, 0.07]], mstype.float32)],
  1020. 'skip': ['backward']}),
  1021. ]
  1022. test_case_array_ops = [
  1023. ('SpaceToDepth', {
  1024. 'block': P.SpaceToDepth(2),
  1025. 'desc_inputs': [[1, 3, 2, 2]],
  1026. 'desc_bprop': [[1, 12, 1, 1]]}),
  1027. ('DepthToSpace', {
  1028. 'block': P.DepthToSpace(2),
  1029. 'desc_inputs': [[1, 12, 1, 1]],
  1030. 'desc_bprop': [[1, 3, 2, 2]]}),
  1031. ('Split', {
  1032. 'block': P.Split(1, 2),
  1033. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  1034. 'skip': ['backward']}),
  1035. ('Argmax', {
  1036. 'block': P.Argmax(),
  1037. 'desc_inputs': [[128, 32, 32, 64]],
  1038. 'desc_bprop': [0],
  1039. 'skip': ['backward']}),
  1040. ('Argmin', {
  1041. 'block': P.Argmin(),
  1042. 'desc_inputs': [[128, 32, 32, 64]],
  1043. 'desc_bprop': [1],
  1044. 'skip': ['backward']}),
  1045. ('ArgMaxWithValue', {
  1046. 'block': P.ArgMaxWithValue(),
  1047. 'desc_inputs': [[128, 32, 32, 64]],
  1048. 'desc_bprop': [[1], [1]],
  1049. 'skip': ['backward']}),
  1050. ('ArgMinWithValue', {
  1051. 'block': P.ArgMinWithValue(),
  1052. 'desc_inputs': [[128, 32, 32, 64]],
  1053. 'desc_bprop': [[1], [1]],
  1054. 'skip': ['backward']}),
  1055. ('Transpose_dim3', {
  1056. 'block': P.Transpose(),
  1057. 'desc_const': [(0, 2, 1)],
  1058. 'desc_inputs': [[1, 2, 3]],
  1059. 'desc_bprop': [[1, 3, 2]]}),
  1060. ('Transpose_dim4', {
  1061. 'block': P.Transpose(),
  1062. 'desc_const': [(0, 1, 2, 3)],
  1063. 'desc_inputs': [[1, 2, 3, 4]],
  1064. 'desc_bprop': [[1, 2, 4, 3]]}),
  1065. ('AddN', {
  1066. 'block': NetForTupleInput(P.AddN()),
  1067. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1068. 'desc_bprop': [[2, 3, 3, 5]],
  1069. 'skip': ['backward']}),
  1070. ('Shape', {
  1071. 'block': P.Shape(),
  1072. 'desc_inputs': [[3, 3, 2, 2]],
  1073. 'skip': ['backward']}),
  1074. ('Reshape', {
  1075. 'block': P.Reshape(),
  1076. 'desc_const': [(64,)],
  1077. 'desc_inputs': [[64, 1]],
  1078. 'desc_bprop': [[64]]}),
  1079. ('Cast', {
  1080. 'block': P.Cast(),
  1081. 'desc_const': [mstype.int32],
  1082. 'desc_inputs': [[2, 3, 4, 5]],
  1083. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  1084. ('ExpandDims', {
  1085. 'block': P.ExpandDims(),
  1086. 'desc_const': [0],
  1087. 'desc_inputs': [[2, 2]],
  1088. 'desc_bprop': [[1, 2, 2]]}),
  1089. ('ExpandDims_1', {
  1090. 'block': P.ExpandDims(),
  1091. 'desc_const': [-1],
  1092. 'desc_inputs': [[2, 2]],
  1093. 'desc_bprop': [[2, 2, 1]]}),
  1094. ('Squeeze', {
  1095. 'block': P.Squeeze(2),
  1096. 'desc_inputs': [[3, 2, 1]],
  1097. 'desc_bprop': [[3, 2]]}),
  1098. ('Squeeze_0', {
  1099. 'block': P.Squeeze(),
  1100. 'desc_inputs': [[3, 1, 2, 1]],
  1101. 'desc_bprop': [[3, 2]]}),
  1102. ('Squeeze_1', {
  1103. 'block': P.Squeeze(),
  1104. 'desc_inputs': [[1, 1, 1, 1]],
  1105. 'desc_bprop': [1.0],
  1106. 'skip': ['backward']}),
  1107. ('Squeeze_2', {
  1108. 'block': P.Squeeze((2, 3)),
  1109. 'desc_inputs': [[3, 2, 1, 1]],
  1110. 'desc_bprop': [[3, 2]]}),
  1111. ('Size', {
  1112. 'block': P.Size(),
  1113. 'desc_inputs': [[2, 3, 5]],
  1114. 'skip': ['backward']}),
  1115. ('Tile_0', {
  1116. 'block': P.Tile(),
  1117. 'desc_const': [(1, 2)],
  1118. 'desc_inputs': [[64, 1]],
  1119. 'desc_bprop': [[64, 2]]}),
  1120. ('Tile_1', {
  1121. 'block': P.Tile(),
  1122. 'desc_const': [(1, 1)],
  1123. 'desc_inputs': [[64, 1]],
  1124. 'desc_bprop': [[64, 1]]}),
  1125. ('Tile_2', {
  1126. 'block': P.Tile(),
  1127. 'desc_const': [(2, 1, 1, 2)],
  1128. 'desc_inputs': [[2, 2, 2]],
  1129. 'desc_bprop': [[2, 2, 2, 4]]}),
  1130. ('ConcatV2_0', {
  1131. 'block': P.Concat(),
  1132. 'desc_inputs': [
  1133. (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  1134. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
  1135. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  1136. ('ConcatV2_1', {
  1137. 'block': P.Concat(axis=2),
  1138. 'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  1139. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
  1140. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  1141. ('ConcatV2_2', {
  1142. 'block': NetForConcat(),
  1143. 'desc_inputs': [[2, 2]],
  1144. 'desc_bprop': [[4, 2]]}),
  1145. ('ConcatV2_3', {
  1146. 'block': NetForConcat1(),
  1147. 'desc_inputs': [[2, 2], [2, 2]],
  1148. 'desc_bprop': [[4, 2]]}),
  1149. ('ConcatV2_4', {
  1150. 'block': P.Concat(axis=0),
  1151. 'desc_inputs': [
  1152. (Tensor(np.ones((3, 2, 3), np.float32)),
  1153. Tensor(np.ones((5, 2, 3), np.float32)),
  1154. Tensor(np.ones((6, 2, 3), np.float32)))],
  1155. 'desc_bprop': [[14, 2, 3]]}),
  1156. ('ConcatV2_5', {
  1157. 'block': P.Concat(axis=-1),
  1158. 'desc_inputs': [(Tensor(np.array([1], np.float32)),
  1159. Tensor(np.array([1], np.float32)),
  1160. Tensor(np.array([1], np.float32)))],
  1161. 'desc_bprop': [[3,]]}),
  1162. ('Pack_0', {
  1163. 'block': NetForPackInput(P.Pack()),
  1164. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1165. 'desc_bprop': [[3, 2, 2]],
  1166. }),
  1167. ('Pack_1', {
  1168. 'block': NetForPackInput(P.Pack(axis=-2)),
  1169. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  1170. 'desc_bprop': [[3, 2, 3, 3]],
  1171. }),
  1172. ('Pack_2', {
  1173. 'block': NetForPackInput(P.Pack()),
  1174. 'desc_inputs': [[128, 128], [128, 128]],
  1175. 'desc_bprop': [[2, 128, 128]],
  1176. }),
  1177. ('Unpack_0', {
  1178. 'block': NetForUnpackInput(P.Unpack(axis=0)),
  1179. 'desc_inputs': [[2, 4]],
  1180. 'desc_bprop': [[4], [4]],
  1181. }),
  1182. ('Unpack_1', {
  1183. 'block': NetForUnpackInput(P.Unpack(axis=-1)),
  1184. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  1185. 'desc_bprop': [[1], [1], [1]],
  1186. }),
  1187. ('Diag_1', {
  1188. 'block': P.Diag(),
  1189. 'desc_inputs': [[4]],
  1190. 'desc_bprop': [[4, 4]],
  1191. }),
  1192. ('Diag_2', {
  1193. 'block': P.Diag(),
  1194. 'desc_inputs': [[4, 4]],
  1195. 'desc_bprop': [[4, 4, 4, 4]],
  1196. }),
  1197. ('DiagPart_1', {
  1198. 'block': P.DiagPart(),
  1199. 'desc_inputs': [[4, 4]],
  1200. 'desc_bprop': [[4]],
  1201. }),
  1202. ('DiagPart_2', {
  1203. 'block': P.DiagPart(),
  1204. 'desc_inputs': [[4, 4, 4, 4]],
  1205. 'desc_bprop': [[4, 4]],
  1206. }),
  1207. ('SpaceToBatch_1', {
  1208. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  1209. 'desc_inputs': [[1, 3, 2, 2]],
  1210. 'desc_bprop': [[4, 3, 1, 1]],
  1211. }),
  1212. ('SpaceToBatch_2', {
  1213. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  1214. 'desc_inputs': [[1, 3, 2, 2]],
  1215. 'desc_bprop': [[4, 3, 2, 3]],
  1216. }),
  1217. ('BatchToSpace_1', {
  1218. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  1219. 'desc_inputs': [[4, 3, 1, 1]],
  1220. 'desc_bprop': [[1, 3, 2, 2]],
  1221. }),
  1222. ('BatchToSpace_2', {
  1223. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  1224. 'desc_inputs': [[4, 3, 1, 1]],
  1225. 'desc_bprop': [[1, 3, 2, 1]],
  1226. }),
  1227. ('UnsortedSegmentMin_1', {
  1228. 'block': P.UnsortedSegmentMin(),
  1229. 'desc_const': [2],
  1230. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  1231. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  1232. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  1233. ]
  1234. test_case_other_ops = [
  1235. ('ScalarLog', {
  1236. 'block': F.scalar_log,
  1237. 'desc_const': [0.0],
  1238. 'desc_inputs': [],
  1239. 'desc_bprop': [1],
  1240. 'skip': ['backward']}),
  1241. ('BoundingBoxEncode', {
  1242. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  1243. 'desc_inputs': [[256, 4], [256, 4]],
  1244. 'desc_bprop': [[256, 4]],
  1245. 'skip': ['backward']}),
  1246. ('BoundingBoxDecode', {
  1247. '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)),
  1248. 'desc_inputs': [[256, 4], [256, 4]],
  1249. 'desc_bprop': [[256, 4]],
  1250. 'skip': ['backward']}),
  1251. ('GatherNd', {
  1252. 'block': P.GatherNd(),
  1253. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  1254. Tensor(np.ones((2, 4), np.int32))),
  1255. 'desc_bprop': [[2]]}),
  1256. ('ScatterNd', {
  1257. 'block': P.ScatterNd(),
  1258. 'desc_const': [(3, 3)],
  1259. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  1260. Tensor(np.ones((2,), np.int32))),
  1261. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  1262. ('ScatterMax', {
  1263. 'block': ScatterMax(),
  1264. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1265. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  1266. 'skip': ['backward']}),
  1267. ('ScatterAdd', {
  1268. 'block': ScatterAdd((6,)),
  1269. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1270. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1271. 'skip': ['backward']}),
  1272. ('ScatterAdd2d', {
  1273. 'block': ScatterAdd((3, 4)),
  1274. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1275. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1276. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1277. 'skip': ['backward']}),
  1278. ('SmoothL1Loss', {
  1279. 'block': P.SmoothL1Loss(),
  1280. 'desc_inputs': [[256, 4], [256, 4]],
  1281. 'desc_bprop': [[256, 4]]}),
  1282. ('IOU', {
  1283. 'block': P.IOU(),
  1284. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  1285. 'desc_bprop': [[128, 256]]}),
  1286. ('Summary', {
  1287. 'block': SummaryNet(),
  1288. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1289. Tensor(np.array([1.2]).astype(np.float32))],
  1290. 'skip': ['backward']}),
  1291. ('ConfusionMulGrad_1', {
  1292. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
  1293. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1294. 'desc_bprop': [[3, 2], [2]],
  1295. 'skip': ['backward']}),
  1296. ('ConfusionMulGrad_2', {
  1297. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
  1298. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1299. 'desc_bprop': [[3, 2], [1, 2]],
  1300. 'skip': ['backward']}),
  1301. ('ConfusionMulGrad_3', {
  1302. 'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
  1303. 'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
  1304. 'desc_bprop': [[2, 3, 4], [1, 1, 1]],
  1305. 'skip': ['backward']}),
  1306. ('HistogramSummary', {
  1307. 'block': HistogramSummaryNet(),
  1308. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1309. Tensor(np.array([1.2]).astype(np.float32))],
  1310. 'skip': ['backward']}),
  1311. ]
  1312. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops]
  1313. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  1314. # use -k to select certain testcast
  1315. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  1316. test_exec_case = test_case
  1317. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or
  1318. 'backward' not in x[1]['skip'], test_case)
  1319. @non_graph_engine
  1320. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  1321. def test_exec():
  1322. context.set_context(mode=context.GRAPH_MODE)
  1323. return test_exec_case
  1324. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  1325. def test_backward_exec():
  1326. context.set_context(mode=context.GRAPH_MODE)
  1327. return test_backward_exec_case
  1328. raise_set = [
  1329. ('Cast_Error', {
  1330. 'block': (P.Cast(), {'exception': TypeError}),
  1331. 'desc_const': [mstype.int32],
  1332. 'desc_inputs': ['wrong input'],
  1333. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  1334. ('Maximum_Error', {
  1335. 'block': (P.Maximum(), {'exception': TypeError}),
  1336. 'desc_const': [(1, 2, 3)],
  1337. 'desc_inputs': [[2, 3, 3, 5]],
  1338. 'desc_bprop': [[2, 3, 3, 5]]}),
  1339. ('Shape_error', {
  1340. 'block': (P.Shape(), {'exception': TypeError}),
  1341. 'desc_inputs': [(64, 1)],
  1342. 'desc_bprop': [[64]]}),
  1343. ('Flatten_Error', {
  1344. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  1345. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  1346. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  1347. ('ScatterNdUpdate', {
  1348. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  1349. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  1350. Tensor(np.ones((2, 2), np.float32)),
  1351. Tensor(np.ones((2,), np.float32))),
  1352. 'desc_bprop': [[2, 3]]}),
  1353. ('Pack', {
  1354. 'block': (NetForPackInput(P.Pack()), {'exception': ValueError}),
  1355. 'desc_inputs': [[2, 2]],
  1356. 'desc_bprop': [[1, 2, 2]]}),
  1357. ('PReLU', {
  1358. 'block': (P.PReLU(), {'exception': ValueError}),
  1359. 'desc_inputs': [[2], [1]],
  1360. 'desc_bprop': [[1]]}),
  1361. ]
  1362. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  1363. def test_check_exception():
  1364. return raise_set