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