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 90 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
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  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, seed=0):
  403. super(NormalNet, self).__init__()
  404. self.shape = shape
  405. self.normal = P.Normal(seed=seed)
  406. def construct(self, mean, stddev):
  407. out = self.normal(self.shape, mean, stddev)
  408. return out
  409. class LaplaceNet(nn.Cell):
  410. def __init__(self, shape=None, seed=0):
  411. super(LaplaceNet, self).__init__()
  412. self.laplace = P.Laplace(seed=seed)
  413. self.shape = shape
  414. def construct(self, mean, lambda_param):
  415. out = self.laplace(self.shape, mean, lambda_param)
  416. return out
  417. class GammaNet(nn.Cell):
  418. def __init__(self, shape=None, seed=0):
  419. super(GammaNet, self).__init__()
  420. self.gamma = P.Gamma(seed=seed)
  421. self.shape = shape
  422. def construct(self, alpha, beta):
  423. out = self.gamma(self.shape, alpha, beta)
  424. return out
  425. class PoissonNet(nn.Cell):
  426. def __init__(self, shape=None, seed=0):
  427. super(PoissonNet, self).__init__()
  428. self.poisson = P.Poisson(seed=seed)
  429. self.shape = shape
  430. def construct(self, mean):
  431. out = self.poisson(self.shape, mean)
  432. return out
  433. class UniformIntNet(nn.Cell):
  434. def __init__(self, shape=None, seed=0):
  435. super(UniformIntNet, self).__init__()
  436. self.uniformint = P.UniformInt(seed=seed)
  437. self.shape = shape
  438. def construct(self, a, b):
  439. out = self.uniformint(self.shape, a, b)
  440. return out
  441. class UniformRealNet(nn.Cell):
  442. def __init__(self, shape=None, seed=0):
  443. super(UniformRealNet, self).__init__()
  444. self.uniformreal = P.UniformReal(seed=seed)
  445. self.shape = shape
  446. def construct(self, a, b):
  447. out = self.uniformreal(self.shape, a, b)
  448. return out
  449. class StridedSliceNet(nn.Cell):
  450. def __init__(self):
  451. super(StridedSliceNet, self).__init__()
  452. self.begins = (1, 2, 3, 2, 1)
  453. self.ends = (5, 6, 7, 8, 9)
  454. self.strides = (1, 2, 3, 2, 1)
  455. self.strided_slice_0 = P.StridedSlice(begin_mask=3, end_mask=5, ellipsis_mask=4,
  456. shrink_axis_mask=2, new_axis_mask=8)
  457. self.strided_slice_1 = P.StridedSlice(begin_mask=5, end_mask=2, ellipsis_mask=2,
  458. shrink_axis_mask=6, new_axis_mask=10)
  459. self.strided_slice_2 = P.StridedSlice(begin_mask=3, end_mask=3, ellipsis_mask=4,
  460. shrink_axis_mask=5, new_axis_mask=13)
  461. self.strided_slice_3 = P.StridedSlice(begin_mask=0, end_mask=0, ellipsis_mask=4,
  462. shrink_axis_mask=12, new_axis_mask=15)
  463. self.const_0 = Tensor(np.ones([6, 8, 9, 1, 8], np.float32))
  464. self.const_1 = Tensor(np.ones([5, 7, 8, 1, 8], np.float32))
  465. self.const_2 = Tensor(np.ones([1, 3, 7, 8, 9, 1, 8], np.float32))
  466. self.const_3 = Tensor(np.ones([1, 1, 6, 7, 8, 9, 1, 8], np.float32))
  467. def construct(self, x):
  468. out_0 = self.strided_slice_0(x, self.begins, self.ends, self.strides) + self.const_0
  469. out_1 = self.strided_slice_1(x, self.begins, self.ends, self.strides) + self.const_1
  470. out_2 = self.strided_slice_2(x, self.begins, self.ends, self.strides) + self.const_2
  471. out_3 = self.strided_slice_3(x, self.begins, self.ends, self.strides) + self.const_3
  472. return out_0, out_1, out_2, out_3
  473. def test_strided_slice_const():
  474. class StridedSLiceConstNet(nn.Cell):
  475. """StridedSLiceConstNet net definition"""
  476. def __init__(self):
  477. super(StridedSLiceConstNet, self).__init__()
  478. self.begins = (0, 2, -5, 2, 1)
  479. self.ends = (0, 6, 9, 8, 9)
  480. self.strides = (1, 2, 1, 2, 1)
  481. self.strided_slice = P.StridedSlice(begin_mask=2,
  482. end_mask=6,
  483. ellipsis_mask=4,
  484. shrink_axis_mask=6,
  485. new_axis_mask=18)
  486. def construct(self, x):
  487. out = self.strided_slice(x, self.begins, self.ends, self.strides)
  488. return out
  489. net = StridedSLiceConstNet()
  490. context.set_context(mode=context.GRAPH_MODE, save_graphs=True)
  491. x = Tensor(np.ones([6, 7, 8, 9, 10]), mstype.float32)
  492. ret = net(x)
  493. assert ret.shape == (0, 1, 7, 8, 9, 3, 1)
  494. assert (ret.asnumpy() == np.array([], np.float32).reshape([0, 1, 7, 8, 9, 3, 1])).all()
  495. class ParallelConcatNet(nn.Cell):
  496. def __init__(self):
  497. super(ParallelConcatNet, self).__init__()
  498. self.parallel_concat = P.ParallelConcat()
  499. def construct(self, x1, x2):
  500. return self.parallel_concat((x1, x2))
  501. test_case_math_ops = [
  502. ('BitwiseAnd', {
  503. 'block': P.BitwiseAnd(),
  504. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  505. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  506. 'skip': ['backward']}),
  507. ('BitwiseAnd_1', {
  508. 'block': P.BitwiseAnd(),
  509. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  510. Tensor(np.array([1, 1, 1]), mstype.int16)],
  511. 'skip': ['backward']}),
  512. ('BitwiseOr', {
  513. 'block': P.BitwiseOr(),
  514. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  515. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  516. 'skip': ['backward']}),
  517. ('BitwiseOr_1', {
  518. 'block': P.BitwiseOr(),
  519. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  520. Tensor(np.array([1, 1, 1]), mstype.int16)],
  521. 'skip': ['backward']}),
  522. ('BitwiseXor', {
  523. 'block': P.BitwiseXor(),
  524. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  525. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  526. 'skip': ['backward']}),
  527. ('BitwiseXor_1', {
  528. 'block': P.BitwiseXor(),
  529. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  530. Tensor(np.array([1, 1, 1]), mstype.int16)],
  531. 'skip': ['backward']}),
  532. ('Neg', {
  533. 'block': P.Neg(),
  534. 'desc_inputs': [[1, 3, 4, 4]],
  535. 'desc_bprop': [[1, 3, 4, 4]]}),
  536. ('Sub', {
  537. 'block': P.Sub(),
  538. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  539. 'desc_bprop': [[2, 3, 3, 5]]}),
  540. ('TensorAdd', {
  541. 'block': P.TensorAdd(),
  542. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  543. 'desc_bprop': [[2, 3, 3, 5]]}),
  544. ('Mul0', {
  545. 'block': P.Mul(),
  546. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  547. 'desc_bprop': [[2, 3, 3, 5]]}),
  548. ('Mul1', {
  549. 'block': P.Mul(),
  550. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  551. 'desc_bprop': [[2, 3, 3, 5]]}),
  552. ('Mul2', {
  553. 'block': P.Mul(),
  554. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  555. 'desc_bprop': [[2, 3, 3, 5]],
  556. 'skip': ['backward']}),
  557. ('Mul3', {
  558. 'block': P.Mul(),
  559. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  560. 'desc_bprop': [[2, 3, 3, 5]],
  561. 'skip': ['backward']}),
  562. ('Mul4', {
  563. 'block': P.Mul(),
  564. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  565. 'desc_bprop': [[2, 3, 3, 5]],
  566. 'skip': ['backward']}),
  567. ('Add0', {
  568. 'block': P.TensorAdd(),
  569. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  570. 'desc_bprop': [[2, 3, 3, 5]]}),
  571. ('Add1', {
  572. 'block': P.TensorAdd(),
  573. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  574. 'desc_bprop': [[2, 3, 3, 5]],
  575. 'skip': ['backward']}),
  576. ('Add2', {
  577. 'block': P.TensorAdd(),
  578. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  579. 'desc_bprop': [[2, 3, 3, 5]],
  580. 'skip': ['backward']}),
  581. ('Add3', {
  582. 'block': P.TensorAdd(),
  583. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  584. 'desc_bprop': [[2, 3, 3, 5]],
  585. 'skip': ['backward']}),
  586. ('Add4', {
  587. 'block': P.TensorAdd(),
  588. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  589. 'desc_bprop': [[2, 3, 3, 5]],
  590. 'skip': ['backward']}),
  591. ('Minimum', {
  592. 'block': P.Minimum(),
  593. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  594. 'desc_bprop': [[2, 3, 3, 5]]}),
  595. ('Pow_0', {
  596. 'block': P.Pow(),
  597. 'desc_const': [2.0],
  598. 'desc_inputs': [[2, 3, 3, 5]],
  599. 'desc_bprop': [[2, 3, 3, 5]]}),
  600. ('Pow_1', {
  601. 'block': P.Pow(),
  602. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  603. 'desc_bprop': [[2, 3, 3, 5]]}),
  604. ('Exp', {
  605. 'block': P.Exp(),
  606. 'desc_inputs': [[2, 3]],
  607. 'desc_bprop': [[2, 3]]}),
  608. ('Expm1', {
  609. 'block': P.Expm1(),
  610. 'desc_inputs': [[2, 3]],
  611. 'desc_bprop': [[2, 3]]}),
  612. ('Erf', {
  613. 'block': P.Erf(),
  614. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  615. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  616. ('Floor', {
  617. 'block': P.Floor(),
  618. 'desc_inputs': [[2, 512, 56, 56]],
  619. 'desc_bprop': [[2, 512, 56, 56]],
  620. 'skip': ['backward']}),
  621. ('Ceil', {
  622. 'block': P.Ceil(),
  623. 'desc_inputs': [[2, 512, 56, 56]],
  624. 'desc_bprop': [[2, 512, 56, 56]],
  625. 'skip': ['backward']}),
  626. ('InplaceAdd', {
  627. 'block': InplaceAddNet(),
  628. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  629. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  630. 'skip': ['backward']}),
  631. ('InplaceSub', {
  632. 'block': InplaceSubNet(),
  633. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  634. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  635. 'skip': ['backward']}),
  636. ('ACos', {
  637. 'block': P.ACos(),
  638. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  639. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  640. ('ACosGrad', {
  641. 'block': G.ACosGrad(),
  642. 'desc_inputs': [[2, 3], [2, 3]],
  643. 'skip': ['backward']}),
  644. ('Acosh', {
  645. 'block': P.Acosh(),
  646. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  647. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  648. ('AcoshGrad', {
  649. 'block': G.AcoshGrad(),
  650. 'desc_inputs': [[2, 3], [2, 3]],
  651. 'skip': ['backward']}),
  652. ('Sin', {
  653. 'block': P.Sin(),
  654. 'desc_inputs': [[2, 3]],
  655. 'desc_bprop': [[2, 3]]}),
  656. ('Asin', {
  657. 'block': P.Asin(),
  658. 'desc_inputs': [[2, 3]],
  659. 'desc_bprop': [[2, 3]]}),
  660. ('Asinh', {
  661. 'block': P.Asinh(),
  662. 'desc_inputs': [[3, 4, 5]],
  663. 'desc_bprop': [[3, 4, 5]]}),
  664. ('Tan', {
  665. 'block': P.Tan(),
  666. 'desc_inputs': [[2, 3]],
  667. 'desc_bprop': [[2, 3]]}),
  668. ('Reciprocal', {
  669. 'block': P.Reciprocal(),
  670. 'desc_inputs': [[2, 3, 3, 5]],
  671. 'desc_bprop': [[2, 3, 3, 5]]}),
  672. ('Minimum_0', {
  673. 'block': P.Minimum(),
  674. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  675. 'desc_bprop': [[2, 3, 3, 5]]}),
  676. ('Maximum', {
  677. 'block': P.Maximum(),
  678. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  679. 'desc_bprop': [[2, 3, 3, 5]]}),
  680. ('Maximum_0', {
  681. 'block': P.Maximum(),
  682. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  683. 'desc_bprop': [[2, 3, 3, 5]]}),
  684. ('MaximumGrad', {
  685. 'block': G.MaximumGrad(),
  686. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  687. 'skip': ['backward']}),
  688. ('MinimumGrad', {
  689. 'block': G.MinimumGrad(),
  690. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  691. 'skip': ['backward']}),
  692. ('StridedSlice', {
  693. 'block': P.StridedSlice(),
  694. 'desc_const': [(0, 1, 2, 1),
  695. (2, 3, 3, 4),
  696. (1, 1, 1, 1)],
  697. 'desc_inputs': [[2, 3, 3, 5]],
  698. 'desc_bprop': [[2, 2, 1, 3]]}),
  699. ('Slice_1', {
  700. 'block': P.Slice(),
  701. 'desc_const': [(0, 1, 2, 1),
  702. (1, 1, 1, 2)],
  703. 'desc_inputs': [[2, 3, 3, 5]],
  704. 'desc_bprop': [[1, 1, 1, 2]]}),
  705. ('StridedSliceGrad', {
  706. 'block': G.StridedSliceGrad(),
  707. 'desc_const': [(64, 1, 1024),
  708. (0, 1, 0),
  709. (64, 2, 1024),
  710. (1, 1, 1)],
  711. 'desc_inputs': [[64, 128, 1024]],
  712. 'skip': ['backward']}),
  713. ('Normal', {
  714. 'block': NormalNet((3, 2, 4), 0),
  715. 'desc_inputs': [Tensor(0.0, mstype.float32), Tensor(1.0, mstype.float32)],
  716. 'skip': ['backward']}),
  717. ('Laplace', {
  718. 'block': LaplaceNet((3, 2, 4), 0),
  719. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  720. 'skip': ['backward']}),
  721. ('Gamma', {
  722. 'block': GammaNet((3, 2, 4), 0),
  723. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  724. 'skip': ['backward']}),
  725. ('Poisson', {
  726. 'block': PoissonNet((3, 2, 4), 0),
  727. 'desc_inputs': [Tensor(2.0, mstype.float32)],
  728. 'skip': ['backward']}),
  729. ('UniformInt', {
  730. 'block': UniformIntNet((3, 2, 4), 0),
  731. 'desc_inputs': [Tensor(1, mstype.int32), Tensor(15, mstype.int32)],
  732. 'skip': ['backward']}),
  733. ('UniformReal', {
  734. 'block': UniformRealNet((3, 2, 4), 0),
  735. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(5.0, mstype.float32)],
  736. 'skip': ['backward']}),
  737. ('RandomChoiceWithMask', {
  738. 'block': P.RandomChoiceWithMask(256),
  739. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  740. 'desc_bprop': [[256, 4], [256, 4]],
  741. 'skip': ['backward']}),
  742. ('LessEqual', {
  743. 'block': P.LessEqual(),
  744. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  745. Tensor(np.random.rand(4).astype(np.float16))],
  746. 'skip': ['backward']}),
  747. ('Less', {
  748. 'block': P.Less(),
  749. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  750. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  751. 'skip': ['backward']}),
  752. ('RealDiv_0', {
  753. 'block': P.RealDiv(),
  754. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  755. 'desc_inputs': [],
  756. 'skip': ['backward']}),
  757. ('RealDiv', {
  758. 'block': P.RealDiv(),
  759. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  760. 'desc_bprop': [[4]]}),
  761. ('RealDiv_1', {
  762. 'block': P.RealDiv(),
  763. 'desc_inputs': [[512, 1024], [512, 1024]],
  764. 'desc_bprop': [[512, 1024]]}),
  765. ('FloorDiv', {
  766. 'block': P.FloorDiv(),
  767. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  768. Tensor(np.random.rand(4).astype(np.float16))],
  769. 'skip': ['backward']}),
  770. ('FloorMod', {
  771. 'block': P.FloorMod(),
  772. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  773. 'desc_bprop': [[2, 3, 4, 5]]}),
  774. ('TruncateDiv', {
  775. 'block': P.TruncateDiv(),
  776. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  777. 'desc_bprop': [[2, 3, 4, 5]]}),
  778. ('TruncateMod', {
  779. 'block': P.TruncateMod(),
  780. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  781. 'desc_bprop': [[2, 3, 4, 5]]}),
  782. ('identity', {
  783. 'block': ops.functional.identity,
  784. 'desc_inputs': [[2, 2]],
  785. 'skip': ['backward']}),
  786. ('MatMul_1', {
  787. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  788. 'desc_inputs': [[1024, 160], [160, 1024]],
  789. 'desc_bprop': [[1024, 1024]]}),
  790. ('MatMul_2', {
  791. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  792. 'desc_inputs': [[160, 1024], [1024, 160]],
  793. 'desc_bprop': [[1024, 1024]]}),
  794. ('Sub', {
  795. 'block': P.Sub(),
  796. 'desc_inputs': [[3], [3]],
  797. 'desc_bprop': [[3]]}),
  798. ('TruncatedNormal', {
  799. 'block': P.TruncatedNormal(),
  800. 'desc_const': [(1, 2, 3)],
  801. 'desc_inputs': [],
  802. 'skip': ['backward'],
  803. 'add_fake_input': True}),
  804. ('Select', {
  805. 'block': P.Select(),
  806. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  807. [2, 3], [2, 3]],
  808. 'desc_bprop': [[2, 3]]}),
  809. ('Rank', {
  810. 'block': P.Rank(),
  811. 'desc_inputs': [[2, 3]],
  812. 'skip': ['backward']}),
  813. ('InvertPermutation', {
  814. 'block': P.InvertPermutation(),
  815. 'desc_const': [(0, 3, 1, 2)],
  816. 'desc_inputs': [],
  817. 'skip': ['backward']}),
  818. ('Square', {
  819. 'block': P.Square(),
  820. 'desc_inputs': [[4]],
  821. 'desc_bprop': [[4]]}),
  822. ('Rsqrt', {
  823. 'block': P.Rsqrt(),
  824. 'desc_inputs': [[4]],
  825. 'desc_bprop': [[4]]}),
  826. ('Sqrt', {
  827. 'block': P.Sqrt(),
  828. 'desc_inputs': [[4]],
  829. 'desc_bprop': [[4]]}),
  830. ('RealDiv', {
  831. 'block': P.RealDiv(),
  832. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  833. 'desc_bprop': [[2, 3, 4, 5]]}),
  834. ('Div', {
  835. 'block': P.Div(),
  836. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  837. 'desc_bprop': [[2, 3, 4, 5]]}),
  838. ('Equal', {
  839. 'block': P.Equal(),
  840. 'desc_inputs': [[3, 4, 5], [4, 5]],
  841. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  842. ('NotEqual', {
  843. 'block': P.NotEqual(),
  844. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  845. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  846. ('NotEqual_0', {
  847. 'block': P.NotEqual(),
  848. 'desc_inputs': [1, [2, 3, 4, 5]],
  849. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  850. 'skip': ['backward']}),
  851. ('ApproximateEqual', {
  852. 'block': P.ApproximateEqual(),
  853. 'desc_inputs': [[3, 4, 5], [3, 4, 5]],
  854. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  855. ('Greater', {
  856. 'block': P.Greater(),
  857. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  858. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  859. ('GreaterEqual', {
  860. 'block': P.GreaterEqual(),
  861. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  862. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  863. ('LogicalNot', {
  864. 'block': P.LogicalNot(),
  865. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  866. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  867. ('LogicalAnd', {
  868. 'block': P.LogicalAnd(),
  869. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  870. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  871. ('LogicalOr', {
  872. 'block': P.LogicalOr(),
  873. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  874. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  875. ('NpuAllocFloatStatus', {
  876. 'block': P.NPUAllocFloatStatus(),
  877. 'desc_inputs': [],
  878. 'add_fack_input': True,
  879. 'fack_input_type': np.float32,
  880. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  881. 'skip': ['backward']}),
  882. ('NpuGetFloatStatus', {
  883. 'block': P.NPUGetFloatStatus(),
  884. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  885. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  886. 'skip': ['backward']}),
  887. ('NpuClearFloatStatus', {
  888. 'block': P.NPUClearFloatStatus(),
  889. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  890. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  891. 'skip': ['backward']}),
  892. ('CheckValid', {
  893. 'block': P.CheckValid(),
  894. 'desc_inputs': [[20000, 4], [3]],
  895. 'desc_bprop': [[20000]],
  896. 'skip': ['backward']}),
  897. ('NMSWithMask', {
  898. 'block': P.NMSWithMask(0.5),
  899. 'desc_inputs': [[128, 5]],
  900. 'desc_bprop': [[128, 5], [128], [128]],
  901. 'skip': ['backward']}),
  902. ('Abs', {
  903. 'block': P.Abs(),
  904. 'desc_inputs': [[4]],
  905. 'desc_bprop': [[4]]}),
  906. ('CumSum', {
  907. 'block': CumSumNet(),
  908. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  909. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  910. [1, 3, 7, 9]]).astype(np.float32))]}),
  911. ('ReduceSum_3', {
  912. 'block': P.ReduceSum(),
  913. 'desc_const': [0],
  914. 'desc_inputs': [[3, 2]],
  915. 'desc_bprop': [[2]]}),
  916. ('ReduceSum_4', {
  917. 'block': P.ReduceSum(keep_dims=True),
  918. 'desc_const': [0],
  919. 'desc_inputs': [[3, 2]],
  920. 'desc_bprop': [[1, 2]]}),
  921. ('ReduceSum_5', {
  922. 'block': P.ReduceSum(keep_dims=True),
  923. 'desc_inputs': [[2, 3, 4]],
  924. 'desc_bprop': [[1, 1, 1]]}),
  925. ('ReduceSum_6', {
  926. 'block': P.ReduceSum(),
  927. 'desc_inputs': [[2, 3, 4]],
  928. 'desc_bprop': [[1]]}),
  929. ('Sum_0', {
  930. 'block': P.ReduceSum(),
  931. 'desc_const': [(1,)],
  932. 'desc_inputs': [[3, 2]],
  933. 'desc_bprop': [[3]]}),
  934. ('Sum_1', {
  935. 'block': P.ReduceSum(keep_dims=True),
  936. 'desc_const': [(1,)],
  937. 'desc_inputs': [[3, 2]],
  938. 'desc_bprop': [[3, 1]]}),
  939. ('Sum_2', {
  940. 'block': P.ReduceSum(),
  941. 'desc_const': [(0, 1)],
  942. 'desc_inputs': [[3, 2]],
  943. 'desc_bprop': [[1]]}),
  944. ('Sum_3', {
  945. 'block': P.ReduceSum(),
  946. 'desc_const': [0],
  947. 'desc_inputs': [[3, 2]],
  948. 'desc_bprop': [[2]]}),
  949. ('Sum_4', {
  950. 'block': P.ReduceSum(keep_dims=True),
  951. 'desc_const': [0],
  952. 'desc_inputs': [[3, 2]],
  953. 'desc_bprop': [[1, 2]]}),
  954. ('Sum_5', {
  955. 'block': P.ReduceSum(keep_dims=True),
  956. 'desc_const': [()],
  957. 'desc_inputs': [[2, 3, 4]],
  958. 'desc_bprop': [[1, 1, 1]]}),
  959. ('Sum_6', {
  960. 'block': P.ReduceSum(),
  961. 'desc_const': [()],
  962. 'desc_inputs': [[2, 3, 4]],
  963. 'desc_bprop': [[1]]}),
  964. ('Sign', {
  965. 'block': P.Sign(),
  966. 'desc_inputs': [[3]],
  967. 'desc_bprop': [[3]]}),
  968. ('Round', {
  969. 'block': P.Round(),
  970. 'desc_inputs': [[3]],
  971. 'desc_bprop': [[3]]}),
  972. ('Atan2', {
  973. 'block': P.Atan2(),
  974. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  975. Tensor(np.array([1, 1]).astype(np.float32))],
  976. 'desc_bprop': [[2]]}),
  977. ('SquareSumAll', {
  978. 'block': P.SquareSumAll(),
  979. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  980. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  981. 'skip': ['backward']}),
  982. ('Cos', {
  983. 'block': P.Cos(),
  984. 'desc_inputs': [[2, 3]],
  985. 'desc_bprop': [[2, 3]]}),
  986. ('ReduceAll', {
  987. 'block': P.ReduceAll(),
  988. 'desc_const': [1],
  989. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  990. 'desc_bprop': []}),
  991. ('BesselI0e', {
  992. 'block': P.BesselI0e(),
  993. 'desc_inputs': [[2, 3]],
  994. 'desc_bprop': [[2, 3]]}),
  995. ('BesselI1e', {
  996. 'block': P.BesselI1e(),
  997. 'desc_inputs': [[2, 3]],
  998. 'desc_bprop': [[2, 3]]}),
  999. ('Atan', {
  1000. 'block': P.Atan(),
  1001. 'desc_inputs': [[2, 3]],
  1002. 'desc_bprop': [[2, 3]]}),
  1003. ('AtanGrad', {
  1004. 'block': G.AtanGrad(),
  1005. 'desc_inputs': [[2, 3], [2, 3]],
  1006. 'skip': ['backward']}),
  1007. ('Atanh', {
  1008. 'block': P.Atanh(),
  1009. 'desc_inputs': [[2, 3]],
  1010. 'desc_bprop': [[2, 3]]}),
  1011. ('Cosh', {
  1012. 'block': P.Cosh(),
  1013. 'desc_inputs': [[3, 4, 5]],
  1014. 'desc_bprop': [[3, 4, 5]]}),
  1015. ('Sinh', {
  1016. 'block': P.Sinh(),
  1017. 'desc_inputs': [[3, 4, 5]],
  1018. 'desc_bprop': [[3, 4, 5]]}),
  1019. ('Inv', {
  1020. 'block': P.Inv(),
  1021. 'desc_inputs': [[21, 9, 12, 5]],
  1022. 'desc_bprop': [[21, 9, 12, 5]]}),
  1023. ('Invert', {
  1024. 'block': P.Invert(),
  1025. 'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
  1026. 'desc_bprop': [],
  1027. 'skip': ['backward']}),
  1028. ('HistogramFixedWidth', {
  1029. 'block': P.HistogramFixedWidth(5),
  1030. 'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
  1031. 'desc_bprop': [],
  1032. 'skip': ['backward']}),
  1033. ('Mod', {
  1034. 'block': P.Mod(),
  1035. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1036. 'desc_bprop': [[2, 3, 4, 5]]}),
  1037. ]
  1038. test_case_nn_ops = [
  1039. ('BiasAdd', {
  1040. 'block': P.BiasAdd(),
  1041. 'desc_inputs': [[1, 3, 3, 3], [3]],
  1042. 'desc_bprop': [[1, 3, 3, 3]]}),
  1043. ('BiasAddGrad', {
  1044. 'block': G.BiasAddGrad(),
  1045. 'desc_inputs': [[1, 3, 3, 3]],
  1046. 'skip': ['backward']}),
  1047. ('Gelu', {
  1048. 'block': P.Gelu(),
  1049. 'desc_inputs': [[1, 3, 4, 4]],
  1050. 'desc_bprop': [[1, 3, 4, 4]]}),
  1051. ('GeluGrad', {
  1052. 'block': G.GeluGrad(),
  1053. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1054. 'desc_bprop': [[2, 2]],
  1055. 'skip': ['backward']}),
  1056. ('Tanh', {
  1057. 'block': P.Tanh(),
  1058. 'desc_inputs': [[1, 3, 4, 4]],
  1059. 'desc_bprop': [[1, 3, 4, 4]]}),
  1060. ('TanhGrad', {
  1061. 'block': G.TanhGrad(),
  1062. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1063. 'desc_bprop': [[1, 3, 4, 4]],
  1064. 'skip': ['backward']}),
  1065. ('ReLU', {
  1066. 'block': P.ReLU(),
  1067. 'desc_inputs': [[1, 3, 4, 4]],
  1068. 'desc_bprop': [[1, 3, 4, 4]]}),
  1069. ('ReLU6', {
  1070. 'block': P.ReLU6(),
  1071. 'desc_inputs': [[1, 3, 4, 4]],
  1072. 'desc_bprop': [[1, 3, 4, 4]]}),
  1073. ('ReLUV2', {
  1074. 'block': P.ReLUV2(),
  1075. 'desc_inputs': [[1, 3, 4, 4]],
  1076. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  1077. ('ReLUGrad', {
  1078. 'block': G.ReluGrad(),
  1079. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1080. 'skip': ['backward']}),
  1081. ('Softplus', {
  1082. 'block': P.Softplus(),
  1083. 'desc_inputs': [[1, 3, 4, 4]],
  1084. 'desc_bprop': [[1, 3, 4, 4]]}),
  1085. ('SoftplusGrad', {
  1086. 'block': G.SoftplusGrad(),
  1087. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1088. 'skip': ['backward']}),
  1089. ('Elu', {
  1090. 'block': P.Elu(),
  1091. 'desc_inputs': [[2, 3, 4]],
  1092. 'desc_bprop': [[2, 3, 4]]}),
  1093. ('EluGrad', {
  1094. 'block': G.EluGrad(),
  1095. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  1096. 'desc_bprop': [[2, 3, 4]],
  1097. 'skip': ['backward']}),
  1098. ('Sigmoid', {
  1099. 'block': P.Sigmoid(),
  1100. 'desc_inputs': [[1, 3, 4, 4]],
  1101. 'desc_bprop': [[1, 3, 4, 4]]}),
  1102. ('MaxPool', {
  1103. 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1104. 'desc_inputs': [[100, 3, 28, 28]],
  1105. 'desc_bprop': [[100, 3, 14, 14]]}),
  1106. ('MaxPoolGrad', {
  1107. 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1108. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  1109. 'desc_bprop': [[3, 4, 6, 6]],
  1110. 'skip': ['backward']}),
  1111. ('AvgPool', {
  1112. 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1113. 'desc_inputs': [[100, 3, 28, 28]],
  1114. 'desc_bprop': [[100, 3, 14, 14]]}),
  1115. ('AvgPoolGrad', {
  1116. 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1117. 'desc_const': [(3, 4, 6, 6)],
  1118. 'const_first': True,
  1119. 'desc_inputs': [[3, 4, 6, 6]],
  1120. 'desc_bprop': [[3, 4, 6, 6]],
  1121. 'skip': ['backward']}),
  1122. ('MaxPoolWithArgmax', {
  1123. 'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
  1124. 'desc_inputs': [[128, 32, 32, 64]],
  1125. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
  1126. ('SoftmaxCrossEntropyWithLogits', {
  1127. 'block': P.SoftmaxCrossEntropyWithLogits(),
  1128. 'desc_inputs': [[1, 10], [1, 10]],
  1129. 'desc_bprop': [[1], [1, 10]],
  1130. 'skip': ['backward_exec']}),
  1131. ('Flatten', {
  1132. 'block': P.Flatten(),
  1133. 'desc_inputs': [[128, 32, 32, 64]],
  1134. 'desc_bprop': [[128, 65536]]}),
  1135. ('LogSoftmax', {
  1136. 'block': P.LogSoftmax(),
  1137. 'desc_inputs': [[64, 2]],
  1138. 'desc_bprop': [[64, 2]]}),
  1139. ('LogSoftmaxGrad', {
  1140. 'block': G.LogSoftmaxGrad(),
  1141. 'desc_inputs': [[16, 1234], [16, 1234]],
  1142. 'desc_bprop': [[64, 2]],
  1143. 'skip': ['backward']}),
  1144. ('L2Normalize', {
  1145. 'block': P.L2Normalize(),
  1146. 'desc_inputs': [[2, 2]],
  1147. 'desc_bprop': [[2, 2]]}),
  1148. ('L2NormalizeGrad', {
  1149. 'block': G.L2NormalizeGrad(),
  1150. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1151. 'desc_bprop': [[2, 2]],
  1152. 'skip': ['backward']}),
  1153. ('LayerNorm', {
  1154. 'block': P.LayerNorm(),
  1155. 'desc_inputs': [[2, 16], [16], [16]],
  1156. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  1157. ('LayerNormGrad', {
  1158. 'block': G.LayerNormGrad(),
  1159. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  1160. 'desc_bprop': [[2, 16], [16], [16]],
  1161. 'skip': ['backward']}),
  1162. ('FusedBatchNorm', {
  1163. 'block': P.FusedBatchNorm(),
  1164. 'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1165. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1166. 'skip': []}),
  1167. ('FusedBatchNormGrad', {
  1168. 'block': G.FusedBatchNormGrad(),
  1169. 'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
  1170. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1171. 'skip': ['backward']}),
  1172. ('BatchNorm', {
  1173. 'block': P.BatchNorm(),
  1174. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1175. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1176. 'skip': []}),
  1177. ('BatchNormGrad', {
  1178. 'block': G.BatchNormGrad(),
  1179. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  1180. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1181. 'skip': ['backward']}),
  1182. ('BasicLSTMCell', {
  1183. 'block': P.BasicLSTMCell(keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'),
  1184. 'desc_inputs': [[128, 128], [128, 128], [128, 128], [512, 256, 1, 1], [512, 1, 1, 1]],
  1185. 'desc_bprop': [[128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128]],
  1186. 'skip': []}),
  1187. ('TopK', {
  1188. 'block': P.TopK(),
  1189. 'desc_const': [5],
  1190. 'desc_inputs': [[20, 20, 10]],
  1191. 'desc_bprop': [[20, 20, 5]],
  1192. 'skip': ['backward']}),
  1193. ('GatherV2_0', {
  1194. 'block': P.GatherV2(),
  1195. 'desc_const': [0],
  1196. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1197. 'desc_bprop': [[2, 1, 2]]}),
  1198. ('GatherV2_1', {
  1199. 'block': P.GatherV2(),
  1200. 'desc_const': [2],
  1201. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1202. 'desc_bprop': [[3, 1, 2]]}),
  1203. ('GatherV2_2', {
  1204. 'block': P.GatherV2(),
  1205. 'desc_const': [0],
  1206. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1207. 'desc_bprop': [[3, 2, 1, 3]]}),
  1208. ('GatherV2_3', {
  1209. 'block': P.GatherV2(),
  1210. 'desc_const': [2],
  1211. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1212. 'desc_bprop': [[3, 1, 3, 2]]}),
  1213. ('GatherV2_4', {
  1214. 'block': P.GatherV2(),
  1215. 'desc_const': [1],
  1216. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  1217. 'desc_bprop': [[32, 1, 1024]]}),
  1218. ('GatherV2_5', {
  1219. 'block': P.GatherV2(),
  1220. 'desc_const': [-1],
  1221. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1222. 'desc_bprop': [[3, 1, 2]]}),
  1223. ('GatherV2_6', {
  1224. 'block': P.GatherV2(),
  1225. 'desc_const': [0],
  1226. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  1227. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  1228. ('SparseGatherV2_0', {
  1229. 'block': P.SparseGatherV2(),
  1230. 'desc_const': [0],
  1231. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1232. 'desc_bprop': [[2, 1, 2]]}),
  1233. ('Range', {
  1234. 'block': inner.Range(1.0, 5.0),
  1235. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  1236. 'desc_bprop': [[10]]}),
  1237. ('UnsortedSegmentSum', {
  1238. 'block': P.UnsortedSegmentSum(),
  1239. 'desc_const': [1280],
  1240. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  1241. 'desc_bprop': [[8192, 1024]],
  1242. 'skip': ['backward']}),
  1243. ('UnsortedSegmentSum_1', {
  1244. 'block': P.UnsortedSegmentSum(),
  1245. 'desc_const': [4],
  1246. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1247. 'desc_bprop': [[4, 1, 3]],
  1248. 'skip': ['backward']}),
  1249. ('UnsortedSegmentMin', {
  1250. 'block': P.UnsortedSegmentMin(),
  1251. 'desc_const': [4],
  1252. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1253. 'desc_bprop': [[4, 2, 1, 3]]}),
  1254. ('UnsortedSegmentProd', {
  1255. 'block': P.UnsortedSegmentProd(),
  1256. 'desc_const': [4],
  1257. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([0, 1, 0]).astype(np.int32))],
  1258. 'desc_bprop': [[4, 2, 1, 3]]}),
  1259. ('DropoutGenMask', {
  1260. 'block': P.DropoutGenMask(),
  1261. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  1262. 'desc_inputs': [],
  1263. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  1264. 'skip': ['backward']}),
  1265. ('DropoutDoMask', {
  1266. 'block': P.DropoutDoMask(),
  1267. 'desc_const': [Tensor(0.5)],
  1268. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  1269. 'desc_bprop': [[64, 12, 128, 128]]}),
  1270. ('Dropout', {
  1271. 'block': nn.Dropout(0.5),
  1272. 'desc_inputs': [[64, 12, 128, 128]],
  1273. 'desc_bprop': [[64, 12, 128, 128]]}),
  1274. ('ReduceMean0', {
  1275. 'block': P.ReduceMean(),
  1276. 'desc_const': [(2,)],
  1277. 'desc_inputs': [[3, 2, 2]],
  1278. 'desc_bprop': [[3, 2]]}),
  1279. ('ReduceMean1', {
  1280. 'block': P.ReduceMean(),
  1281. 'desc_const': [2],
  1282. 'desc_inputs': [[3, 2, 2]],
  1283. 'desc_bprop': [[3, 2]]}),
  1284. ('All', {
  1285. 'block': P.ReduceAll(),
  1286. 'desc_const': [(1,)],
  1287. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  1288. 'desc_bprop': [[3]],
  1289. 'skip': ['backward']}),
  1290. ('DescConst', {
  1291. 'block': Tensor(np.array([2], np.float32)),
  1292. 'desc_inputs': [],
  1293. 'desc_bprop': [[1]],
  1294. 'skip': ['backward'],
  1295. 'add_fake_input': True}),
  1296. ('Fill', {
  1297. 'block': P.Fill(),
  1298. 'desc_const': [mstype.float32, (2, 3), 1.0],
  1299. 'desc_inputs': [],
  1300. 'desc_bprop': [[2, 3]],
  1301. 'skip': ['backward'],
  1302. 'add_fake_input': True}),
  1303. ('OnesLike', {
  1304. 'block': P.OnesLike(),
  1305. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1306. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1307. }),
  1308. ('ZerosLike', {
  1309. 'block': P.ZerosLike(),
  1310. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1311. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1312. }),
  1313. ('Softmax', {
  1314. 'block': P.Softmax(),
  1315. 'desc_inputs': [[5, 5]],
  1316. 'desc_bprop': [[5, 5]]}),
  1317. ('Softsign', {
  1318. 'block': P.Softsign(),
  1319. 'desc_inputs': [[5, 5]],
  1320. 'desc_bprop': [[5, 5]]}),
  1321. ('DepthwiseConv2dNative_1', {
  1322. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  1323. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  1324. 'desc_bprop': [[10, 32, 16, 16]]}),
  1325. ('DepthwiseConv2dNative_2', {
  1326. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  1327. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  1328. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  1329. ('SigmoidCrossEntropyWithLogits', {
  1330. 'block': P.SigmoidCrossEntropyWithLogits(),
  1331. 'desc_inputs': [[128, 10], [128, 10]],
  1332. 'desc_bprop': [[128, 10]]}),
  1333. ('Pad', {
  1334. 'block': P.Pad(((1, 2), (2, 3))),
  1335. 'desc_inputs': [[7, 7]],
  1336. 'desc_bprop': [[10, 12]]}),
  1337. ('BinaryCrossEntropy', {
  1338. 'block': P.BinaryCrossEntropy(),
  1339. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  1340. 'desc_bprop': []}),
  1341. ('SparseApplyAdagrad', {
  1342. 'block': SparseApplyAdagradNet(),
  1343. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1344. 'desc_bprop': [[3, 3], [3, 3]],
  1345. 'skip': ['backward']}),
  1346. ('SparseApplyAdagradV2', {
  1347. 'block': SparseApplyAdagradV2Net(),
  1348. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1349. 'skip': ['backward']}),
  1350. ('SparseApplyFtrl', {
  1351. 'block': SparseApplyFtrlNet(),
  1352. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1353. 'skip': ['backward']}),
  1354. ('SparseApplyFtrlV2', {
  1355. 'block': SparseApplyFtrlV2Net(),
  1356. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1357. 'skip': ['backward']}),
  1358. ('ApplyProximalAdagrad', {
  1359. 'block': ApplyProximalAdagradNet(),
  1360. 'desc_inputs': [[3, 3]],
  1361. 'skip': ['backward']}),
  1362. ('SparseApplyProximalAdagrad', {
  1363. 'block': SparseApplyProximalAdagradNet(),
  1364. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1365. 'skip': ['backward']}),
  1366. ('ApplyAdaMax', {
  1367. 'block': ApplyAdaMaxNet(),
  1368. 'desc_inputs': [[3, 3]],
  1369. 'skip': ['backward']}),
  1370. ('ApplyAdadelta', {
  1371. 'block': ApplyAdadeltaNet(),
  1372. 'desc_inputs': [[3, 3]],
  1373. 'skip': ['backward']}),
  1374. ('ApplyAdagrad', {
  1375. 'block': ApplyAdagradNet(),
  1376. 'desc_inputs': [[3, 3]],
  1377. 'skip': ['backward']}),
  1378. ('ApplyAdagradV2', {
  1379. 'block': ApplyAdagradV2Net(),
  1380. 'desc_inputs': [[3, 3]],
  1381. 'skip': ['backward']}),
  1382. ('ApplyAddSign', {
  1383. 'block': ApplyAddSignNet(),
  1384. 'desc_inputs': [[3, 3]],
  1385. 'skip': ['backward']}),
  1386. ('ApplyPowerSign', {
  1387. 'block': ApplyPowerSignNet(),
  1388. 'desc_inputs': [[3, 3]],
  1389. 'skip': ['backward']}),
  1390. ('ApplyGradientDescent', {
  1391. 'block': ApplyGradientDescentNet(),
  1392. 'desc_inputs': [[3, 3]],
  1393. 'skip': ['backward']}),
  1394. ('ApplyProximalGradientDescent', {
  1395. 'block': ApplyProximalGradientDescentNet(),
  1396. 'desc_inputs': [[3, 3]],
  1397. 'skip': ['backward']}),
  1398. ('Flatten_1', {
  1399. 'block': NetForFlatten(),
  1400. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1401. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1402. 'skip': ['backward']}),
  1403. ('Flatten_2', {
  1404. 'block': NetForFlatten(),
  1405. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  1406. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  1407. 'skip': ['backward']}),
  1408. ('Flatten_3', {
  1409. 'block': NetForFlattenComposed(),
  1410. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1411. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1412. 'skip': []}),
  1413. ('ArgmaxNet', {
  1414. 'block': ArgmaxNet(),
  1415. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1416. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1417. 'skip': ['backward']}),
  1418. ('ArgminNet', {
  1419. 'block': ArgminNet(),
  1420. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1421. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1422. 'skip': ['backward']}),
  1423. ('StridedSliceNet', {
  1424. 'block': StridedSliceNet(),
  1425. 'desc_inputs': [[6, 7, 8, 9, 10]],
  1426. 'skip': ['backward']}),
  1427. ('OneHot', {
  1428. 'block': P.OneHot(),
  1429. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  1430. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  1431. 'desc_bprop': [[1, 3]]}),
  1432. ('ReduceProd_0', {
  1433. 'block': P.ReduceProd(),
  1434. 'desc_const': [0],
  1435. 'desc_inputs': [[3, 2]],
  1436. 'desc_bprop': [[2]]}),
  1437. ('ReduceProd_1', {
  1438. 'block': P.ReduceProd(keep_dims=True),
  1439. 'desc_const': [0],
  1440. 'desc_inputs': [[3, 2]],
  1441. 'desc_bprop': [[1, 2]]}),
  1442. ('CumProd', {
  1443. 'block': P.CumProd(),
  1444. 'desc_const': [0],
  1445. 'desc_inputs': [[3, 2]],
  1446. 'desc_bprop': [[3, 2]]}),
  1447. ('ApplyFtrl', {
  1448. 'block': ApplyFtrlNet(),
  1449. 'desc_inputs': [[3, 3]],
  1450. 'desc_bprop': [3, 3],
  1451. 'skip': ['backward']}),
  1452. ('ApplyRMSProp', {
  1453. 'block': ApplyRMSNet(),
  1454. 'desc_inputs': [[3, 3]],
  1455. 'desc_bprop': [3, 3],
  1456. 'skip': ['backward']}),
  1457. ('ApplyCenteredRMSProp', {
  1458. 'block': P.ApplyCenteredRMSProp(),
  1459. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  1460. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  1461. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  1462. 'desc_bprop': [1],
  1463. 'skip': ['backward']}),
  1464. ('CTCLoss', {
  1465. 'block': P.CTCLoss(),
  1466. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  1467. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  1468. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  1469. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  1470. 'desc_bprop': [[4], [6, 4, 6]]}),
  1471. ('L2Loss_1', {
  1472. 'block': P.L2Loss(),
  1473. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  1474. 'desc_bprop': []}),
  1475. ('L2Loss_2', {
  1476. 'block': P.L2Loss(),
  1477. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  1478. 'desc_bprop': []}),
  1479. ('ResizeBilinear', {
  1480. 'block': P.ResizeBilinear((5, 5)),
  1481. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  1482. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  1483. ('ResizeBilinearGrad', {
  1484. 'block': G.ResizeBilinearGrad(),
  1485. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1486. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1487. 'skip': ['backward']}),
  1488. ('ROIAlign', {
  1489. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  1490. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  1491. 'desc_bprop': [[7, 7]]}),
  1492. ('ROIAlignGrad', {
  1493. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  1494. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  1495. 'desc_bprop': [[1, 1, 2, 2]],
  1496. 'skip': ['backward']}),
  1497. ('LARSUpdate', {
  1498. 'block': P.LARSUpdate(1e-05, 0.001, False),
  1499. 'desc_const': [0.0, 0.001],
  1500. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1501. 'desc_bprop': [3, 3],
  1502. 'skip': ['backward']}),
  1503. ('SGD', {
  1504. 'block': P.SGD(0.0, 0.0, False),
  1505. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  1506. 'desc_bprop': [3, 3],
  1507. 'skip': ['backward']}),
  1508. ('BinaryCrossEntropy', {
  1509. 'block': P.BinaryCrossEntropy(),
  1510. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1511. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1512. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1513. 'desc_bprop': []}),
  1514. ('BinaryCrossEntropyGrad', {
  1515. 'block': G.BinaryCrossEntropyGrad(),
  1516. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1517. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1518. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1519. 'desc_bprop': [],
  1520. 'skip': ['backward']}),
  1521. ('DataFormatDimMap', {
  1522. 'block': P.DataFormatDimMap(),
  1523. 'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
  1524. 'desc_bprop': [],
  1525. 'skip': ['backward']}),
  1526. ('MaxPoolGradGrad', {
  1527. 'block': G.MaxPoolGradGrad(),
  1528. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1529. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1530. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16)],
  1531. 'desc_bprop': [],
  1532. 'skip': ['backward']}),
  1533. ('MaxPoolGradGradWithArgmax', {
  1534. 'block': G.MaxPoolGradGradWithArgmax(),
  1535. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1536. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1537. Tensor(np.zeros((1, 1, 2, 2)), mstype.uint16)],
  1538. 'desc_bprop': [],
  1539. 'skip': ['backward']}),
  1540. ]
  1541. test_case_array_ops = [
  1542. ('SpaceToDepth', {
  1543. 'block': P.SpaceToDepth(2),
  1544. 'desc_inputs': [[1, 3, 2, 2]],
  1545. 'desc_bprop': [[1, 12, 1, 1]]}),
  1546. ('DepthToSpace', {
  1547. 'block': P.DepthToSpace(2),
  1548. 'desc_inputs': [[1, 12, 1, 1]],
  1549. 'desc_bprop': [[1, 3, 2, 2]]}),
  1550. ('Split', {
  1551. 'block': P.Split(1, 2),
  1552. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  1553. 'skip': ['backward']}),
  1554. ('Argmax', {
  1555. 'block': P.Argmax(),
  1556. 'desc_inputs': [[128, 32, 32, 64]],
  1557. 'desc_bprop': [0],
  1558. 'skip': ['backward']}),
  1559. ('Argmin', {
  1560. 'block': P.Argmin(),
  1561. 'desc_inputs': [[128, 32, 32, 64]],
  1562. 'desc_bprop': [1],
  1563. 'skip': ['backward']}),
  1564. ('ArgMaxWithValue', {
  1565. 'block': P.ArgMaxWithValue(),
  1566. 'desc_inputs': [[128, 32, 32, 64]],
  1567. 'desc_bprop': [[1], [1]],
  1568. 'skip': ['backward']}),
  1569. ('ArgMinWithValue', {
  1570. 'block': P.ArgMinWithValue(),
  1571. 'desc_inputs': [[128, 32, 32, 64]],
  1572. 'desc_bprop': [[1], [1]],
  1573. 'skip': ['backward']}),
  1574. ('Transpose_dim3', {
  1575. 'block': P.Transpose(),
  1576. 'desc_const': [(0, 2, 1)],
  1577. 'desc_inputs': [[1, 2, 3]],
  1578. 'desc_bprop': [[1, 3, 2]]}),
  1579. ('Transpose_dim4', {
  1580. 'block': P.Transpose(),
  1581. 'desc_const': [(0, 1, 2, 3)],
  1582. 'desc_inputs': [[1, 2, 3, 4]],
  1583. 'desc_bprop': [[1, 2, 4, 3]]}),
  1584. ('AddN', {
  1585. 'block': NetForTupleInput(P.AddN()),
  1586. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1587. 'desc_bprop': [[2, 3, 3, 5]]}),
  1588. ('AccumulateNV2', {
  1589. 'block': NetForTupleInput(P.AccumulateNV2()),
  1590. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1591. 'desc_bprop': [[2, 3, 3, 5]]}),
  1592. ('Shape', {
  1593. 'block': P.Shape(),
  1594. 'desc_inputs': [[3, 3, 2, 2]],
  1595. 'skip': ['backward']}),
  1596. ('Reshape', {
  1597. 'block': P.Reshape(),
  1598. 'desc_const': [(64,)],
  1599. 'desc_inputs': [[64, 1]],
  1600. 'desc_bprop': [[64]]}),
  1601. ('Cast', {
  1602. 'block': P.Cast(),
  1603. 'desc_const': [mstype.int32],
  1604. 'desc_inputs': [[2, 3, 4, 5]],
  1605. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  1606. ('ExpandDims', {
  1607. 'block': P.ExpandDims(),
  1608. 'desc_const': [0],
  1609. 'desc_inputs': [[2, 2]],
  1610. 'desc_bprop': [[1, 2, 2]]}),
  1611. ('ExpandDims_1', {
  1612. 'block': P.ExpandDims(),
  1613. 'desc_const': [-1],
  1614. 'desc_inputs': [[2, 2]],
  1615. 'desc_bprop': [[2, 2, 1]]}),
  1616. ('Squeeze', {
  1617. 'block': P.Squeeze(2),
  1618. 'desc_inputs': [[3, 2, 1]],
  1619. 'desc_bprop': [[3, 2]]}),
  1620. ('Squeeze_0', {
  1621. 'block': P.Squeeze(),
  1622. 'desc_inputs': [[3, 1, 2, 1]],
  1623. 'desc_bprop': [[3, 2]]}),
  1624. ('Squeeze_1', {
  1625. 'block': P.Squeeze(),
  1626. 'desc_inputs': [[1, 1, 1, 1]],
  1627. 'desc_bprop': [1.0],
  1628. 'skip': ['backward']}),
  1629. ('Squeeze_2', {
  1630. 'block': P.Squeeze((2, 3)),
  1631. 'desc_inputs': [[3, 2, 1, 1]],
  1632. 'desc_bprop': [[3, 2]]}),
  1633. ('Size', {
  1634. 'block': P.Size(),
  1635. 'desc_inputs': [[2, 3, 5]],
  1636. 'skip': ['backward']}),
  1637. ('Tile_0', {
  1638. 'block': P.Tile(),
  1639. 'desc_const': [(1, 2)],
  1640. 'desc_inputs': [[64, 1]],
  1641. 'desc_bprop': [[64, 2]]}),
  1642. ('Tile_1', {
  1643. 'block': P.Tile(),
  1644. 'desc_const': [(1, 1)],
  1645. 'desc_inputs': [[64, 1]],
  1646. 'desc_bprop': [[64, 1]]}),
  1647. ('Tile_2', {
  1648. 'block': P.Tile(),
  1649. 'desc_const': [(2, 1, 1, 2)],
  1650. 'desc_inputs': [[2, 2, 2]],
  1651. 'desc_bprop': [[2, 2, 2, 4]]}),
  1652. ('ConcatV2_0', {
  1653. 'block': P.Concat(),
  1654. 'desc_inputs': [
  1655. (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  1656. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
  1657. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  1658. ('ConcatV2_1', {
  1659. 'block': P.Concat(axis=2),
  1660. 'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  1661. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
  1662. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  1663. ('ConcatV2_2', {
  1664. 'block': NetForConcat(),
  1665. 'desc_inputs': [[2, 2]],
  1666. 'desc_bprop': [[4, 2]]}),
  1667. ('ConcatV2_3', {
  1668. 'block': NetForConcat1(),
  1669. 'desc_inputs': [[2, 2], [2, 2]],
  1670. 'desc_bprop': [[4, 2]]}),
  1671. ('ConcatV2_4', {
  1672. 'block': P.Concat(axis=0),
  1673. 'desc_inputs': [
  1674. (Tensor(np.ones((3, 2, 3), np.float32)),
  1675. Tensor(np.ones((5, 2, 3), np.float32)),
  1676. Tensor(np.ones((6, 2, 3), np.float32)))],
  1677. 'desc_bprop': [[14, 2, 3]]}),
  1678. ('ConcatV2_5', {
  1679. 'block': P.Concat(axis=-1),
  1680. 'desc_inputs': [(Tensor(np.array([1], np.float32)),
  1681. Tensor(np.array([1], np.float32)),
  1682. Tensor(np.array([1], np.float32)))],
  1683. 'desc_bprop': [[3, ]]}),
  1684. ('Pack_0', {
  1685. 'block': NetForPackInput(P.Pack()),
  1686. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1687. 'desc_bprop': [[3, 2, 2]],
  1688. }),
  1689. ('Pack_1', {
  1690. 'block': NetForPackInput(P.Pack(axis=-2)),
  1691. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  1692. 'desc_bprop': [[3, 2, 3, 3]],
  1693. }),
  1694. ('Pack_2', {
  1695. 'block': NetForPackInput(P.Pack()),
  1696. 'desc_inputs': [[128, 128], [128, 128]],
  1697. 'desc_bprop': [[2, 128, 128]],
  1698. }),
  1699. ('Pack_3', {
  1700. 'block': NetForPackInput(P.Pack()),
  1701. 'desc_inputs': [[2, 2]],
  1702. 'desc_bprop': [[1, 2, 2]]}),
  1703. ('Unpack_0', {
  1704. 'block': NetForUnpackInput(P.Unpack(axis=0)),
  1705. 'desc_inputs': [[2, 4]],
  1706. 'desc_bprop': [[4], [4]],
  1707. }),
  1708. ('Unpack_1', {
  1709. 'block': NetForUnpackInput(P.Unpack(axis=-1)),
  1710. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  1711. 'desc_bprop': [[1], [1], [1]],
  1712. }),
  1713. ('Diag_1', {
  1714. 'block': P.Diag(),
  1715. 'desc_inputs': [[4]],
  1716. 'desc_bprop': [[4, 4]],
  1717. }),
  1718. ('Diag_2', {
  1719. 'block': P.Diag(),
  1720. 'desc_inputs': [[4, 4]],
  1721. 'desc_bprop': [[4, 4, 4, 4]],
  1722. }),
  1723. ('DiagPart_1', {
  1724. 'block': P.DiagPart(),
  1725. 'desc_inputs': [[4, 4]],
  1726. 'desc_bprop': [[4]],
  1727. }),
  1728. ('DiagPart_2', {
  1729. 'block': P.DiagPart(),
  1730. 'desc_inputs': [[4, 4, 4, 4]],
  1731. 'desc_bprop': [[4, 4]],
  1732. }),
  1733. ('SpaceToBatch_1', {
  1734. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  1735. 'desc_inputs': [[1, 3, 2, 2]],
  1736. 'desc_bprop': [[4, 3, 1, 1]],
  1737. }),
  1738. ('SpaceToBatch_2', {
  1739. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  1740. 'desc_inputs': [[1, 3, 2, 2]],
  1741. 'desc_bprop': [[4, 3, 2, 3]],
  1742. }),
  1743. ('BatchToSpace_1', {
  1744. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  1745. 'desc_inputs': [[4, 3, 1, 1]],
  1746. 'desc_bprop': [[1, 3, 2, 2]],
  1747. }),
  1748. ('BatchToSpace_2', {
  1749. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  1750. 'desc_inputs': [[4, 3, 1, 1]],
  1751. 'desc_bprop': [[1, 3, 2, 1]],
  1752. }),
  1753. ('UnsortedSegmentMin_1', {
  1754. 'block': P.UnsortedSegmentMin(),
  1755. 'desc_const': [2],
  1756. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  1757. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  1758. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  1759. ('BroadcastTo', {
  1760. 'block': P.BroadcastTo((2, 3)),
  1761. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
  1762. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
  1763. ('InTopK', {
  1764. 'block': P.InTopK(2),
  1765. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
  1766. Tensor(np.array([2, 1, 2]).astype(np.int32))],
  1767. 'skip': ['backward'],
  1768. }),
  1769. ('InplaceUpdate', {
  1770. 'block': P.InplaceUpdate((0, 2)),
  1771. 'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
  1772. Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
  1773. 'skip': ['backward'],
  1774. }),
  1775. ('ReverseSequence', {
  1776. 'block': P.ReverseSequence(1, 0),
  1777. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
  1778. Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1779. 'desc_bprop': [[3, 3]]}),
  1780. ('LinSpace', {
  1781. 'block': inner.LinSpace(),
  1782. 'desc_inputs': [Tensor([5, 5.5], mstype.float32),
  1783. Tensor(1, mstype.float32),
  1784. Tensor(10, mstype.float32),
  1785. Tensor(5, mstype.int32)],
  1786. 'skip': ['backward'],
  1787. }),
  1788. ('MatrixDiag', {
  1789. 'block': inner.MatrixDiag(),
  1790. 'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
  1791. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1792. 'skip': ['backward'],
  1793. }),
  1794. ('MatrixDiagPart', {
  1795. 'block': inner.MatrixDiagPart(),
  1796. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1797. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1798. 'skip': ['backward'],
  1799. }),
  1800. ('MatrixSetDiag', {
  1801. 'block': inner.MatrixSetDiag(),
  1802. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1803. Tensor(np.arange(6).reshape(3, 2), mstype.float32),
  1804. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1805. 'skip': ['backward'],
  1806. }),
  1807. ('TransShape', {
  1808. 'block': P.TransShape(),
  1809. 'desc_const': [(1, 12, 24, 24)],
  1810. 'desc_inputs': [[1, 3, 24, 24]],
  1811. 'desc_bprop': [[1, 12, 24, 24]],
  1812. }),
  1813. ('ParallelConcat', {
  1814. 'block': ParallelConcatNet(),
  1815. 'desc_inputs': [Tensor([[1, 2]], mstype.float32),
  1816. Tensor([[5, 6]], mstype.float32)],
  1817. 'skip': ['backward'],
  1818. }),
  1819. ]
  1820. test_case_other_ops = [
  1821. ('ScalarLog', {
  1822. 'block': F.scalar_log,
  1823. 'desc_const': [0.0],
  1824. 'desc_inputs': [],
  1825. 'desc_bprop': [1],
  1826. 'skip': ['backward']}),
  1827. ('BoundingBoxEncode', {
  1828. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  1829. 'desc_inputs': [[256, 4], [256, 4]],
  1830. 'desc_bprop': [[256, 4]],
  1831. 'skip': ['backward']}),
  1832. ('BoundingBoxDecode', {
  1833. '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)),
  1834. 'desc_inputs': [[256, 4], [256, 4]],
  1835. 'desc_bprop': [[256, 4]],
  1836. 'skip': ['backward']}),
  1837. ('GatherNd', {
  1838. 'block': P.GatherNd(),
  1839. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  1840. Tensor(np.ones((2, 4), np.int32))),
  1841. 'desc_bprop': [[2]]}),
  1842. ('ScatterNd', {
  1843. 'block': P.ScatterNd(),
  1844. 'desc_const': [(3, 3)],
  1845. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  1846. Tensor(np.ones((2,), np.int32))),
  1847. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  1848. ('TensorScatterUpdate', {
  1849. 'block': P.TensorScatterUpdate(),
  1850. 'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
  1851. Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1852. Tensor(np.ones([2, 5], np.float32) * 99)),
  1853. 'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
  1854. ('ScatterMaxUseLocking', {
  1855. 'block': ScatterMax(use_locking=True),
  1856. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1857. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  1858. 'skip': ['backward']}),
  1859. ('ScatterMax1d', {
  1860. 'block': ScatterMax(),
  1861. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1862. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  1863. 'skip': ['backward']}),
  1864. ('ScatterMaxF32', {
  1865. 'block': ScatterMax(),
  1866. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1867. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  1868. 'skip': ['backward']}),
  1869. ('ScatterMaxF16', {
  1870. 'block': ScatterMax(np.float16),
  1871. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1872. Tensor(np.ones([2, 2, 3], np.float16) * 99)),
  1873. 'skip': ['backward']}),
  1874. ('ScatterMaxI32', {
  1875. 'block': ScatterMax(np.int32),
  1876. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1877. Tensor(np.ones([2, 2, 3], np.int32) * 99)),
  1878. 'skip': ['backward']}),
  1879. ('ScatterMinUseLocking', {
  1880. 'block': ScatterMin(use_locking=True),
  1881. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1882. Tensor(np.ones([2, 3], np.float32))),
  1883. 'skip': ['backward']}),
  1884. ('ScatterMin1d', {
  1885. 'block': ScatterMin(),
  1886. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1887. Tensor(np.ones([2, 3], np.float32))),
  1888. 'skip': ['backward']}),
  1889. ('ScatterMinF32', {
  1890. 'block': ScatterMin(),
  1891. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1892. Tensor(np.ones([2, 2, 3], np.float32))),
  1893. 'skip': ['backward']}),
  1894. ('ScatterMinF16', {
  1895. 'block': ScatterMin(np.float16),
  1896. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1897. Tensor(np.ones([2, 2, 3], np.float16))),
  1898. 'skip': ['backward']}),
  1899. ('ScatterMinI32', {
  1900. 'block': ScatterMin(np.int32),
  1901. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1902. Tensor(np.ones([2, 2, 3], np.int32))),
  1903. 'skip': ['backward']}),
  1904. ('ScatterUpdate', {
  1905. 'block': ScatterUpdate((6,)),
  1906. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1907. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1908. 'skip': ['backward']}),
  1909. ('ScatterAddUseLocking', {
  1910. 'block': ScatterAdd((6,), use_locking=True),
  1911. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1912. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1913. 'skip': ['backward']}),
  1914. ('ScatterAdd', {
  1915. 'block': ScatterAdd((6,)),
  1916. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1917. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1918. 'skip': ['backward']}),
  1919. ('ScatterAddScalar', {
  1920. 'block': ScatterAdd((6,)),
  1921. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1922. Tensor(np.array([2.0], np.float32))),
  1923. 'skip': ['backward']}),
  1924. ('ScatterAdd2d', {
  1925. 'block': ScatterAdd((3, 4)),
  1926. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1927. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1928. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1929. 'skip': ['backward']}),
  1930. ('ScatterAddF16', {
  1931. 'block': ScatterAdd((6,), np.float16),
  1932. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1933. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1934. 'skip': ['backward']}),
  1935. ('ScatterAddI8', {
  1936. 'block': ScatterAdd((6,), np.int8),
  1937. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1938. Tensor(np.array([2, 3, 4], np.int8))),
  1939. 'skip': ['backward']}),
  1940. ('ScatterAddI32', {
  1941. 'block': ScatterAdd((6,), np.int32),
  1942. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1943. Tensor(np.array([2, 3, 4], np.int32))),
  1944. 'skip': ['backward']}),
  1945. ('ScatterAddU8', {
  1946. 'block': ScatterAdd((6,), np.uint8),
  1947. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1948. Tensor(np.array([2, 3, 4], np.uint8))),
  1949. 'skip': ['backward']}),
  1950. ('ScatterMulUseLocking', {
  1951. 'block': ScatterMul((6,), use_locking=True),
  1952. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1953. Tensor(np.array([2.0], np.float32))),
  1954. 'skip': ['backward']}),
  1955. ('ScatterMulScalar', {
  1956. 'block': ScatterMul((6,)),
  1957. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1958. Tensor(np.array([2.0], np.float32))),
  1959. 'skip': ['backward']}),
  1960. ('ScatterMul2d', {
  1961. 'block': ScatterMul((3, 4)),
  1962. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1963. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1964. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1965. 'skip': ['backward']}),
  1966. ('ScatterMulF16', {
  1967. 'block': ScatterMul((6,), np.float16),
  1968. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1969. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1970. 'skip': ['backward']}),
  1971. ('ScatterMulI8', {
  1972. 'block': ScatterMul((6,), np.int8),
  1973. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1974. Tensor(np.array([2, 3, 4], np.int8))),
  1975. 'skip': ['backward']}),
  1976. ('ScatterMulI32', {
  1977. 'block': ScatterMul((6,), np.int32),
  1978. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1979. Tensor(np.array([2, 3, 4], np.int32))),
  1980. 'skip': ['backward']}),
  1981. ('ScatterMulU8', {
  1982. 'block': ScatterMul((6,), np.uint8),
  1983. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1984. Tensor(np.array([2, 3, 4], np.uint8))),
  1985. 'skip': ['backward']}),
  1986. ('ScatterDivUseLocking', {
  1987. 'block': ScatterDiv((6,), use_locking=True),
  1988. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1989. Tensor(np.array([2.0], np.float32))),
  1990. 'skip': ['backward']}),
  1991. ('ScatterDivScalar', {
  1992. 'block': ScatterDiv((6,)),
  1993. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1994. Tensor(np.array([2.0], np.float32))),
  1995. 'skip': ['backward']}),
  1996. ('ScatterDiv2d', {
  1997. 'block': ScatterDiv((3, 4)),
  1998. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1999. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2000. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2001. 'skip': ['backward']}),
  2002. ('ScatterDivF16', {
  2003. 'block': ScatterDiv((6,), np.float16),
  2004. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2005. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2006. 'skip': ['backward']}),
  2007. ('ScatterDivI8', {
  2008. 'block': ScatterDiv((6,), np.int8),
  2009. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2010. Tensor(np.array([2, 3, 4], np.int8))),
  2011. 'skip': ['backward']}),
  2012. ('ScatterDivU8', {
  2013. 'block': ScatterDiv((6,), np.uint8),
  2014. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2015. Tensor(np.array([2, 3, 4], np.uint8))),
  2016. 'skip': ['backward']}),
  2017. ('ScatterSubUseLocking', {
  2018. 'block': ScatterSub((6,), use_locking=True),
  2019. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2020. Tensor(np.array([2.0], np.float32))),
  2021. 'skip': ['backward']}),
  2022. ('ScatterSubScalar', {
  2023. 'block': ScatterSub((6,)),
  2024. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2025. Tensor(np.array([2.0], np.float32))),
  2026. 'skip': ['backward']}),
  2027. ('ScatterSub2d', {
  2028. 'block': ScatterSub((3, 4)),
  2029. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2030. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2031. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2032. 'skip': ['backward']}),
  2033. ('ScatterSubF16', {
  2034. 'block': ScatterSub((6,), np.float16),
  2035. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2036. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2037. 'skip': ['backward']}),
  2038. ('ScatterSubI32', {
  2039. 'block': ScatterSub((6,), np.int32),
  2040. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2041. Tensor(np.array([2, 3, 4], np.int32))),
  2042. 'skip': ['backward']}),
  2043. ('ScatterSubI8', {
  2044. 'block': ScatterSub((6,), np.int8),
  2045. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2046. Tensor(np.array([2, 3, 4], np.int8))),
  2047. 'skip': ['backward']}),
  2048. ('ScatterSubU8', {
  2049. 'block': ScatterSub((6,), np.uint8),
  2050. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2051. Tensor(np.array([1, 1, 0], np.uint8))),
  2052. 'skip': ['backward']}),
  2053. ('SmoothL1Loss', {
  2054. 'block': P.SmoothL1Loss(),
  2055. 'desc_inputs': [[256, 4], [256, 4]],
  2056. 'desc_bprop': [[256, 4]]}),
  2057. ('IOU', {
  2058. 'block': P.IOU(),
  2059. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  2060. 'desc_bprop': [[128, 256]]}),
  2061. ('Summary', {
  2062. 'block': SummaryNet(),
  2063. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2064. Tensor(np.array([1.2]).astype(np.float32))],
  2065. 'skip': ['backward']}),
  2066. ('ConfusionMulGrad_1', {
  2067. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
  2068. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  2069. 'desc_bprop': [[3, 2], [2]],
  2070. 'skip': ['backward']}),
  2071. ('ConfusionMulGrad_2', {
  2072. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
  2073. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  2074. 'desc_bprop': [[3, 2], [1, 2]],
  2075. 'skip': ['backward']}),
  2076. ('ConfusionMulGrad_3', {
  2077. 'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
  2078. 'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
  2079. 'desc_bprop': [[2, 3, 4], [1, 1, 1]],
  2080. 'skip': ['backward']}),
  2081. ('HistogramSummary', {
  2082. 'block': HistogramSummaryNet(),
  2083. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2084. Tensor(np.array([1.2]).astype(np.float32))],
  2085. 'skip': ['backward']}),
  2086. ('PopulationCount', {
  2087. 'block': P.PopulationCount(),
  2088. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.int16))],
  2089. 'skip': ['backward']}),
  2090. ]
  2091. test_case_quant_ops = [
  2092. ('Quant_1', {
  2093. 'block': inner.Quant(0.5, 0.0, False, "Round"),
  2094. 'desc_inputs': [Tensor(np.random.rand(1, 2, 4, 4), mstype.float32)],
  2095. 'skip': ['backward']}),
  2096. ('Quant_2', {
  2097. 'block': inner.Quant(80.0, 10.0, True, "Round"),
  2098. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2099. 'skip': ['backward']}),
  2100. ('Quant_3', {
  2101. 'block': inner.Quant(80.0, 0.0, False, "Floor"),
  2102. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2103. 'skip': ['backward']}),
  2104. ('Quant_4', {
  2105. 'block': inner.Quant(80.0, 0.0, False, "Ceil"),
  2106. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2107. 'skip': ['backward']}),
  2108. ('Quant_5', {
  2109. 'block': inner.Quant(80.0, 0.0, False, "Trunc"),
  2110. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2111. 'skip': ['backward']}),
  2112. ('Quant_6', {
  2113. 'block': inner.Quant(-80.0, 10.0, False, "Round"),
  2114. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2115. 'skip': ['backward']}),
  2116. ('Quant_7', {
  2117. 'block': inner.Quant(80.0, -10.0, False, "Round"),
  2118. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2119. 'skip': ['backward']}),
  2120. ('Quant_8', {
  2121. 'block': inner.Quant(80.0, 10.0, False, "Round"),
  2122. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
  2123. 'skip': ['backward']}),
  2124. ]
  2125. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops, test_case_quant_ops]
  2126. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  2127. # use -k to select certain testcast
  2128. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  2129. test_exec_case = test_case
  2130. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
  2131. @non_graph_engine
  2132. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  2133. def test_exec():
  2134. context.set_context(mode=context.GRAPH_MODE)
  2135. return test_exec_case
  2136. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  2137. def test_backward_exec():
  2138. context.set_context(mode=context.GRAPH_MODE)
  2139. return test_backward_exec_case
  2140. raise_set = [
  2141. ('Cast_Error', {
  2142. 'block': (P.Cast(), {'exception': TypeError}),
  2143. 'desc_const': [mstype.int32],
  2144. 'desc_inputs': ['wrong input'],
  2145. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  2146. ('Maximum_Error', {
  2147. 'block': (P.Maximum(), {'exception': TypeError}),
  2148. 'desc_const': [(1, 2, 3)],
  2149. 'desc_inputs': [[2, 3, 3, 5]],
  2150. 'desc_bprop': [[2, 3, 3, 5]]}),
  2151. ('Shape_error', {
  2152. 'block': (P.Shape(), {'exception': TypeError}),
  2153. 'desc_inputs': [(64, 1)],
  2154. 'desc_bprop': [[64]]}),
  2155. ('Flatten_Error', {
  2156. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  2157. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  2158. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  2159. ('ScatterNdUpdate', {
  2160. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  2161. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  2162. Tensor(np.ones((2, 2), np.float32)),
  2163. Tensor(np.ones((2,), np.float32))),
  2164. 'desc_bprop': [[2, 3]]}),
  2165. ('PReLU', {
  2166. 'block': (P.PReLU(), {'exception': ValueError}),
  2167. 'desc_inputs': [[2], [1]],
  2168. 'desc_bprop': [[1]]}),
  2169. ('SSIM', {
  2170. 'block': (nn.SSIM(), {'exception': ValueError}),
  2171. 'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
  2172. Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]}),
  2173. ('StridedSlice_0', {
  2174. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2175. 'desc_const': [(1, 2.2, 3), (3, 4, 5), (1, 1, 1)],
  2176. 'desc_inputs': [[4, 5, 6, 7]]}),
  2177. ('StridedSlice_1', {
  2178. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2179. 'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1)],
  2180. 'desc_inputs': [[4, 5, 6, 7]]}),
  2181. ('StridedSlice_2', {
  2182. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2183. 'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1, 0)],
  2184. 'desc_inputs': [[4, 5, 6, 7]]}),
  2185. ]
  2186. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  2187. def test_check_exception():
  2188. return raise_set