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