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

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