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