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