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

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