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

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