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

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