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