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