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