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

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