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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  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 mindspore.ops.operations import _inner_ops as inner
  27. from ..ut_filter import non_graph_engine
  28. from ....mindspore_test_framework.mindspore_test import mindspore_test
  29. from ....mindspore_test_framework.pipeline.forward.compile_forward \
  30. import (pipeline_for_compile_forward_ge_graph_for_case_by_case_config,
  31. pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  32. from ....mindspore_test_framework.pipeline.gradient.compile_gradient \
  33. import pipeline_for_compile_grad_ge_graph_for_case_by_case_config
  34. def test_tensor_scatter_update():
  35. class TensorScatterUpdateNet(nn.Cell):
  36. """TensorScatterUpdate net definition"""
  37. def __init__(self):
  38. super(TensorScatterUpdateNet, self).__init__()
  39. self.tensor_scatter_update = P.TensorScatterUpdate()
  40. def construct(self, x, i, u):
  41. out = self.tensor_scatter_update(x, i, u)
  42. return out
  43. net = TensorScatterUpdateNet()
  44. context.set_context(mode=context.GRAPH_MODE, save_graphs=True)
  45. x = Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32)
  46. indices = Tensor(np.array([[0, 0], [1, 1]], np.int32))
  47. updates = Tensor(np.ones([2, 5], np.float32))
  48. net(x, indices, updates)
  49. class InputBackward(nn.Cell):
  50. def __init__(self, network):
  51. super(InputBackward, self).__init__()
  52. self.network = network
  53. self.network.set_train()
  54. self.grad = C.grad_all_with_sens
  55. def construct(self, x1, x2, x3, sens):
  56. return self.grad(self.network)(x1, x2, x3, sens)
  57. class NetForTupleInput(nn.Cell):
  58. def __init__(self, op):
  59. super(NetForTupleInput, self).__init__()
  60. self.op = op
  61. def construct(self, x1, x2):
  62. return self.op((x1, x2))
  63. class StridedSlicessdNet(nn.Cell):
  64. def __init__(self):
  65. super(StridedSlicessdNet, self).__init__()
  66. self.rank = P.Rank()
  67. def construct(self, x1):
  68. return P.StridedSlice(1, 1, 0, self.rank(x1), 0)(x1, (0, 0), (0, 0), (1, 1))
  69. class NetForConcat(nn.Cell):
  70. def __init__(self):
  71. super(NetForConcat, self).__init__()
  72. self.concat = P.Concat()
  73. def construct(self, x1):
  74. return self.concat((x1, x1))
  75. class NetForConcat1(nn.Cell):
  76. def __init__(self):
  77. super(NetForConcat1, self).__init__()
  78. self.concat = P.Concat()
  79. def construct(self, x1, x2):
  80. return self.concat((x1, x2))
  81. class NetForPackInput(nn.Cell):
  82. def __init__(self, op):
  83. super(NetForPackInput, self).__init__()
  84. self.op = op
  85. self.mul = P.Mul()
  86. def construct(self, *args):
  87. t = ()
  88. for element in args:
  89. t = t + (self.mul(element, element),)
  90. return self.op(t)
  91. class NetForUnpackInput(nn.Cell):
  92. def __init__(self, op):
  93. super(NetForUnpackInput, self).__init__()
  94. self.op = op
  95. self.mul = P.Mul()
  96. def construct(self, x1):
  97. return self.op((self.mul(x1, x1)))
  98. class NetForFlatten(nn.Cell):
  99. def __init__(self):
  100. super(NetForFlatten, self).__init__()
  101. self.flatten = P.Flatten()
  102. def construct(self, x, y):
  103. return self.flatten(x) + y
  104. class NetForFlatten0D(nn.Cell):
  105. def __init__(self):
  106. super(NetForFlatten0D, self).__init__()
  107. self.flatten = P.Flatten()
  108. def construct(self, x):
  109. return self.flatten(x)
  110. class NetForFlattenComposed(nn.Cell):
  111. # make flatten op together with other ops for testing flatten grad
  112. def __init__(self):
  113. super(NetForFlattenComposed, self).__init__()
  114. self.flatten = P.Flatten()
  115. def construct(self, x, y):
  116. return self.flatten(x + x) + y
  117. class ArgmaxNet(nn.Cell):
  118. def __init__(self):
  119. super(ArgmaxNet, self).__init__()
  120. self.argmax = P.Argmax(axis=1)
  121. def construct(self, input_):
  122. return self.argmax(input_)
  123. class ArgminNet(nn.Cell):
  124. def __init__(self):
  125. super(ArgminNet, self).__init__()
  126. self.argmin = P.Argmin(axis=1)
  127. def construct(self, input_):
  128. return self.argmin(input_)
  129. class CumSumNet(nn.Cell):
  130. def __init__(self):
  131. super(CumSumNet, self).__init__()
  132. self.cumsum = P.CumSum()
  133. self.axis = 1
  134. def construct(self, input_):
  135. return self.cumsum(input_, self.axis)
  136. class SummaryNet(nn.Cell):
  137. def __init__(self):
  138. super(SummaryNet, self).__init__()
  139. self.s = P.ScalarSummary()
  140. self.add = P.TensorAdd()
  141. def construct(self, x, y):
  142. self.s("x1", x)
  143. return self.add(x, y)
  144. class HistogramSummaryNet(nn.Cell):
  145. def __init__(self):
  146. super(HistogramSummaryNet, self).__init__()
  147. self.summary = P.HistogramSummary()
  148. self.add = P.TensorAdd()
  149. def construct(self, x, y):
  150. out = self.add(x, y)
  151. string_in = "out"
  152. self.summary(string_in, out)
  153. return out
  154. class ScatterMax(nn.Cell):
  155. """ScatterMax net definition"""
  156. def __init__(self):
  157. super(ScatterMax, self).__init__()
  158. self.scatter_max = P.ScatterMax()
  159. self.ref = Parameter(Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], np.float32)), name="ref")
  160. def construct(self, indices, updates):
  161. out = self.scatter_max(self.ref, indices, updates)
  162. return out
  163. class ScatterAdd(nn.Cell):
  164. """ScatterAdd net definition"""
  165. def __init__(self, ref_shape):
  166. super(ScatterAdd, self).__init__()
  167. self.scatter_add = P.ScatterAdd()
  168. self.ref = Parameter(Tensor(np.ones(ref_shape, np.float32)), name="ref")
  169. def construct(self, indices, updates):
  170. out = self.scatter_add(self.ref, indices, updates)
  171. return out
  172. class ApplyFtrlNet(nn.Cell):
  173. def __init__(self):
  174. super(ApplyFtrlNet, self).__init__()
  175. self.apply_ftrl = P.ApplyFtrl()
  176. self.lr = 0.001
  177. self.l1 = 0.0
  178. self.l2 = 0.0
  179. self.lr_power = -0.5
  180. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  181. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  182. self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")
  183. def construct(self, grad):
  184. out = self.apply_ftrl(self.var, self.accum, self.linear, grad, self.lr, self.l1, self.l2, self.lr_power)
  185. return out
  186. class SparseApplyFtrlNet(nn.Cell):
  187. def __init__(self):
  188. super(SparseApplyFtrlNet, self).__init__()
  189. self.sparse_apply_ftrl = P.SparseApplyFtrl(lr=0.001, l1=0.0, l2=0.0, lr_power=-0.5)
  190. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  191. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  192. self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")
  193. def construct(self, grad, indices):
  194. out = self.sparse_apply_ftrl(self.var, self.accum, self.linear, grad, indices)
  195. return out
  196. class SparseApplyProximalAdagradNet(nn.Cell):
  197. def __init__(self):
  198. super(SparseApplyProximalAdagradNet, self).__init__()
  199. self.sparse_apply_proximal_adagrad = P.SparseApplyProximalAdagrad()
  200. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  201. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  202. self.lr = 0.01
  203. self.l1 = 0.0
  204. self.l2 = 0.0
  205. def construct(self, grad, indices):
  206. out = self.sparse_apply_proximal_adagrad(self.var, self.accum, self.lr, self.l1, self.l2, grad, indices)
  207. return out
  208. class ApplyProximalAdagradNet(nn.Cell):
  209. def __init__(self):
  210. super(ApplyProximalAdagradNet, self).__init__()
  211. self.apply_proximal_adagrad = P.ApplyProximalAdagrad()
  212. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  213. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  214. self.lr = 0.01
  215. self.l1 = 0.0
  216. self.l2 = 0.0
  217. def construct(self, grad):
  218. out = self.apply_proximal_adagrad(self.var, self.accum, self.lr, self.l1, self.l2, grad)
  219. return out
  220. class ApplyAdaMaxNet(nn.Cell):
  221. def __init__(self):
  222. super(ApplyAdaMaxNet, self).__init__()
  223. self.apply_ada_max = P.ApplyAdaMax()
  224. self.beta1_power = 0.9
  225. self.lr = 0.001
  226. self.beta1 = 0.9
  227. self.beta2 = 0.99
  228. self.epsilon = 1e-10
  229. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  230. self.m = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="m")
  231. self.v = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="v")
  232. def construct(self, grad):
  233. out = self.apply_ada_max(self.var, self.m, self.v, self.beta1_power, self.lr,
  234. self.beta1, self.beta2, self.epsilon, grad)
  235. return out
  236. class ApplyAdadeltaNet(nn.Cell):
  237. def __init__(self):
  238. super(ApplyAdadeltaNet, self).__init__()
  239. self.apply_adadelta = P.ApplyAdadelta()
  240. self.lr = 0.001
  241. self.rho = 0.0
  242. self.epsilon = 1e-6
  243. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  244. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  245. self.accum_update = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum_update")
  246. def construct(self, grad):
  247. out = self.apply_adadelta(self.var, self.accum, self.accum_update, self.lr, self.rho, self.epsilon, grad)
  248. return out
  249. class ApplyAdagradNet(nn.Cell):
  250. def __init__(self):
  251. super(ApplyAdagradNet, self).__init__()
  252. self.apply_adagrad = P.ApplyAdagrad()
  253. self.lr = 0.001
  254. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  255. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  256. def construct(self, grad):
  257. out = self.apply_adagrad(self.var, self.accum, self.lr, grad)
  258. return out
  259. class ApplyAdagradV2Net(nn.Cell):
  260. def __init__(self):
  261. super(ApplyAdagradV2Net, self).__init__()
  262. self.apply_adagrad_v2 = P.ApplyAdagradV2(epsilon=1e-6)
  263. self.lr = 0.001
  264. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  265. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  266. def construct(self, grad):
  267. out = self.apply_adagrad_v2(self.var, self.accum, self.lr, grad)
  268. return out
  269. class SparseApplyAdagradNet(nn.Cell):
  270. def __init__(self):
  271. super(SparseApplyAdagradNet, self).__init__()
  272. self.sparse_apply_adagrad = P.SparseApplyAdagrad(lr=0.01)
  273. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  274. self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
  275. def construct(self, grad, indices):
  276. out = self.sparse_apply_adagrad(self.var, self.accum, grad, indices)
  277. return out
  278. class ApplyRMSNet(nn.Cell):
  279. def __init__(self):
  280. super(ApplyRMSNet, self).__init__()
  281. self.apply_rms = P.ApplyRMSProp()
  282. self.lr = 0.001
  283. self.rho = 0.0
  284. self.momentum = 0.0
  285. self.epsilon = 1e-10
  286. self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
  287. self.ms = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="ms")
  288. self.moment = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="moment")
  289. def construct(self, grad):
  290. out = self.apply_rms(self.var, self.ms, self.moment, self.lr, grad, self.rho, self.momentum, self.epsilon)
  291. return out
  292. class InplaceAddNet(nn.Cell):
  293. def __init__(self):
  294. super(InplaceAddNet, self).__init__()
  295. self.inplace_add = P.InplaceAdd(indices=(0, 1))
  296. def construct(self, x, v):
  297. out = self.inplace_add(x, v)
  298. return out
  299. class InplaceSubNet(nn.Cell):
  300. def __init__(self):
  301. super(InplaceSubNet, self).__init__()
  302. self.inplace_sub = P.InplaceSub(indices=(0, 1))
  303. def construct(self, x, v):
  304. out = self.inplace_sub(x, v)
  305. return out
  306. class NormalNet(nn.Cell):
  307. def __init__(self, shape=None, mean=0.0, stddev=1.0, seed=0):
  308. super(NormalNet, self).__init__()
  309. self.normal = P.Normal(seed=seed)
  310. self.shape = shape
  311. self.mean = Tensor(mean, mstype.float32)
  312. self.stddev = Tensor(stddev, mstype.float32)
  313. def construct(self):
  314. out = self.normal(self.shape, self.mean, self.stddev)
  315. return out
  316. test_case_math_ops = [
  317. ('BitwiseAnd', {
  318. 'block': P.BitwiseAnd(),
  319. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  320. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  321. 'skip': ['backward']}),
  322. ('BitwiseAnd_1', {
  323. 'block': P.BitwiseAnd(),
  324. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  325. Tensor(np.array([1, 1, 1]), mstype.int16)],
  326. 'skip': ['backward']}),
  327. ('BitwiseOr', {
  328. 'block': P.BitwiseOr(),
  329. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  330. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  331. 'skip': ['backward']}),
  332. ('BitwiseOr_1', {
  333. 'block': P.BitwiseOr(),
  334. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  335. Tensor(np.array([1, 1, 1]), mstype.int16)],
  336. 'skip': ['backward']}),
  337. ('BitwiseXor', {
  338. 'block': P.BitwiseXor(),
  339. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  340. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  341. 'skip': ['backward']}),
  342. ('BitwiseXor_1', {
  343. 'block': P.BitwiseXor(),
  344. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  345. Tensor(np.array([1, 1, 1]), mstype.int16)],
  346. 'skip': ['backward']}),
  347. ('Neg', {
  348. 'block': P.Neg(),
  349. 'desc_inputs': [[1, 3, 4, 4]],
  350. 'desc_bprop': [[1, 3, 4, 4]]}),
  351. ('Sub', {
  352. 'block': P.Sub(),
  353. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  354. 'desc_bprop': [[2, 3, 3, 5]]}),
  355. ('TensorAdd', {
  356. 'block': P.TensorAdd(),
  357. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  358. 'desc_bprop': [[2, 3, 3, 5]]}),
  359. ('Mul0', {
  360. 'block': P.Mul(),
  361. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  362. 'desc_bprop': [[2, 3, 3, 5]]}),
  363. ('Mul1', {
  364. 'block': P.Mul(),
  365. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  366. 'desc_bprop': [[2, 3, 3, 5]]}),
  367. ('Mul2', {
  368. 'block': P.Mul(),
  369. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  370. 'desc_bprop': [[2, 3, 3, 5]],
  371. 'skip': ['backward']}),
  372. ('Mul3', {
  373. 'block': P.Mul(),
  374. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  375. 'desc_bprop': [[2, 3, 3, 5]],
  376. 'skip': ['backward']}),
  377. ('Mul4', {
  378. 'block': P.Mul(),
  379. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  380. 'desc_bprop': [[2, 3, 3, 5]],
  381. 'skip': ['backward']}),
  382. ('Add0', {
  383. 'block': P.TensorAdd(),
  384. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  385. 'desc_bprop': [[2, 3, 3, 5]]}),
  386. ('Add1', {
  387. 'block': P.TensorAdd(),
  388. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  389. 'desc_bprop': [[2, 3, 3, 5]],
  390. 'skip': ['backward']}),
  391. ('Add2', {
  392. 'block': P.TensorAdd(),
  393. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  394. 'desc_bprop': [[2, 3, 3, 5]],
  395. 'skip': ['backward']}),
  396. ('Add3', {
  397. 'block': P.TensorAdd(),
  398. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  399. 'desc_bprop': [[2, 3, 3, 5]],
  400. 'skip': ['backward']}),
  401. ('Add4', {
  402. 'block': P.TensorAdd(),
  403. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  404. 'desc_bprop': [[2, 3, 3, 5]],
  405. 'skip': ['backward']}),
  406. ('Minimum', {
  407. 'block': P.Minimum(),
  408. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  409. 'desc_bprop': [[2, 3, 3, 5]]}),
  410. ('Pow_0', {
  411. 'block': P.Pow(),
  412. 'desc_const': [2.0],
  413. 'desc_inputs': [[2, 3, 3, 5]],
  414. 'desc_bprop': [[2, 3, 3, 5]]}),
  415. ('Pow_1', {
  416. 'block': P.Pow(),
  417. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  418. 'desc_bprop': [[2, 3, 3, 5]]}),
  419. ('Exp', {
  420. 'block': P.Exp(),
  421. 'desc_inputs': [[2, 3]],
  422. 'desc_bprop': [[2, 3]]}),
  423. ('Expm1', {
  424. 'block': P.Expm1(),
  425. 'desc_inputs': [[2, 3]],
  426. 'desc_bprop': [[2, 3]]}),
  427. ('Erf', {
  428. 'block': P.Erf(),
  429. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  430. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  431. ('Floor', {
  432. 'block': P.Floor(),
  433. 'desc_inputs': [[2, 512, 56, 56]],
  434. 'desc_bprop': [[2, 512, 56, 56]],
  435. 'skip': ['backward']}),
  436. ('Ceil', {
  437. 'block': P.Ceil(),
  438. 'desc_inputs': [[2, 512, 56, 56]],
  439. 'desc_bprop': [[2, 512, 56, 56]],
  440. 'skip': ['backward']}),
  441. ('InplaceAdd', {
  442. 'block': InplaceAddNet(),
  443. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  444. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  445. 'skip': ['backward']}),
  446. ('InplaceSub', {
  447. 'block': InplaceSubNet(),
  448. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  449. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  450. 'skip': ['backward']}),
  451. ('ACos', {
  452. 'block': P.ACos(),
  453. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  454. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  455. ('ACosGrad', {
  456. 'block': G.ACosGrad(),
  457. 'desc_inputs': [[2, 3], [2, 3]],
  458. 'skip': ['backward']}),
  459. ('Acosh', {
  460. 'block': P.Acosh(),
  461. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  462. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  463. ('AcoshGrad', {
  464. 'block': G.AcoshGrad(),
  465. 'desc_inputs': [[2, 3], [2, 3]],
  466. 'skip': ['backward']}),
  467. ('Sin', {
  468. 'block': P.Sin(),
  469. 'desc_inputs': [[2, 3]],
  470. 'desc_bprop': [[2, 3]]}),
  471. ('Asin', {
  472. 'block': P.Asin(),
  473. 'desc_inputs': [[2, 3]],
  474. 'desc_bprop': [[2, 3]]}),
  475. ('Asinh', {
  476. 'block': P.Asinh(),
  477. 'desc_inputs': [[3, 4, 5]],
  478. 'desc_bprop': [[3, 4, 5]]}),
  479. ('Reciprocal', {
  480. 'block': P.Reciprocal(),
  481. 'desc_inputs': [[2, 3, 3, 5]],
  482. 'desc_bprop': [[2, 3, 3, 5]]}),
  483. ('Minimum_0', {
  484. 'block': P.Minimum(),
  485. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  486. 'desc_bprop': [[2, 3, 3, 5]]}),
  487. ('Maximum', {
  488. 'block': P.Maximum(),
  489. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  490. 'desc_bprop': [[2, 3, 3, 5]]}),
  491. ('Maximum_0', {
  492. 'block': P.Maximum(),
  493. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  494. 'desc_bprop': [[2, 3, 3, 5]]}),
  495. ('MaximumGrad', {
  496. 'block': G.MaximumGrad(),
  497. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  498. 'skip': ['backward']}),
  499. ('MinimumGrad', {
  500. 'block': G.MinimumGrad(),
  501. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  502. 'skip': ['backward']}),
  503. ('StridedSlice', {
  504. 'block': P.StridedSlice(),
  505. 'desc_const': [(0, 1, 2, 1),
  506. (2, 3, 3, 4),
  507. (1, 1, 1, 1)],
  508. 'desc_inputs': [[2, 3, 3, 5]],
  509. 'desc_bprop': [[2, 2, 1, 3]]}),
  510. ('Slice_1', {
  511. 'block': P.Slice(),
  512. 'desc_const': [(0, 1, 2, 1),
  513. (1, 1, 1, 2)],
  514. 'desc_inputs': [[2, 3, 3, 5]],
  515. 'desc_bprop': [[1, 1, 1, 2]]}),
  516. ('StridedSliceGrad', {
  517. 'block': G.StridedSliceGrad(),
  518. 'desc_const': [(64, 1, 1024),
  519. (0, 1, 0),
  520. (64, 2, 1024),
  521. (1, 1, 1)],
  522. 'desc_inputs': [[64, 128, 1024]],
  523. 'skip': ['backward']}),
  524. ('RandomChoiceWithMask', {
  525. 'block': P.RandomChoiceWithMask(256),
  526. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  527. 'desc_bprop': [[256, 4], [256, 4]],
  528. 'skip': ['backward']}),
  529. ('LessEqual', {
  530. 'block': P.LessEqual(),
  531. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  532. Tensor(np.random.rand(4).astype(np.float16))],
  533. 'skip': ['backward']}),
  534. ('Less', {
  535. 'block': P.Less(),
  536. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  537. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  538. 'skip': ['backward']}),
  539. ('RealDiv_0', {
  540. 'block': P.RealDiv(),
  541. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  542. 'desc_inputs': [],
  543. 'skip': ['backward']}),
  544. ('RealDiv', {
  545. 'block': P.RealDiv(),
  546. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  547. 'desc_bprop': [[4]]}),
  548. ('RealDiv_1', {
  549. 'block': P.RealDiv(),
  550. 'desc_inputs': [[512, 1024], [512, 1024]],
  551. 'desc_bprop': [[512, 1024]]}),
  552. ('FloorDiv', {
  553. 'block': P.FloorDiv(),
  554. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  555. Tensor(np.random.rand(4).astype(np.float16))],
  556. 'skip': ['backward']}),
  557. ('FloorMod', {
  558. 'block': P.FloorMod(),
  559. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  560. 'desc_bprop': [[2, 3, 4, 5]]}),
  561. ('identity', {
  562. 'block': ops.functional.identity,
  563. 'desc_inputs': [[2, 2]],
  564. 'skip': ['backward']}),
  565. ('MatMul_1', {
  566. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  567. 'desc_inputs': [[1024, 160], [160, 1024]],
  568. 'desc_bprop': [[1024, 1024]]}),
  569. ('MatMul_2', {
  570. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  571. 'desc_inputs': [[160, 1024], [1024, 160]],
  572. 'desc_bprop': [[1024, 1024]]}),
  573. ('Sub', {
  574. 'block': P.Sub(),
  575. 'desc_inputs': [[3], [3]],
  576. 'desc_bprop': [[3]]}),
  577. ('TruncatedNormal', {
  578. 'block': P.TruncatedNormal(),
  579. 'desc_const': [(1, 2, 3)],
  580. 'desc_inputs': [],
  581. 'skip': ['backward'],
  582. 'add_fake_input': True}),
  583. ('Select', {
  584. 'block': P.Select(),
  585. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  586. [2, 3], [2, 3]],
  587. 'desc_bprop': [[2, 3]]}),
  588. ('Rank', {
  589. 'block': P.Rank(),
  590. 'desc_inputs': [[2, 3]],
  591. 'skip': ['backward']}),
  592. ('InvertPermutation', {
  593. 'block': P.InvertPermutation(),
  594. 'desc_const': [(0, 3, 1, 2)],
  595. 'desc_inputs': [],
  596. 'skip': ['backward']}),
  597. ('Square', {
  598. 'block': P.Square(),
  599. 'desc_inputs': [[4]],
  600. 'desc_bprop': [[4]]}),
  601. ('Rsqrt', {
  602. 'block': P.Rsqrt(),
  603. 'desc_inputs': [[4]],
  604. 'desc_bprop': [[4]]}),
  605. ('Sqrt', {
  606. 'block': P.Sqrt(),
  607. 'desc_inputs': [[4]],
  608. 'desc_bprop': [[4]]}),
  609. ('RealDiv', {
  610. 'block': P.RealDiv(),
  611. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  612. 'desc_bprop': [[2, 3, 4, 5]]}),
  613. ('Div', {
  614. 'block': P.Div(),
  615. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  616. 'desc_bprop': [[2, 3, 4, 5]]}),
  617. ('Equal', {
  618. 'block': P.Equal(),
  619. 'desc_inputs': [[3, 4, 5], [4, 5]],
  620. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  621. ('NotEqual', {
  622. 'block': P.NotEqual(),
  623. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  624. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  625. ('NotEqual_0', {
  626. 'block': P.NotEqual(),
  627. 'desc_inputs': [1, [2, 3, 4, 5]],
  628. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  629. 'skip': ['backward']}),
  630. ('ApproximateEqual', {
  631. 'block': P.ApproximateEqual(),
  632. 'desc_inputs': [[3, 4, 5], [3, 4, 5]],
  633. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  634. ('Greater', {
  635. 'block': P.Greater(),
  636. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  637. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  638. ('GreaterEqual', {
  639. 'block': P.GreaterEqual(),
  640. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  641. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  642. ('LogicalNot', {
  643. 'block': P.LogicalNot(),
  644. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  645. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  646. ('LogicalAnd', {
  647. 'block': P.LogicalAnd(),
  648. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  649. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  650. ('LogicalOr', {
  651. 'block': P.LogicalOr(),
  652. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  653. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  654. ('NpuAllocFloatStatus', {
  655. 'block': P.NPUAllocFloatStatus(),
  656. 'desc_inputs': [],
  657. 'add_fack_input': True,
  658. 'fack_input_type': np.float32,
  659. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  660. 'skip': ['backward']}),
  661. ('NpuGetFloatStatus', {
  662. 'block': P.NPUGetFloatStatus(),
  663. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  664. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  665. 'skip': ['backward']}),
  666. ('NpuClearFloatStatus', {
  667. 'block': P.NPUClearFloatStatus(),
  668. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  669. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  670. 'skip': ['backward']}),
  671. ('CheckValid', {
  672. 'block': P.CheckValid(),
  673. 'desc_inputs': [[20000, 4], [3]],
  674. 'desc_bprop': [[20000]],
  675. 'skip': ['backward']}),
  676. ('NMSWithMask', {
  677. 'block': P.NMSWithMask(0.5),
  678. 'desc_inputs': [[128, 5]],
  679. 'desc_bprop': [[128, 5], [128], [128]],
  680. 'skip': ['backward']}),
  681. ('Abs', {
  682. 'block': P.Abs(),
  683. 'desc_inputs': [[4]],
  684. 'desc_bprop': [[4]]}),
  685. ('CumSum', {
  686. 'block': CumSumNet(),
  687. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  688. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  689. [1, 3, 7, 9]]).astype(np.float32))]}),
  690. ('ReduceSum_3', {
  691. 'block': P.ReduceSum(),
  692. 'desc_const': [0],
  693. 'desc_inputs': [[3, 2]],
  694. 'desc_bprop': [[2]]}),
  695. ('ReduceSum_4', {
  696. 'block': P.ReduceSum(keep_dims=True),
  697. 'desc_const': [0],
  698. 'desc_inputs': [[3, 2]],
  699. 'desc_bprop': [[1, 2]]}),
  700. ('ReduceSum_5', {
  701. 'block': P.ReduceSum(keep_dims=True),
  702. 'desc_inputs': [[2, 3, 4]],
  703. 'desc_bprop': [[1, 1, 1]]}),
  704. ('ReduceSum_6', {
  705. 'block': P.ReduceSum(),
  706. 'desc_inputs': [[2, 3, 4]],
  707. 'desc_bprop': [[1]]}),
  708. ('Sum_0', {
  709. 'block': P.ReduceSum(),
  710. 'desc_const': [(1,)],
  711. 'desc_inputs': [[3, 2]],
  712. 'desc_bprop': [[3]]}),
  713. ('Sum_1', {
  714. 'block': P.ReduceSum(keep_dims=True),
  715. 'desc_const': [(1,)],
  716. 'desc_inputs': [[3, 2]],
  717. 'desc_bprop': [[3, 1]]}),
  718. ('Sum_2', {
  719. 'block': P.ReduceSum(),
  720. 'desc_const': [(0, 1)],
  721. 'desc_inputs': [[3, 2]],
  722. 'desc_bprop': [[1]]}),
  723. ('Sum_3', {
  724. 'block': P.ReduceSum(),
  725. 'desc_const': [0],
  726. 'desc_inputs': [[3, 2]],
  727. 'desc_bprop': [[2]]}),
  728. ('Sum_4', {
  729. 'block': P.ReduceSum(keep_dims=True),
  730. 'desc_const': [0],
  731. 'desc_inputs': [[3, 2]],
  732. 'desc_bprop': [[1, 2]]}),
  733. ('Sum_5', {
  734. 'block': P.ReduceSum(keep_dims=True),
  735. 'desc_const': [()],
  736. 'desc_inputs': [[2, 3, 4]],
  737. 'desc_bprop': [[1, 1, 1]]}),
  738. ('Sum_6', {
  739. 'block': P.ReduceSum(),
  740. 'desc_const': [()],
  741. 'desc_inputs': [[2, 3, 4]],
  742. 'desc_bprop': [[1]]}),
  743. ('Sign', {
  744. 'block': P.Sign(),
  745. 'desc_inputs': [[3]],
  746. 'desc_bprop': [[3]]}),
  747. ('Round', {
  748. 'block': P.Round(),
  749. 'desc_inputs': [[3]],
  750. 'desc_bprop': [[3]]}),
  751. ('Atan2', {
  752. 'block': P.Atan2(),
  753. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  754. Tensor(np.array([1, 1]).astype(np.float32))],
  755. 'desc_bprop': [[2]]}),
  756. ('SquareSumAll', {
  757. 'block': P.SquareSumAll(),
  758. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  759. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  760. 'skip': ['backward']}),
  761. ('Cos', {
  762. 'block': P.Cos(),
  763. 'desc_inputs': [[2, 3]],
  764. 'desc_bprop': [[2, 3]]}),
  765. ('ReduceAll', {
  766. 'block': P.ReduceAll(),
  767. 'desc_const': [1],
  768. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  769. 'desc_bprop': []}),
  770. ('BesselI0e', {
  771. 'block': P.BesselI0e(),
  772. 'desc_inputs': [[2, 3]],
  773. 'desc_bprop': [[2, 3]]}),
  774. ('BesselI1e', {
  775. 'block': P.BesselI1e(),
  776. 'desc_inputs': [[2, 3]],
  777. 'desc_bprop': [[2, 3]]}),
  778. ('Atan', {
  779. 'block': P.Atan(),
  780. 'desc_inputs': [[2, 3]],
  781. 'desc_bprop': [[2, 3]]}),
  782. ('AtanGrad', {
  783. 'block': G.AtanGrad(),
  784. 'desc_inputs': [[2, 3], [2, 3]],
  785. 'skip': ['backward']}),
  786. ('Atanh', {
  787. 'block': P.Atanh(),
  788. 'desc_inputs': [[2, 3]],
  789. 'desc_bprop': [[2, 3]]}),
  790. ('Cosh', {
  791. 'block': P.Cosh(),
  792. 'desc_inputs': [[3, 4, 5]],
  793. 'desc_bprop': [[3, 4, 5]]}),
  794. ('Sinh', {
  795. 'block': P.Sinh(),
  796. 'desc_inputs': [[3, 4, 5]],
  797. 'desc_bprop': [[3, 4, 5]]}),
  798. ('Inv', {
  799. 'block': P.Inv(),
  800. 'desc_inputs': [[21, 9, 12, 5]],
  801. 'desc_bprop': [[21, 9, 12, 5]]}),
  802. ('Invert', {
  803. 'block': P.Invert(),
  804. 'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
  805. 'desc_bprop': [],
  806. 'skip': ['backward']}),
  807. ('HistogramFixedWidth', {
  808. 'block': P.HistogramFixedWidth(5),
  809. 'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
  810. 'desc_bprop': [],
  811. 'skip': ['backward']}),
  812. ('Normal', {
  813. 'block': NormalNet((3, 2, 4), 0.0, 1.0, 0),
  814. 'desc_inputs': [],
  815. 'skip': ['backward']}),
  816. ]
  817. test_case_nn_ops = [
  818. ('BiasAdd', {
  819. 'block': P.BiasAdd(),
  820. 'desc_inputs': [[1, 3, 3, 3], [3]],
  821. 'desc_bprop': [[1, 3, 3, 3]]}),
  822. ('BiasAddGrad', {
  823. 'block': G.BiasAddGrad(),
  824. 'desc_inputs': [[1, 3, 3, 3]],
  825. 'skip': ['backward']}),
  826. ('Gelu', {
  827. 'block': P.Gelu(),
  828. 'desc_inputs': [[1, 3, 4, 4]],
  829. 'desc_bprop': [[1, 3, 4, 4]]}),
  830. ('GeluGrad', {
  831. 'block': G.GeluGrad(),
  832. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  833. 'desc_bprop': [[2, 2]],
  834. 'skip': ['backward']}),
  835. ('Tanh', {
  836. 'block': P.Tanh(),
  837. 'desc_inputs': [[1, 3, 4, 4]],
  838. 'desc_bprop': [[1, 3, 4, 4]]}),
  839. ('TanhGrad', {
  840. 'block': G.TanhGrad(),
  841. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  842. 'desc_bprop': [[1, 3, 4, 4]],
  843. 'skip': ['backward']}),
  844. ('ReLU', {
  845. 'block': P.ReLU(),
  846. 'desc_inputs': [[1, 3, 4, 4]],
  847. 'desc_bprop': [[1, 3, 4, 4]]}),
  848. ('ReLU6', {
  849. 'block': P.ReLU6(),
  850. 'desc_inputs': [[1, 3, 4, 4]],
  851. 'desc_bprop': [[1, 3, 4, 4]]}),
  852. ('ReLUV2', {
  853. 'block': P.ReLUV2(),
  854. 'desc_inputs': [[1, 3, 4, 4]],
  855. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  856. ('ReLUGrad', {
  857. 'block': G.ReluGrad(),
  858. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  859. 'skip': ['backward']}),
  860. ('Softplus', {
  861. 'block': P.Softplus(),
  862. 'desc_inputs': [[1, 3, 4, 4]],
  863. 'desc_bprop': [[1, 3, 4, 4]]}),
  864. ('SoftplusGrad', {
  865. 'block': G.SoftplusGrad(),
  866. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  867. 'skip': ['backward']}),
  868. ('Elu', {
  869. 'block': P.Elu(),
  870. 'desc_inputs': [[2, 3, 4]],
  871. 'desc_bprop': [[2, 3, 4]]}),
  872. ('EluGrad', {
  873. 'block': G.EluGrad(),
  874. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  875. 'desc_bprop': [[2, 3, 4]],
  876. 'skip': ['backward']}),
  877. ('Sigmoid', {
  878. 'block': P.Sigmoid(),
  879. 'desc_inputs': [[1, 3, 4, 4]],
  880. 'desc_bprop': [[1, 3, 4, 4]]}),
  881. ('MaxPool', {
  882. 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  883. 'desc_inputs': [[100, 3, 28, 28]],
  884. 'desc_bprop': [[100, 3, 14, 14]]}),
  885. ('MaxPoolGrad', {
  886. 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  887. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  888. 'desc_bprop': [[3, 4, 6, 6]],
  889. 'skip': ['backward']}),
  890. ('AvgPool', {
  891. 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  892. 'desc_inputs': [[100, 3, 28, 28]],
  893. 'desc_bprop': [[100, 3, 14, 14]]}),
  894. ('AvgPoolGrad', {
  895. 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  896. 'desc_const': [(3, 4, 6, 6)],
  897. 'const_first': True,
  898. 'desc_inputs': [[3, 4, 6, 6]],
  899. 'desc_bprop': [[3, 4, 6, 6]],
  900. 'skip': ['backward']}),
  901. ('MaxPoolWithArgmax', {
  902. 'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
  903. 'desc_inputs': [[128, 32, 32, 64]],
  904. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
  905. ('SoftmaxCrossEntropyWithLogits', {
  906. 'block': P.SoftmaxCrossEntropyWithLogits(),
  907. 'desc_inputs': [[1, 10], [1, 10]],
  908. 'desc_bprop': [[1], [1, 10]],
  909. 'skip': ['backward_exec']}),
  910. ('Flatten', {
  911. 'block': P.Flatten(),
  912. 'desc_inputs': [[128, 32, 32, 64]],
  913. 'desc_bprop': [[128, 65536]]}),
  914. ('LogSoftmax', {
  915. 'block': P.LogSoftmax(),
  916. 'desc_inputs': [[64, 2]],
  917. 'desc_bprop': [[64, 2]]}),
  918. ('LogSoftmaxGrad', {
  919. 'block': G.LogSoftmaxGrad(),
  920. 'desc_inputs': [[16, 1234], [16, 1234]],
  921. 'desc_bprop': [[64, 2]],
  922. 'skip': ['backward']}),
  923. ('L2Normalize', {
  924. 'block': P.L2Normalize(),
  925. 'desc_inputs': [[2, 2]],
  926. 'desc_bprop': [[2, 2]]}),
  927. ('L2NormalizeGrad', {
  928. 'block': G.L2NormalizeGrad(),
  929. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  930. 'desc_bprop': [[2, 2]],
  931. 'skip': ['backward']}),
  932. ('LayerNorm', {
  933. 'block': P.LayerNorm(),
  934. 'desc_inputs': [[2, 16], [16], [16]],
  935. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  936. ('LayerNormGrad', {
  937. 'block': G.LayerNormGrad(),
  938. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  939. 'desc_bprop': [[2, 16], [16], [16]],
  940. 'skip': ['backward']}),
  941. ('FusedBatchNorm', {
  942. 'block': P.FusedBatchNorm(),
  943. 'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
  944. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  945. 'skip': []}),
  946. ('FusedBatchNormGrad', {
  947. 'block': G.FusedBatchNormGrad(),
  948. 'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
  949. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  950. 'skip': ['backward']}),
  951. ('BatchNorm', {
  952. 'block': P.BatchNorm(),
  953. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  954. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  955. 'skip': []}),
  956. ('BatchNormGrad', {
  957. 'block': G.BatchNormGrad(),
  958. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  959. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  960. 'skip': ['backward']}),
  961. ('BasicLSTMCell', {
  962. 'block': P.BasicLSTMCell(keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'),
  963. 'desc_inputs': [[128, 128], [128, 128], [128, 128], [512, 256, 1, 1], [512, 1, 1, 1]],
  964. 'desc_bprop': [[128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128]],
  965. 'skip': []}),
  966. ('TopK', {
  967. 'block': P.TopK(),
  968. 'desc_const': [5],
  969. 'desc_inputs': [[20, 20, 10]],
  970. 'desc_bprop': [[20, 20, 5]],
  971. 'skip': ['backward']}),
  972. ('GatherV2_0', {
  973. 'block': P.GatherV2(),
  974. 'desc_const': [0],
  975. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  976. 'desc_bprop': [[2, 1, 2]]}),
  977. ('GatherV2_1', {
  978. 'block': P.GatherV2(),
  979. 'desc_const': [2],
  980. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  981. 'desc_bprop': [[3, 1, 2]]}),
  982. ('GatherV2_2', {
  983. 'block': P.GatherV2(),
  984. 'desc_const': [0],
  985. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  986. 'desc_bprop': [[3, 2, 1, 3]]}),
  987. ('GatherV2_3', {
  988. 'block': P.GatherV2(),
  989. 'desc_const': [2],
  990. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  991. 'desc_bprop': [[3, 1, 3, 2]]}),
  992. ('GatherV2_4', {
  993. 'block': P.GatherV2(),
  994. 'desc_const': [1],
  995. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  996. 'desc_bprop': [[32, 1, 1024]]}),
  997. ('GatherV2_5', {
  998. 'block': P.GatherV2(),
  999. 'desc_const': [-1],
  1000. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1001. 'desc_bprop': [[3, 1, 2]]}),
  1002. ('GatherV2_6', {
  1003. 'block': P.GatherV2(),
  1004. 'desc_const': [0],
  1005. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  1006. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  1007. ('SparseGatherV2_0', {
  1008. 'block': P.SparseGatherV2(),
  1009. 'desc_const': [0],
  1010. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1011. 'desc_bprop': [[2, 1, 2]]}),
  1012. ('Range', {
  1013. 'block': inner.Range(1.0, 5.0),
  1014. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  1015. 'desc_bprop': [[10]]}),
  1016. ('UnsortedSegmentSum', {
  1017. 'block': P.UnsortedSegmentSum(),
  1018. 'desc_const': [1280],
  1019. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  1020. 'desc_bprop': [[8192, 1024]],
  1021. 'skip': ['backward']}),
  1022. ('UnsortedSegmentSum_1', {
  1023. 'block': P.UnsortedSegmentSum(),
  1024. 'desc_const': [4],
  1025. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1026. 'desc_bprop': [[4, 1, 3]],
  1027. 'skip': ['backward']}),
  1028. ('UnsortedSegmentMin', {
  1029. 'block': P.UnsortedSegmentMin(),
  1030. 'desc_const': [4],
  1031. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1032. 'desc_bprop': [[4, 2, 1, 3]]}),
  1033. ('DropoutGenMask', {
  1034. 'block': P.DropoutGenMask(),
  1035. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  1036. 'desc_inputs': [],
  1037. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  1038. 'skip': ['backward']}),
  1039. ('DropoutDoMask', {
  1040. 'block': P.DropoutDoMask(),
  1041. 'desc_const': [Tensor(0.5)],
  1042. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  1043. 'desc_bprop': [[64, 12, 128, 128]]}),
  1044. ('Dropout', {
  1045. 'block': nn.Dropout(0.5),
  1046. 'desc_inputs': [[64, 12, 128, 128]],
  1047. 'desc_bprop': [[64, 12, 128, 128]]}),
  1048. ('ReduceMean0', {
  1049. 'block': P.ReduceMean(),
  1050. 'desc_const': [(2,)],
  1051. 'desc_inputs': [[3, 2, 2]],
  1052. 'desc_bprop': [[3, 2]]}),
  1053. ('ReduceMean1', {
  1054. 'block': P.ReduceMean(),
  1055. 'desc_const': [2],
  1056. 'desc_inputs': [[3, 2, 2]],
  1057. 'desc_bprop': [[3, 2]]}),
  1058. ('All', {
  1059. 'block': P.ReduceAll(),
  1060. 'desc_const': [(1,)],
  1061. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  1062. 'desc_bprop': [[3]],
  1063. 'skip': ['backward']}),
  1064. ('DescConst', {
  1065. 'block': Tensor(np.array([2], np.float32)),
  1066. 'desc_inputs': [],
  1067. 'desc_bprop': [[1]],
  1068. 'skip': ['backward'],
  1069. 'add_fake_input': True}),
  1070. ('Fill', {
  1071. 'block': P.Fill(),
  1072. 'desc_const': [mstype.float32, (2, 3), 1.0],
  1073. 'desc_inputs': [],
  1074. 'desc_bprop': [[2, 3]],
  1075. 'skip': ['backward'],
  1076. 'add_fake_input': True}),
  1077. ('OnesLike', {
  1078. 'block': P.OnesLike(),
  1079. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1080. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1081. }),
  1082. ('ZerosLike', {
  1083. 'block': P.ZerosLike(),
  1084. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1085. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1086. }),
  1087. ('Softmax', {
  1088. 'block': P.Softmax(),
  1089. 'desc_inputs': [[5, 5]],
  1090. 'desc_bprop': [[5, 5]]}),
  1091. ('DepthwiseConv2dNative_1', {
  1092. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  1093. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  1094. 'desc_bprop': [[10, 32, 16, 16]]}),
  1095. ('DepthwiseConv2dNative_2', {
  1096. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  1097. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  1098. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  1099. ('SigmoidCrossEntropyWithLogits', {
  1100. 'block': P.SigmoidCrossEntropyWithLogits(),
  1101. 'desc_inputs': [[128, 10], [128, 10]],
  1102. 'desc_bprop': [[128, 10]]}),
  1103. ('Pad', {
  1104. 'block': P.Pad(((1, 2), (2, 3))),
  1105. 'desc_inputs': [[7, 7]],
  1106. 'desc_bprop': [[10, 12]]}),
  1107. ('BinaryCrossEntropy', {
  1108. 'block': P.BinaryCrossEntropy(),
  1109. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  1110. 'desc_bprop': []}),
  1111. ('SparseApplyAdagrad', {
  1112. 'block': SparseApplyAdagradNet(),
  1113. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1114. 'desc_bprop': [[3, 3], [3, 3]],
  1115. 'skip': ['backward']}),
  1116. ('SparseApplyFtrl', {
  1117. 'block': SparseApplyFtrlNet(),
  1118. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1119. 'skip': ['backward']}),
  1120. ('ApplyProximalAdagrad', {
  1121. 'block': ApplyProximalAdagradNet(),
  1122. 'desc_inputs': [[3, 3]],
  1123. 'skip': ['backward']}),
  1124. ('SparseApplyProximalAdagrad', {
  1125. 'block': SparseApplyProximalAdagradNet(),
  1126. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1127. 'skip': ['backward']}),
  1128. ('ApplyAdaMax', {
  1129. 'block': ApplyAdaMaxNet(),
  1130. 'desc_inputs': [[3, 3]],
  1131. 'skip': ['backward']}),
  1132. ('ApplyAdadelta', {
  1133. 'block': ApplyAdadeltaNet(),
  1134. 'desc_inputs': [[3, 3]],
  1135. 'skip': ['backward']}),
  1136. ('ApplyAdagrad', {
  1137. 'block': ApplyAdagradNet(),
  1138. 'desc_inputs': [[3, 3]],
  1139. 'skip': ['backward']}),
  1140. ('ApplyAdagradV2', {
  1141. 'block': ApplyAdagradV2Net(),
  1142. 'desc_inputs': [[3, 3]],
  1143. 'skip': ['backward']}),
  1144. ('Flatten_1', {
  1145. 'block': NetForFlatten(),
  1146. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1147. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1148. 'skip': ['backward']}),
  1149. ('Flatten_2', {
  1150. 'block': NetForFlatten(),
  1151. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  1152. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  1153. 'skip': ['backward']}),
  1154. ('Flatten_3', {
  1155. 'block': NetForFlattenComposed(),
  1156. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1157. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1158. 'skip': []}),
  1159. ('ArgmaxNet', {
  1160. 'block': ArgmaxNet(),
  1161. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1162. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1163. 'skip': ['backward']}),
  1164. ('ArgminNet', {
  1165. 'block': ArgminNet(),
  1166. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1167. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1168. 'skip': ['backward']}),
  1169. ('OneHot', {
  1170. 'block': P.OneHot(),
  1171. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  1172. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  1173. 'desc_bprop': [[1, 3]]}),
  1174. ('ReduceProd_0', {
  1175. 'block': P.ReduceProd(),
  1176. 'desc_const': [0],
  1177. 'desc_inputs': [[3, 2]],
  1178. 'desc_bprop': [[2]]}),
  1179. ('ReduceProd_1', {
  1180. 'block': P.ReduceProd(keep_dims=True),
  1181. 'desc_const': [0],
  1182. 'desc_inputs': [[3, 2]],
  1183. 'desc_bprop': [[1, 2]]}),
  1184. ('CumProd', {
  1185. 'block': P.CumProd(),
  1186. 'desc_const': [0],
  1187. 'desc_inputs': [[3, 2]],
  1188. 'desc_bprop': [[3, 2]]}),
  1189. ('ApplyFtrl', {
  1190. 'block': ApplyFtrlNet(),
  1191. 'desc_inputs': [[3, 3]],
  1192. 'desc_bprop': [3, 3],
  1193. 'skip': ['backward']}),
  1194. ('ApplyRMSProp', {
  1195. 'block': ApplyRMSNet(),
  1196. 'desc_inputs': [[3, 3]],
  1197. 'desc_bprop': [3, 3],
  1198. 'skip': ['backward']}),
  1199. ('ApplyCenteredRMSProp', {
  1200. 'block': P.ApplyCenteredRMSProp(),
  1201. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  1202. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  1203. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  1204. 'desc_bprop': [1],
  1205. 'skip': ['backward']}),
  1206. ('CTCLoss', {
  1207. 'block': P.CTCLoss(),
  1208. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  1209. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  1210. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  1211. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  1212. 'desc_bprop': [[4], [6, 4, 6]]}),
  1213. ('L2Loss_1', {
  1214. 'block': P.L2Loss(),
  1215. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  1216. 'desc_bprop': []}),
  1217. ('L2Loss_2', {
  1218. 'block': P.L2Loss(),
  1219. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  1220. 'desc_bprop': []}),
  1221. ('ResizeBilinear', {
  1222. 'block': P.ResizeBilinear((5, 5)),
  1223. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  1224. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  1225. ('ResizeBilinearGrad', {
  1226. 'block': G.ResizeBilinearGrad(),
  1227. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1228. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1229. 'skip': ['backward']}),
  1230. ('ROIAlign', {
  1231. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  1232. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  1233. 'desc_bprop': [[7, 7]]}),
  1234. ('ROIAlignGrad', {
  1235. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  1236. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  1237. 'desc_bprop': [[1, 1, 2, 2]],
  1238. 'skip': ['backward']}),
  1239. ('LARSUpdate', {
  1240. 'block': P.LARSUpdate(1e-05, 0.001, False),
  1241. 'desc_const': [0.0, 0.001],
  1242. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1243. 'desc_bprop': [3, 3],
  1244. 'skip': ['backward']}),
  1245. ('SGD', {
  1246. 'block': P.SGD(0.0, 0.0, False),
  1247. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  1248. 'desc_bprop': [3, 3],
  1249. 'skip': ['backward']}),
  1250. ('BinaryCrossEntropy', {
  1251. 'block': P.BinaryCrossEntropy(),
  1252. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1253. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1254. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1255. 'desc_bprop': []}),
  1256. ('BinaryCrossEntropyGrad', {
  1257. 'block': G.BinaryCrossEntropyGrad(),
  1258. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1259. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1260. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1261. 'desc_bprop': [],
  1262. 'skip': ['backward']}),
  1263. ('DataFormatDimMap', {
  1264. 'block': P.DataFormatDimMap(),
  1265. 'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
  1266. 'desc_bprop': [],
  1267. 'skip': ['backward']}),
  1268. ]
  1269. test_case_array_ops = [
  1270. ('SpaceToDepth', {
  1271. 'block': P.SpaceToDepth(2),
  1272. 'desc_inputs': [[1, 3, 2, 2]],
  1273. 'desc_bprop': [[1, 12, 1, 1]]}),
  1274. ('DepthToSpace', {
  1275. 'block': P.DepthToSpace(2),
  1276. 'desc_inputs': [[1, 12, 1, 1]],
  1277. 'desc_bprop': [[1, 3, 2, 2]]}),
  1278. ('Split', {
  1279. 'block': P.Split(1, 2),
  1280. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  1281. 'skip': ['backward']}),
  1282. ('Argmax', {
  1283. 'block': P.Argmax(),
  1284. 'desc_inputs': [[128, 32, 32, 64]],
  1285. 'desc_bprop': [0],
  1286. 'skip': ['backward']}),
  1287. ('Argmin', {
  1288. 'block': P.Argmin(),
  1289. 'desc_inputs': [[128, 32, 32, 64]],
  1290. 'desc_bprop': [1],
  1291. 'skip': ['backward']}),
  1292. ('ArgMaxWithValue', {
  1293. 'block': P.ArgMaxWithValue(),
  1294. 'desc_inputs': [[128, 32, 32, 64]],
  1295. 'desc_bprop': [[1], [1]],
  1296. 'skip': ['backward']}),
  1297. ('ArgMinWithValue', {
  1298. 'block': P.ArgMinWithValue(),
  1299. 'desc_inputs': [[128, 32, 32, 64]],
  1300. 'desc_bprop': [[1], [1]],
  1301. 'skip': ['backward']}),
  1302. ('Transpose_dim3', {
  1303. 'block': P.Transpose(),
  1304. 'desc_const': [(0, 2, 1)],
  1305. 'desc_inputs': [[1, 2, 3]],
  1306. 'desc_bprop': [[1, 3, 2]]}),
  1307. ('Transpose_dim4', {
  1308. 'block': P.Transpose(),
  1309. 'desc_const': [(0, 1, 2, 3)],
  1310. 'desc_inputs': [[1, 2, 3, 4]],
  1311. 'desc_bprop': [[1, 2, 4, 3]]}),
  1312. ('AddN', {
  1313. 'block': NetForTupleInput(P.AddN()),
  1314. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1315. 'desc_bprop': [[2, 3, 3, 5]],
  1316. 'skip': ['backward']}),
  1317. ('AccumulateNV2', {
  1318. 'block': NetForTupleInput(P.AccumulateNV2()),
  1319. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1320. 'desc_bprop': [[2, 3, 3, 5]],
  1321. 'skip': ['backward']}),
  1322. ('Shape', {
  1323. 'block': P.Shape(),
  1324. 'desc_inputs': [[3, 3, 2, 2]],
  1325. 'skip': ['backward']}),
  1326. ('Reshape', {
  1327. 'block': P.Reshape(),
  1328. 'desc_const': [(64,)],
  1329. 'desc_inputs': [[64, 1]],
  1330. 'desc_bprop': [[64]]}),
  1331. ('Cast', {
  1332. 'block': P.Cast(),
  1333. 'desc_const': [mstype.int32],
  1334. 'desc_inputs': [[2, 3, 4, 5]],
  1335. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  1336. ('ExpandDims', {
  1337. 'block': P.ExpandDims(),
  1338. 'desc_const': [0],
  1339. 'desc_inputs': [[2, 2]],
  1340. 'desc_bprop': [[1, 2, 2]]}),
  1341. ('ExpandDims_1', {
  1342. 'block': P.ExpandDims(),
  1343. 'desc_const': [-1],
  1344. 'desc_inputs': [[2, 2]],
  1345. 'desc_bprop': [[2, 2, 1]]}),
  1346. ('Squeeze', {
  1347. 'block': P.Squeeze(2),
  1348. 'desc_inputs': [[3, 2, 1]],
  1349. 'desc_bprop': [[3, 2]]}),
  1350. ('Squeeze_0', {
  1351. 'block': P.Squeeze(),
  1352. 'desc_inputs': [[3, 1, 2, 1]],
  1353. 'desc_bprop': [[3, 2]]}),
  1354. ('Squeeze_1', {
  1355. 'block': P.Squeeze(),
  1356. 'desc_inputs': [[1, 1, 1, 1]],
  1357. 'desc_bprop': [1.0],
  1358. 'skip': ['backward']}),
  1359. ('Squeeze_2', {
  1360. 'block': P.Squeeze((2, 3)),
  1361. 'desc_inputs': [[3, 2, 1, 1]],
  1362. 'desc_bprop': [[3, 2]]}),
  1363. ('Size', {
  1364. 'block': P.Size(),
  1365. 'desc_inputs': [[2, 3, 5]],
  1366. 'skip': ['backward']}),
  1367. ('Tile_0', {
  1368. 'block': P.Tile(),
  1369. 'desc_const': [(1, 2)],
  1370. 'desc_inputs': [[64, 1]],
  1371. 'desc_bprop': [[64, 2]]}),
  1372. ('Tile_1', {
  1373. 'block': P.Tile(),
  1374. 'desc_const': [(1, 1)],
  1375. 'desc_inputs': [[64, 1]],
  1376. 'desc_bprop': [[64, 1]]}),
  1377. ('Tile_2', {
  1378. 'block': P.Tile(),
  1379. 'desc_const': [(2, 1, 1, 2)],
  1380. 'desc_inputs': [[2, 2, 2]],
  1381. 'desc_bprop': [[2, 2, 2, 4]]}),
  1382. ('ConcatV2_0', {
  1383. 'block': P.Concat(),
  1384. 'desc_inputs': [
  1385. (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  1386. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
  1387. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  1388. ('ConcatV2_1', {
  1389. 'block': P.Concat(axis=2),
  1390. 'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  1391. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
  1392. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  1393. ('ConcatV2_2', {
  1394. 'block': NetForConcat(),
  1395. 'desc_inputs': [[2, 2]],
  1396. 'desc_bprop': [[4, 2]]}),
  1397. ('ConcatV2_3', {
  1398. 'block': NetForConcat1(),
  1399. 'desc_inputs': [[2, 2], [2, 2]],
  1400. 'desc_bprop': [[4, 2]]}),
  1401. ('ConcatV2_4', {
  1402. 'block': P.Concat(axis=0),
  1403. 'desc_inputs': [
  1404. (Tensor(np.ones((3, 2, 3), np.float32)),
  1405. Tensor(np.ones((5, 2, 3), np.float32)),
  1406. Tensor(np.ones((6, 2, 3), np.float32)))],
  1407. 'desc_bprop': [[14, 2, 3]]}),
  1408. ('ConcatV2_5', {
  1409. 'block': P.Concat(axis=-1),
  1410. 'desc_inputs': [(Tensor(np.array([1], np.float32)),
  1411. Tensor(np.array([1], np.float32)),
  1412. Tensor(np.array([1], np.float32)))],
  1413. 'desc_bprop': [[3, ]]}),
  1414. ('Pack_0', {
  1415. 'block': NetForPackInput(P.Pack()),
  1416. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1417. 'desc_bprop': [[3, 2, 2]],
  1418. }),
  1419. ('Pack_1', {
  1420. 'block': NetForPackInput(P.Pack(axis=-2)),
  1421. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  1422. 'desc_bprop': [[3, 2, 3, 3]],
  1423. }),
  1424. ('Pack_2', {
  1425. 'block': NetForPackInput(P.Pack()),
  1426. 'desc_inputs': [[128, 128], [128, 128]],
  1427. 'desc_bprop': [[2, 128, 128]],
  1428. }),
  1429. ('Unpack_0', {
  1430. 'block': NetForUnpackInput(P.Unpack(axis=0)),
  1431. 'desc_inputs': [[2, 4]],
  1432. 'desc_bprop': [[4], [4]],
  1433. }),
  1434. ('Unpack_1', {
  1435. 'block': NetForUnpackInput(P.Unpack(axis=-1)),
  1436. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  1437. 'desc_bprop': [[1], [1], [1]],
  1438. }),
  1439. ('Diag_1', {
  1440. 'block': P.Diag(),
  1441. 'desc_inputs': [[4]],
  1442. 'desc_bprop': [[4, 4]],
  1443. }),
  1444. ('Diag_2', {
  1445. 'block': P.Diag(),
  1446. 'desc_inputs': [[4, 4]],
  1447. 'desc_bprop': [[4, 4, 4, 4]],
  1448. }),
  1449. ('DiagPart_1', {
  1450. 'block': P.DiagPart(),
  1451. 'desc_inputs': [[4, 4]],
  1452. 'desc_bprop': [[4]],
  1453. }),
  1454. ('DiagPart_2', {
  1455. 'block': P.DiagPart(),
  1456. 'desc_inputs': [[4, 4, 4, 4]],
  1457. 'desc_bprop': [[4, 4]],
  1458. }),
  1459. ('SpaceToBatch_1', {
  1460. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  1461. 'desc_inputs': [[1, 3, 2, 2]],
  1462. 'desc_bprop': [[4, 3, 1, 1]],
  1463. }),
  1464. ('SpaceToBatch_2', {
  1465. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  1466. 'desc_inputs': [[1, 3, 2, 2]],
  1467. 'desc_bprop': [[4, 3, 2, 3]],
  1468. }),
  1469. ('BatchToSpace_1', {
  1470. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  1471. 'desc_inputs': [[4, 3, 1, 1]],
  1472. 'desc_bprop': [[1, 3, 2, 2]],
  1473. }),
  1474. ('BatchToSpace_2', {
  1475. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  1476. 'desc_inputs': [[4, 3, 1, 1]],
  1477. 'desc_bprop': [[1, 3, 2, 1]],
  1478. }),
  1479. ('UnsortedSegmentMin_1', {
  1480. 'block': P.UnsortedSegmentMin(),
  1481. 'desc_const': [2],
  1482. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  1483. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  1484. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  1485. ('BroadcastTo', {
  1486. 'block': P.BroadcastTo((2, 3)),
  1487. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
  1488. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
  1489. ('InTopK', {
  1490. 'block': P.InTopK(2),
  1491. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
  1492. Tensor(np.array([2, 1, 2]).astype(np.int32))],
  1493. 'skip': ['backward'],
  1494. }),
  1495. ('InplaceUpdate', {
  1496. 'block': P.InplaceUpdate((0, 2)),
  1497. 'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
  1498. Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
  1499. 'skip': ['backward'],
  1500. }),
  1501. ('ReverseSequence', {
  1502. 'block': P.ReverseSequence(1, 0),
  1503. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
  1504. Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1505. 'desc_bprop': [[3, 3]]}),
  1506. ('LinSpace', {
  1507. 'block': inner.LinSpace(),
  1508. 'desc_inputs': [Tensor([5, 5.5], mstype.float32),
  1509. Tensor(1, mstype.float32),
  1510. Tensor(10, mstype.float32),
  1511. Tensor(5, mstype.int32)],
  1512. 'skip': ['backward'],
  1513. }),
  1514. ('MatrixDiag', {
  1515. 'block': inner.MatrixDiag(),
  1516. 'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
  1517. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1518. 'skip': ['backward'],
  1519. }),
  1520. ('MatrixDiagPart', {
  1521. 'block': inner.MatrixDiagPart(),
  1522. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1523. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1524. 'skip': ['backward'],
  1525. }),
  1526. ('MatrixSetDiag', {
  1527. 'block': inner.MatrixSetDiag(),
  1528. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1529. Tensor(np.arange(6).reshape(3, 2), mstype.float32),
  1530. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1531. 'skip': ['backward'],
  1532. }),
  1533. ]
  1534. test_case_other_ops = [
  1535. ('ScalarLog', {
  1536. 'block': F.scalar_log,
  1537. 'desc_const': [0.0],
  1538. 'desc_inputs': [],
  1539. 'desc_bprop': [1],
  1540. 'skip': ['backward']}),
  1541. ('BoundingBoxEncode', {
  1542. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  1543. 'desc_inputs': [[256, 4], [256, 4]],
  1544. 'desc_bprop': [[256, 4]],
  1545. 'skip': ['backward']}),
  1546. ('BoundingBoxDecode', {
  1547. '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)),
  1548. 'desc_inputs': [[256, 4], [256, 4]],
  1549. 'desc_bprop': [[256, 4]],
  1550. 'skip': ['backward']}),
  1551. ('GatherNd', {
  1552. 'block': P.GatherNd(),
  1553. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  1554. Tensor(np.ones((2, 4), np.int32))),
  1555. 'desc_bprop': [[2]]}),
  1556. ('ScatterNd', {
  1557. 'block': P.ScatterNd(),
  1558. 'desc_const': [(3, 3)],
  1559. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  1560. Tensor(np.ones((2,), np.int32))),
  1561. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  1562. ('TensorScatterUpdate', {
  1563. 'block': P.TensorScatterUpdate(),
  1564. 'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
  1565. Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1566. Tensor(np.ones([2, 5], np.float32) * 99)),
  1567. 'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
  1568. ('ScatterMax', {
  1569. 'block': ScatterMax(),
  1570. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1571. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  1572. 'skip': ['backward']}),
  1573. ('ScatterAdd', {
  1574. 'block': ScatterAdd((6,)),
  1575. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1576. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1577. 'skip': ['backward']}),
  1578. ('ScatterAdd2d', {
  1579. 'block': ScatterAdd((3, 4)),
  1580. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1581. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1582. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1583. 'skip': ['backward']}),
  1584. ('SmoothL1Loss', {
  1585. 'block': P.SmoothL1Loss(),
  1586. 'desc_inputs': [[256, 4], [256, 4]],
  1587. 'desc_bprop': [[256, 4]]}),
  1588. ('IOU', {
  1589. 'block': P.IOU(),
  1590. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  1591. 'desc_bprop': [[128, 256]]}),
  1592. ('Summary', {
  1593. 'block': SummaryNet(),
  1594. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1595. Tensor(np.array([1.2]).astype(np.float32))],
  1596. 'skip': ['backward']}),
  1597. ('ConfusionMulGrad_1', {
  1598. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
  1599. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1600. 'desc_bprop': [[3, 2], [2]],
  1601. 'skip': ['backward']}),
  1602. ('ConfusionMulGrad_2', {
  1603. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
  1604. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  1605. 'desc_bprop': [[3, 2], [1, 2]],
  1606. 'skip': ['backward']}),
  1607. ('ConfusionMulGrad_3', {
  1608. 'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
  1609. 'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
  1610. 'desc_bprop': [[2, 3, 4], [1, 1, 1]],
  1611. 'skip': ['backward']}),
  1612. ('HistogramSummary', {
  1613. 'block': HistogramSummaryNet(),
  1614. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1615. Tensor(np.array([1.2]).astype(np.float32))],
  1616. 'skip': ['backward']}),
  1617. ]
  1618. test_case_quant_ops = [
  1619. ('AscendQuant_1', {
  1620. 'block': inner.AscendQuant(0.5, 0.0, False, "Round"),
  1621. 'desc_inputs': [Tensor(np.random.rand(1,2,4,4), mstype.float32)],
  1622. 'skip': ['backward']}),
  1623. ('AscendQuant_2', {
  1624. 'block': inner.AscendQuant(80.0, 10.0, True, "Round"),
  1625. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1626. 'skip': ['backward']}),
  1627. ('AscendQuant_3', {
  1628. 'block': inner.AscendQuant(80.0, 0.0, False, "Floor"),
  1629. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1630. 'skip': ['backward']}),
  1631. ('AscendQuant_4', {
  1632. 'block': inner.AscendQuant(80.0, 0.0, False, "Ceil"),
  1633. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1634. 'skip': ['backward']}),
  1635. ('AscendQuant_5', {
  1636. 'block': inner.AscendQuant(80.0, 0.0, False, "Trunc"),
  1637. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1638. 'skip': ['backward']}),
  1639. ('AscendQuant_6', {
  1640. 'block': inner.AscendQuant(-80.0, 10.0, False, "Round"),
  1641. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1642. 'skip': ['backward']}),
  1643. ('AscendQuant_7', {
  1644. 'block': inner.AscendQuant(80.0, -10.0, False, "Round"),
  1645. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  1646. 'skip': ['backward']}),
  1647. ('AscendQuant_8', {
  1648. 'block': inner.AscendQuant(80.0, 10.0, False, "Round"),
  1649. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
  1650. 'skip': ['backward']}),
  1651. ]
  1652. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops, test_case_quant_ops]
  1653. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  1654. # use -k to select certain testcast
  1655. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  1656. test_exec_case = test_case
  1657. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
  1658. @non_graph_engine
  1659. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  1660. def test_exec():
  1661. context.set_context(mode=context.GRAPH_MODE)
  1662. return test_exec_case
  1663. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  1664. def test_backward_exec():
  1665. context.set_context(mode=context.GRAPH_MODE)
  1666. return test_backward_exec_case
  1667. raise_set = [
  1668. ('Cast_Error', {
  1669. 'block': (P.Cast(), {'exception': TypeError}),
  1670. 'desc_const': [mstype.int32],
  1671. 'desc_inputs': ['wrong input'],
  1672. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  1673. ('Maximum_Error', {
  1674. 'block': (P.Maximum(), {'exception': TypeError}),
  1675. 'desc_const': [(1, 2, 3)],
  1676. 'desc_inputs': [[2, 3, 3, 5]],
  1677. 'desc_bprop': [[2, 3, 3, 5]]}),
  1678. ('Shape_error', {
  1679. 'block': (P.Shape(), {'exception': TypeError}),
  1680. 'desc_inputs': [(64, 1)],
  1681. 'desc_bprop': [[64]]}),
  1682. ('Flatten_Error', {
  1683. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  1684. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  1685. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  1686. ('ScatterNdUpdate', {
  1687. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  1688. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  1689. Tensor(np.ones((2, 2), np.float32)),
  1690. Tensor(np.ones((2,), np.float32))),
  1691. 'desc_bprop': [[2, 3]]}),
  1692. ('Pack', {
  1693. 'block': (NetForPackInput(P.Pack()), {'exception': ValueError}),
  1694. 'desc_inputs': [[2, 2]],
  1695. 'desc_bprop': [[1, 2, 2]]}),
  1696. ('PReLU', {
  1697. 'block': (P.PReLU(), {'exception': ValueError}),
  1698. 'desc_inputs': [[2], [1]],
  1699. 'desc_bprop': [[1]]}),
  1700. ('SSIM', {
  1701. 'block': (nn.SSIM(), {'exception': ValueError}),
  1702. 'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
  1703. Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]}),
  1704. ]
  1705. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  1706. def test_check_exception():
  1707. return raise_set