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

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