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 122 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
  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. class ApplyAdagradDANet(nn.Cell):
  752. def __init__(self, use_locking=False):
  753. super(ApplyAdagradDANet, self).__init__()
  754. self.apply_adagrad_d_a = P.ApplyAdagradDA(use_locking)
  755. self.var = Parameter(Tensor(np.array([[0.6, 0.4], [0.1, 0.5]]).astype(np.float32)), name="var")
  756. self.gradient_accumulator = Parameter(Tensor(np.array([[0.1, 0.3], [0.1, 0.5]]).astype(np.float32)),
  757. name="gradient_accumulator")
  758. self.gradient_squared_accumulator = Parameter(Tensor(np.array([[0.2, 0.1], [0.1, 0.2]]).astype(np.float32)),
  759. name="gradient_squared_accumulator")
  760. def construct(self, grad, lr, l1, l2, global_step):
  761. out = self.apply_adagrad_d_a(self.var, self.gradient_accumulator, self.gradient_squared_accumulator, grad,
  762. lr, l1, l2, global_step)
  763. return out
  764. class SparseApplyRMSPropNet(nn.Cell):
  765. def __init__(self, rho, momentum, epsilon, use_locking=False):
  766. super(SparseApplyRMSPropNet, self).__init__()
  767. self.sparse_apply_r_m_s_prop = P.SparseApplyRMSProp(rho, momentum, epsilon, use_locking)
  768. self.var = Parameter(Tensor(np.array([[0.6, 0.3], [0.1, 0.5]]).astype(np.float32)), name="var")
  769. self.ms = Parameter(Tensor(np.array([[0.2, 0.4], [0.1, 0.3]]).astype(np.float32)), name="ms")
  770. self.mom = Parameter(Tensor(np.array([[0.3, 0.1], [0.3, 0.6]]).astype(np.float32)), name="mom")
  771. def construct(self, lr, grad, indices):
  772. out = self.sparse_apply_r_m_s_prop(self.var, self.ms, self.mom, lr, grad, indices)
  773. return out
  774. test_case_math_ops = [
  775. ('BitwiseAnd', {
  776. 'block': P.BitwiseAnd(),
  777. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  778. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  779. 'skip': ['backward']}),
  780. ('BitwiseAnd_1', {
  781. 'block': P.BitwiseAnd(),
  782. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  783. Tensor(np.array([1, 1, 1]), mstype.int16)],
  784. 'skip': ['backward']}),
  785. ('BitwiseOr', {
  786. 'block': P.BitwiseOr(),
  787. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  788. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  789. 'skip': ['backward']}),
  790. ('BitwiseOr_1', {
  791. 'block': P.BitwiseOr(),
  792. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  793. Tensor(np.array([1, 1, 1]), mstype.int16)],
  794. 'skip': ['backward']}),
  795. ('BitwiseXor', {
  796. 'block': P.BitwiseXor(),
  797. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  798. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  799. 'skip': ['backward']}),
  800. ('BitwiseXor_1', {
  801. 'block': P.BitwiseXor(),
  802. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  803. Tensor(np.array([1, 1, 1]), mstype.int16)],
  804. 'skip': ['backward']}),
  805. ('Neg', {
  806. 'block': P.Neg(),
  807. 'desc_inputs': [[1, 3, 4, 4]],
  808. 'desc_bprop': [[1, 3, 4, 4]]}),
  809. ('Sub', {
  810. 'block': P.Sub(),
  811. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  812. 'desc_bprop': [[2, 3, 3, 5]]}),
  813. ('Add', {
  814. 'block': P.Add(),
  815. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  816. 'desc_bprop': [[2, 3, 3, 5]]}),
  817. ('Mul0', {
  818. 'block': P.Mul(),
  819. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  820. 'desc_bprop': [[2, 3, 3, 5]]}),
  821. ('Mul1', {
  822. 'block': P.Mul(),
  823. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  824. 'desc_bprop': [[2, 3, 3, 5]]}),
  825. ('Mul2', {
  826. 'block': P.Mul(),
  827. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  828. 'desc_bprop': [[2, 3, 3, 5]],
  829. 'skip': ['backward']}),
  830. ('Mul3', {
  831. 'block': P.Mul(),
  832. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  833. 'desc_bprop': [[2, 3, 3, 5]],
  834. 'skip': ['backward']}),
  835. ('Mul4', {
  836. 'block': P.Mul(),
  837. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  838. 'desc_bprop': [[2, 3, 3, 5]],
  839. 'skip': ['backward']}),
  840. ('Add0', {
  841. 'block': P.Add(),
  842. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  843. 'desc_bprop': [[2, 3, 3, 5]]}),
  844. ('Add1', {
  845. 'block': P.Add(),
  846. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  847. 'desc_bprop': [[2, 3, 3, 5]],
  848. 'skip': ['backward']}),
  849. ('Add2', {
  850. 'block': P.Add(),
  851. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  852. 'desc_bprop': [[2, 3, 3, 5]],
  853. 'skip': ['backward']}),
  854. ('Add3', {
  855. 'block': P.Add(),
  856. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  857. 'desc_bprop': [[2, 3, 3, 5]],
  858. 'skip': ['backward']}),
  859. ('Add4', {
  860. 'block': P.Add(),
  861. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  862. 'desc_bprop': [[2, 3, 3, 5]],
  863. 'skip': ['backward']}),
  864. ('Minimum', {
  865. 'block': P.Minimum(),
  866. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  867. 'desc_bprop': [[2, 3, 3, 5]]}),
  868. ('Pow_0', {
  869. 'block': P.Pow(),
  870. 'desc_const': [2.0],
  871. 'desc_inputs': [[2, 3, 3, 5]],
  872. 'desc_bprop': [[2, 3, 3, 5]]}),
  873. ('Pow_1', {
  874. 'block': P.Pow(),
  875. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  876. 'desc_bprop': [[2, 3, 3, 5]]}),
  877. ('Exp', {
  878. 'block': P.Exp(),
  879. 'desc_inputs': [[2, 3]],
  880. 'desc_bprop': [[2, 3]]}),
  881. ('Expm1', {
  882. 'block': P.Expm1(),
  883. 'desc_inputs': [[2, 3]],
  884. 'desc_bprop': [[2, 3]]}),
  885. ('Erf', {
  886. 'block': P.Erf(),
  887. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  888. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  889. ('Floor', {
  890. 'block': P.Floor(),
  891. 'desc_inputs': [[2, 512, 56, 56]],
  892. 'desc_bprop': [[2, 512, 56, 56]],
  893. 'skip': ['backward']}),
  894. ('Ceil', {
  895. 'block': P.Ceil(),
  896. 'desc_inputs': [[2, 512, 56, 56]],
  897. 'desc_bprop': [[2, 512, 56, 56]],
  898. 'skip': ['backward']}),
  899. ('InplaceAdd', {
  900. 'block': InplaceAddNet(),
  901. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  902. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  903. 'skip': ['backward']}),
  904. ('InplaceSub', {
  905. 'block': InplaceSubNet(),
  906. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  907. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  908. 'skip': ['backward']}),
  909. ('ACos', {
  910. 'block': P.ACos(),
  911. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  912. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  913. ('ACosGrad', {
  914. 'block': G.ACosGrad(),
  915. 'desc_inputs': [[2, 3], [2, 3]],
  916. 'skip': ['backward']}),
  917. ('Acosh', {
  918. 'block': P.Acosh(),
  919. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  920. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  921. ('AcoshGrad', {
  922. 'block': G.AcoshGrad(),
  923. 'desc_inputs': [[2, 3], [2, 3]],
  924. 'skip': ['backward']}),
  925. ('Sin', {
  926. 'block': P.Sin(),
  927. 'desc_inputs': [[2, 3]],
  928. 'desc_bprop': [[2, 3]]}),
  929. ('Asin', {
  930. 'block': P.Asin(),
  931. 'desc_inputs': [[2, 3]],
  932. 'desc_bprop': [[2, 3]]}),
  933. ('Asinh', {
  934. 'block': P.Asinh(),
  935. 'desc_inputs': [[3, 4, 5]],
  936. 'desc_bprop': [[3, 4, 5]]}),
  937. ('Tan', {
  938. 'block': P.Tan(),
  939. 'desc_inputs': [[2, 3]],
  940. 'desc_bprop': [[2, 3]]}),
  941. ('Reciprocal', {
  942. 'block': P.Reciprocal(),
  943. 'desc_inputs': [[2, 3, 3, 5]],
  944. 'desc_bprop': [[2, 3, 3, 5]]}),
  945. ('Minimum_0', {
  946. 'block': P.Minimum(),
  947. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  948. 'desc_bprop': [[2, 3, 3, 5]]}),
  949. ('Maximum', {
  950. 'block': P.Maximum(),
  951. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  952. 'desc_bprop': [[2, 3, 3, 5]]}),
  953. ('Maximum_0', {
  954. 'block': P.Maximum(),
  955. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  956. 'desc_bprop': [[2, 3, 3, 5]]}),
  957. ('MaximumGrad', {
  958. 'block': G.MaximumGrad(),
  959. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  960. 'skip': ['backward']}),
  961. ('MinimumGrad', {
  962. 'block': G.MinimumGrad(),
  963. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  964. 'skip': ['backward']}),
  965. ('StridedSlice_00', {
  966. 'block': P.StridedSlice(shrink_axis_mask=0),
  967. 'desc_const': [(0, 1, 2, 1),
  968. (2, 3, 3, 4),
  969. (1, 1, 1, 2)],
  970. 'desc_inputs': [[2, 3, 3, 5]],
  971. 'desc_bprop': [[2, 2, 1, 3]],
  972. 'skip': ['backward']}),
  973. ('Slice_1', {
  974. 'block': P.Slice(),
  975. 'desc_const': [(0, 1, 2, 1),
  976. (1, 1, 1, 2)],
  977. 'desc_inputs': [[2, 3, 3, 5]],
  978. 'desc_bprop': [[1, 1, 1, 2]]}),
  979. ('StridedSliceGrad', {
  980. 'block': G.StridedSliceGrad(),
  981. 'desc_const': [(64, 1, 1024),
  982. (0, 1, 0),
  983. (64, 2, 1024),
  984. (1, 1, 1)],
  985. 'desc_inputs': [[64, 128, 1024]],
  986. 'skip': ['backward']}),
  987. ('Normal', {
  988. 'block': NormalNet((3, 2, 4), 0),
  989. 'desc_inputs': [Tensor(0.0, mstype.float32), Tensor(1.0, mstype.float32)],
  990. 'skip': ['backward']}),
  991. ('Laplace', {
  992. 'block': LaplaceNet((3, 2, 4), 0),
  993. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  994. 'skip': ['backward']}),
  995. ('Gamma', {
  996. 'block': GammaNet((3, 2, 4), 0),
  997. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  998. 'skip': ['backward']}),
  999. ('Poisson', {
  1000. 'block': PoissonNet((3, 2, 4), 0),
  1001. 'desc_inputs': [Tensor(2.0, mstype.float32)],
  1002. 'skip': ['backward']}),
  1003. ('Uniform', {
  1004. 'block': UniformNet((3, 2, 4), 0),
  1005. 'desc_inputs': [Tensor(0.0, mstype.float32), Tensor(1.0, mstype.float32)],
  1006. 'skip': ['backward']}),
  1007. ('RandomChoiceWithMask', {
  1008. 'block': P.RandomChoiceWithMask(256),
  1009. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  1010. 'desc_bprop': [[256, 4], [256, 4]],
  1011. 'skip': ['backward']}),
  1012. ('Lerp', {
  1013. 'block': P.Lerp(),
  1014. 'desc_inputs': [Tensor(np.array([1., 2., 3., 4.]).astype(np.float32)),
  1015. Tensor(np.array([10., 10., 10., 10.]).astype(np.float32)),
  1016. Tensor(0.5, mstype.float32)],
  1017. 'desc_bprop': [Tensor(np.array([1., 2., 3., 4.]).astype(np.float32))]}),
  1018. ('LessEqual', {
  1019. 'block': P.LessEqual(),
  1020. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  1021. Tensor(np.random.rand(4).astype(np.float16))],
  1022. 'skip': ['backward']}),
  1023. ('Less', {
  1024. 'block': P.Less(),
  1025. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  1026. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  1027. 'skip': ['backward']}),
  1028. ('RealDiv_0', {
  1029. 'block': P.RealDiv(),
  1030. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  1031. 'desc_inputs': [],
  1032. 'skip': ['backward']}),
  1033. ('RealDiv', {
  1034. 'block': P.RealDiv(),
  1035. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  1036. 'desc_bprop': [[4]]}),
  1037. ('RealDiv_1', {
  1038. 'block': P.RealDiv(),
  1039. 'desc_inputs': [[512, 1024], [512, 1024]],
  1040. 'desc_bprop': [[512, 1024]]}),
  1041. ('FloorDiv', {
  1042. 'block': P.FloorDiv(),
  1043. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  1044. Tensor(np.random.rand(4).astype(np.float16))],
  1045. 'skip': ['backward']}),
  1046. ('FloorMod', {
  1047. 'block': P.FloorMod(),
  1048. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1049. 'desc_bprop': [[2, 3, 4, 5]]}),
  1050. ('TruncateDiv', {
  1051. 'block': P.TruncateDiv(),
  1052. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1053. 'desc_bprop': [[2, 3, 4, 5]]}),
  1054. ('TruncateMod', {
  1055. 'block': P.TruncateMod(),
  1056. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1057. 'desc_bprop': [[2, 3, 4, 5]]}),
  1058. ('identity', {
  1059. 'block': ops.functional.identity,
  1060. 'desc_inputs': [[2, 2]],
  1061. 'skip': ['backward']}),
  1062. ('MatMul_1', {
  1063. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  1064. 'desc_inputs': [[1024, 160], [160, 1024]],
  1065. 'desc_bprop': [[1024, 1024]]}),
  1066. ('MatMul_2', {
  1067. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  1068. 'desc_inputs': [[160, 1024], [1024, 160]],
  1069. 'desc_bprop': [[1024, 1024]]}),
  1070. ('Sub', {
  1071. 'block': P.Sub(),
  1072. 'desc_inputs': [[3], [3]],
  1073. 'desc_bprop': [[3]]}),
  1074. ('TruncatedNormal', {
  1075. 'block': P.TruncatedNormal(),
  1076. 'desc_const': [(1, 2, 3)],
  1077. 'desc_inputs': [],
  1078. 'skip': ['backward'],
  1079. 'add_fake_input': True}),
  1080. ('Select', {
  1081. 'block': P.Select(),
  1082. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  1083. [2, 3], [2, 3]],
  1084. 'desc_bprop': [[2, 3]]}),
  1085. ('ClipByNorm_1', {
  1086. 'block': ClipByNorm(),
  1087. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1088. Tensor(np.array([0.01]).astype(np.float32))],
  1089. 'skip': ['backward']}),
  1090. ('ClipByNorm_2', {
  1091. 'block': ClipByNorm(axis=0),
  1092. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1093. Tensor(np.array([0.01]).astype(np.float32))],
  1094. 'skip': ['backward']}),
  1095. ('ClipByGlobalNorm', {
  1096. 'block': ClipByGlobalNorm(x=Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1097. clip_norm=1.0, use_norm=None),
  1098. 'desc_inputs': [],
  1099. 'skip': ['backward']}),
  1100. ('Embedding_1', {
  1101. 'block': Embedding(vocab_size=10, embedding_size=3),
  1102. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1103. 'skip': ['backward']}),
  1104. ('Embedding_2', {
  1105. 'block': Embedding(vocab_size=10, embedding_size=3, padding_idx=2),
  1106. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1107. 'skip': ['backward']}),
  1108. ('EmbeddingLookup_1', {
  1109. 'block': EmbeddingLookup(vocab_size=10, embedding_size=3),
  1110. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1111. 'skip': ['backward']}),
  1112. ('EmbeddingLookup_2', {
  1113. 'block': EmbeddingLookup(vocab_size=10, embedding_size=3, max_norm=0.01),
  1114. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1115. 'skip': ['backward']}),
  1116. ('Moments', {
  1117. 'block': Moments(axis=(), keep_dims=False),
  1118. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32))],
  1119. 'skip': ['backward']}),
  1120. ('NLLLoss', {
  1121. 'block': NLLLoss(reduction="mean"),
  1122. 'desc_inputs': [Tensor(np.random.rand(3, 16), mstype.float32),
  1123. Tensor(np.random.rand(3), mstype.int32),
  1124. Tensor(np.random.rand(16), mstype.float32)],
  1125. 'desc_bprop': [(Tensor(np.random.rand(1), mstype.float32), Tensor(np.random.rand(1), mstype.float32))]}),
  1126. ('BatchNorm3d', {
  1127. 'block': BatchNorm3d(num_features=3),
  1128. 'desc_inputs': [Tensor(np.random.rand(3, 3, 3, 5, 4).astype(np.float32))],
  1129. 'skip': ['backward']}),
  1130. ('Conv3D', {
  1131. 'block': Conv3D(out_channel=32, kernel_size=(4, 3, 3), mode=1, pad_mode='valid', pad=0,
  1132. stride=1, dilation=1, group=1, data_format="NCDHW"),
  1133. 'desc_inputs': [Tensor(np.random.random((16, 3, 10, 32, 32)).astype(np.float16)),
  1134. Tensor(np.random.random((32, 3, 4, 3, 3)).astype(np.float16))],
  1135. 'skip': ['backward']}),
  1136. ('Conv3DBackpropInput', {
  1137. 'block': Conv3DBackpropInput(input_shape=(16, 32, 13, 37, 33), out_channel=32, kernel_size=(4, 6, 2), mode=1,
  1138. pad_mode='valid', pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1139. 'desc_inputs': [Tensor(np.random.random((32, 32, 4, 6, 2)).astype(np.float16)),
  1140. Tensor(np.random.random((16, 32, 10, 32, 32)).astype(np.float16))],
  1141. 'skip': ['backward']}),
  1142. ('Conv3DBackpropFilter', {
  1143. 'block': Conv3DBackpropFilter(w_shape=(32, 32, 4, 6, 2), out_channel=32, kernel_size=(4, 6, 2), mode=1,
  1144. pad_mode='valid', pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1145. 'desc_inputs': [Tensor(np.random.random((16, 32, 13, 37, 33)).astype(np.float16)),
  1146. Tensor(np.random.random((16, 32, 10, 32, 32)).astype(np.float16))],
  1147. 'skip': ['backward']}),
  1148. ('Conv3DTranspose', {
  1149. 'block': Conv3DTranspose(in_channel=32, out_channel=3, kernel_size=(4, 6, 2), mode=1,
  1150. pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1151. 'desc_inputs': [Tensor(np.random.random((32, 3, 10, 32, 32)).astype(np.float16)),
  1152. Tensor(np.random.random((3, 3, 4, 6, 2)).astype(np.float16))],
  1153. 'skip': ['backward']}),
  1154. ('CountNonZero', {
  1155. 'block': CountNonZero(axis=(), keep_dims=False, dtype=mstype.int32),
  1156. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32))],
  1157. 'skip': ['backward']}),
  1158. ('FakeQuantWithMinMaxVars', {
  1159. 'block': Q.FakeQuantWithMinMaxVars(num_bits=8, narrow_range=False),
  1160. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 5), mstype.float32),
  1161. Tensor(np.array([-6]), mstype.float32),
  1162. Tensor(np.array([6]), mstype.float32)],
  1163. 'desc_bprop': [Tensor(np.random.rand(3, 16, 5, 5), mstype.float32)]}),
  1164. ('FakeQuantWithMinMaxVarsPerChannel', {
  1165. 'block': Q.FakeQuantWithMinMaxVarsPerChannel(num_bits=8, narrow_range=False),
  1166. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4), mstype.float32),
  1167. Tensor(np.array([-6, -1, -2, -3]), mstype.float32),
  1168. Tensor(np.array([6, 1, 2, 3]), mstype.float32)],
  1169. 'desc_bprop': [Tensor(np.random.rand(3, 16, 5, 4), mstype.float32)]}),
  1170. ('Mish', {
  1171. 'block': Mish(),
  1172. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1173. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1174. ('SeLU', {
  1175. 'block': SeLU(),
  1176. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1177. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1178. ('MulNoNan', {
  1179. 'block': MulNoNan(),
  1180. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32),
  1181. Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1182. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1183. ('Rank', {
  1184. 'block': P.Rank(),
  1185. 'desc_inputs': [[2, 3]],
  1186. 'skip': ['backward']}),
  1187. ('InvertPermutation', {
  1188. 'block': P.InvertPermutation(),
  1189. 'desc_const': [(0, 3, 1, 2)],
  1190. 'desc_inputs': [],
  1191. 'skip': ['backward']}),
  1192. ('Xdivy', {
  1193. 'block': P.Xdivy(),
  1194. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1195. 'desc_bprop': [[2, 3, 4, 5]]}),
  1196. ('Xlogy', {
  1197. 'block': P.Xlogy(),
  1198. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1199. 'desc_bprop': [[2, 3, 4, 5]]}),
  1200. ('SquaredDifference', {
  1201. 'block': P.SquaredDifference(),
  1202. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1203. 'desc_bprop': [[2, 3, 4, 5]]}),
  1204. ('Square', {
  1205. 'block': P.Square(),
  1206. 'desc_inputs': [[4]],
  1207. 'desc_bprop': [[4]]}),
  1208. ('Rsqrt', {
  1209. 'block': P.Rsqrt(),
  1210. 'desc_inputs': [[4]],
  1211. 'desc_bprop': [[4]]}),
  1212. ('Sqrt', {
  1213. 'block': P.Sqrt(),
  1214. 'desc_inputs': [[4]],
  1215. 'desc_bprop': [[4]]}),
  1216. ('RealDiv', {
  1217. 'block': P.RealDiv(),
  1218. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1219. 'desc_bprop': [[2, 3, 4, 5]]}),
  1220. ('IsFinite', {
  1221. 'block': P.IsFinite(),
  1222. 'desc_inputs': [Tensor(np.random.random((3, 4, 5)).astype(np.float32))],
  1223. 'desc_bprop': [Tensor(np.random.random((3, 4, 5)).astype(np.bool))]}),
  1224. ('Div', {
  1225. 'block': P.Div(),
  1226. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1227. 'desc_bprop': [[2, 3, 4, 5]]}),
  1228. ('Equal', {
  1229. 'block': P.Equal(),
  1230. 'desc_inputs': [[3, 4, 5], [4, 5]],
  1231. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1232. ('NotEqual', {
  1233. 'block': P.NotEqual(),
  1234. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  1235. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1236. ('NotEqual_0', {
  1237. 'block': P.NotEqual(),
  1238. 'desc_inputs': [Tensor(np.array(1).astype(np.int32)), [2, 3, 4, 5]],
  1239. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  1240. 'skip': ['backward']}),
  1241. ('ApproximateEqual', {
  1242. 'block': P.ApproximateEqual(),
  1243. 'desc_inputs': [[3, 4, 5], [3, 4, 5]],
  1244. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1245. ('Greater', {
  1246. 'block': P.Greater(),
  1247. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  1248. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1249. ('GreaterEqual', {
  1250. 'block': P.GreaterEqual(),
  1251. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  1252. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1253. ('LogicalNot', {
  1254. 'block': P.LogicalNot(),
  1255. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  1256. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  1257. ('LogicalAnd', {
  1258. 'block': P.LogicalAnd(),
  1259. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  1260. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  1261. ('LogicalOr', {
  1262. 'block': P.LogicalOr(),
  1263. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  1264. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1265. ('NpuAllocFloatStatus', {
  1266. 'block': P.NPUAllocFloatStatus(),
  1267. 'desc_inputs': [],
  1268. 'add_fack_input': True,
  1269. 'fack_input_type': np.float32,
  1270. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1271. 'skip': ['backward']}),
  1272. ('NpuGetFloatStatus', {
  1273. 'block': P.NPUGetFloatStatus(),
  1274. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  1275. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1276. 'skip': ['backward']}),
  1277. ('NpuClearFloatStatus', {
  1278. 'block': P.NPUClearFloatStatus(),
  1279. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  1280. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1281. 'skip': ['backward']}),
  1282. ('CheckValid', {
  1283. 'block': P.CheckValid(),
  1284. 'desc_inputs': [[20000, 4], [3]],
  1285. 'desc_bprop': [[20000]],
  1286. 'skip': ['backward']}),
  1287. ('NMSWithMask', {
  1288. 'block': P.NMSWithMask(0.5),
  1289. 'desc_inputs': [[128, 5]],
  1290. 'desc_bprop': [[128, 5], [128], [128]],
  1291. 'skip': ['backward']}),
  1292. ('Abs', {
  1293. 'block': P.Abs(),
  1294. 'desc_inputs': [[4]],
  1295. 'desc_bprop': [[4]]}),
  1296. ('CumSum', {
  1297. 'block': CumSumNet(),
  1298. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  1299. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  1300. [1, 3, 7, 9]]).astype(np.float32))]}),
  1301. ('ReduceSum_3', {
  1302. 'block': P.ReduceSum(),
  1303. 'desc_const': [0],
  1304. 'desc_inputs': [[3, 2]],
  1305. 'desc_bprop': [[2]]}),
  1306. ('ReduceSum_4', {
  1307. 'block': P.ReduceSum(keep_dims=True),
  1308. 'desc_const': [0],
  1309. 'desc_inputs': [[3, 2]],
  1310. 'desc_bprop': [[1, 2]]}),
  1311. ('ReduceSum_5', {
  1312. 'block': P.ReduceSum(keep_dims=True),
  1313. 'desc_inputs': [[2, 3, 4]],
  1314. 'desc_bprop': [[1, 1, 1]]}),
  1315. ('ReduceSum_6', {
  1316. 'block': P.ReduceSum(),
  1317. 'desc_inputs': [[2, 3, 4]],
  1318. 'desc_bprop': [[1]]}),
  1319. ('Sum_0', {
  1320. 'block': P.ReduceSum(),
  1321. 'desc_const': [(1,)],
  1322. 'desc_inputs': [[3, 2]],
  1323. 'desc_bprop': [[3]]}),
  1324. ('Sum_1', {
  1325. 'block': P.ReduceSum(keep_dims=True),
  1326. 'desc_const': [(1,)],
  1327. 'desc_inputs': [[3, 2]],
  1328. 'desc_bprop': [[3, 1]]}),
  1329. ('Sum_2', {
  1330. 'block': P.ReduceSum(),
  1331. 'desc_const': [(0, 1)],
  1332. 'desc_inputs': [[3, 2]],
  1333. 'desc_bprop': [[1]]}),
  1334. ('Sum_3', {
  1335. 'block': P.ReduceSum(),
  1336. 'desc_const': [0],
  1337. 'desc_inputs': [[3, 2]],
  1338. 'desc_bprop': [[2]]}),
  1339. ('Sum_4', {
  1340. 'block': P.ReduceSum(keep_dims=True),
  1341. 'desc_const': [0],
  1342. 'desc_inputs': [[3, 2]],
  1343. 'desc_bprop': [[1, 2]]}),
  1344. ('Sum_5', {
  1345. 'block': P.ReduceSum(keep_dims=True),
  1346. 'desc_const': [()],
  1347. 'desc_inputs': [[2, 3, 4]],
  1348. 'desc_bprop': [[1, 1, 1]]}),
  1349. ('Sum_6', {
  1350. 'block': P.ReduceSum(),
  1351. 'desc_const': [()],
  1352. 'desc_inputs': [[2, 3, 4]],
  1353. 'desc_bprop': [[1]]}),
  1354. ('Sign', {
  1355. 'block': P.Sign(),
  1356. 'desc_inputs': [[3]],
  1357. 'desc_bprop': [[3]]}),
  1358. ('Round', {
  1359. 'block': P.Round(),
  1360. 'desc_inputs': [[3]],
  1361. 'desc_bprop': [[3]]}),
  1362. ('Atan2', {
  1363. 'block': P.Atan2(),
  1364. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  1365. Tensor(np.array([1, 1]).astype(np.float32))],
  1366. 'desc_bprop': [[2]]}),
  1367. ('SquareSumAll', {
  1368. 'block': P.SquareSumAll(),
  1369. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  1370. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  1371. 'desc_bprop': [Tensor(np.array(0.1).astype(np.float32)),
  1372. Tensor(np.array(0.1).astype(np.float32))]}),
  1373. ('Cos', {
  1374. 'block': P.Cos(),
  1375. 'desc_inputs': [[2, 3]],
  1376. 'desc_bprop': [[2, 3]]}),
  1377. ('ReduceAll', {
  1378. 'block': P.ReduceAll(),
  1379. 'desc_const': [1],
  1380. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  1381. 'desc_bprop': []}),
  1382. ('ReduceAny', {
  1383. 'block': P.ReduceAny(),
  1384. 'desc_const': [1],
  1385. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  1386. 'desc_bprop': []}),
  1387. ('BesselI0e', {
  1388. 'block': P.BesselI0e(),
  1389. 'desc_inputs': [[2, 3]],
  1390. 'desc_bprop': [[2, 3]]}),
  1391. ('BesselI1e', {
  1392. 'block': P.BesselI1e(),
  1393. 'desc_inputs': [[2, 3]],
  1394. 'desc_bprop': [[2, 3]]}),
  1395. ('Atan', {
  1396. 'block': P.Atan(),
  1397. 'desc_inputs': [[2, 3]],
  1398. 'desc_bprop': [[2, 3]]}),
  1399. ('AtanGrad', {
  1400. 'block': G.AtanGrad(),
  1401. 'desc_inputs': [[2, 3], [2, 3]],
  1402. 'skip': ['backward']}),
  1403. ('Atanh', {
  1404. 'block': P.Atanh(),
  1405. 'desc_inputs': [[2, 3]],
  1406. 'desc_bprop': [[2, 3]]}),
  1407. ('Cosh', {
  1408. 'block': P.Cosh(),
  1409. 'desc_inputs': [[3, 4, 5]],
  1410. 'desc_bprop': [[3, 4, 5]]}),
  1411. ('Sinh', {
  1412. 'block': P.Sinh(),
  1413. 'desc_inputs': [[3, 4, 5]],
  1414. 'desc_bprop': [[3, 4, 5]]}),
  1415. ('Inv', {
  1416. 'block': P.Inv(),
  1417. 'desc_inputs': [[21, 9, 12, 5]],
  1418. 'desc_bprop': [[21, 9, 12, 5]]}),
  1419. ('Invert', {
  1420. 'block': P.Invert(),
  1421. 'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
  1422. 'desc_bprop': [],
  1423. 'skip': ['backward']}),
  1424. ('HistogramFixedWidth', {
  1425. 'block': P.HistogramFixedWidth(5),
  1426. 'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
  1427. 'desc_bprop': [],
  1428. 'skip': ['backward']}),
  1429. ('Mod', {
  1430. 'block': P.Mod(),
  1431. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1432. 'desc_bprop': [[2, 3, 4, 5]]}),
  1433. ('IFMR', {
  1434. 'block': Q.IFMR(min_percentile=0.2, max_percentile=0.9, search_range=(1.0, 2.0),
  1435. search_step=1.0, with_offset=False),
  1436. 'desc_inputs': [[3, 4, 5], Tensor([0.1], mstype.float32), Tensor([0.9], mstype.float32),
  1437. Tensor(np.random.rand(4).astype(np.int32))],
  1438. 'desc_bprop': [],
  1439. 'skip': ['backward']}),
  1440. ('Erfinv', {
  1441. 'block': P.Erfinv(),
  1442. 'desc_inputs': [Tensor(np.array([0.1, 0.1, 0.1]).astype(np.float16))],
  1443. 'desc_bprop': [Tensor(np.array([1, 1, 1]).astype(np.float16))]}),
  1444. ('IndexAdd', {
  1445. 'block': IndexAdd(1),
  1446. 'desc_inputs': (Tensor(np.array([0, 1, 2]).astype(np.int32)),
  1447. Tensor(np.array([[0.5, 1.0, 1.5], [1.0, 1.5, 2.0], [2.0, 2.5, 3.0]]).astype(np.float32))),
  1448. 'desc_bprop': [Tensor(np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]).astype(np.float32))]}),
  1449. ]
  1450. test_case_nn_ops = [
  1451. ('BiasAdd', {
  1452. 'block': P.BiasAdd(),
  1453. 'desc_inputs': [[1, 3, 3, 3], [3]],
  1454. 'desc_bprop': [[1, 3, 3, 3]]}),
  1455. ('BiasAddGrad', {
  1456. 'block': G.BiasAddGrad(),
  1457. 'desc_inputs': [[1, 3, 3, 3]],
  1458. 'skip': ['backward']}),
  1459. ('GeLU', {
  1460. 'block': P.GeLU(),
  1461. 'desc_inputs': [[1, 3, 4, 4]],
  1462. 'desc_bprop': [[1, 3, 4, 4]]}),
  1463. ('GeLUGrad', {
  1464. 'block': G.GeLUGrad(),
  1465. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1466. 'desc_bprop': [[2, 2]],
  1467. 'skip': ['backward']}),
  1468. ('Tanh', {
  1469. 'block': P.Tanh(),
  1470. 'desc_inputs': [[1, 3, 4, 4]],
  1471. 'desc_bprop': [[1, 3, 4, 4]]}),
  1472. ('TanhGrad', {
  1473. 'block': G.TanhGrad(),
  1474. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1475. 'desc_bprop': [[1, 3, 4, 4]],
  1476. 'skip': ['backward']}),
  1477. ('ReLU', {
  1478. 'block': P.ReLU(),
  1479. 'desc_inputs': [[1, 3, 4, 4]],
  1480. 'desc_bprop': [[1, 3, 4, 4]]}),
  1481. ('ReLU6', {
  1482. 'block': P.ReLU6(),
  1483. 'desc_inputs': [[1, 3, 4, 4]],
  1484. 'desc_bprop': [[1, 3, 4, 4]]}),
  1485. ('ReLUV2', {
  1486. 'block': P.ReLUV2(),
  1487. 'desc_inputs': [[1, 3, 4, 4]],
  1488. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  1489. ('ReLUGrad', {
  1490. 'block': G.ReluGrad(),
  1491. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1492. 'skip': ['backward']}),
  1493. ('Softplus', {
  1494. 'block': P.Softplus(),
  1495. 'desc_inputs': [[1, 3, 4, 4]],
  1496. 'desc_bprop': [[1, 3, 4, 4]]}),
  1497. ('SoftplusGrad', {
  1498. 'block': G.SoftplusGrad(),
  1499. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1500. 'skip': ['backward']}),
  1501. ('Elu', {
  1502. 'block': P.Elu(),
  1503. 'desc_inputs': [[2, 3, 4]],
  1504. 'desc_bprop': [[2, 3, 4]]}),
  1505. ('EluGrad', {
  1506. 'block': G.EluGrad(),
  1507. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  1508. 'desc_bprop': [[2, 3, 4]],
  1509. 'skip': ['backward']}),
  1510. ('Sigmoid', {
  1511. 'block': P.Sigmoid(),
  1512. 'desc_inputs': [[1, 3, 4, 4]],
  1513. 'desc_bprop': [[1, 3, 4, 4]]}),
  1514. ('MaxPool', {
  1515. 'block': P.MaxPool(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1516. 'desc_inputs': [[100, 3, 28, 28]],
  1517. 'desc_bprop': [[100, 3, 14, 14]]}),
  1518. ('MaxPoolGrad', {
  1519. 'block': G.MaxPoolGrad(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1520. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  1521. 'desc_bprop': [[3, 4, 6, 6]],
  1522. 'skip': ['backward']}),
  1523. ('MaxPool3D', {
  1524. 'block': P.MaxPool3D(kernel_size=2, strides=2, pad_mode="VALID"),
  1525. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1526. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1527. ('MaxPool3D', {
  1528. 'block': P.MaxPool3D(kernel_size=4, strides=2, pad_mode="PAD", pad_list=2, ceil_mode=False),
  1529. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1530. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1531. ('MaxPool3D', {
  1532. 'block': P.MaxPool3D(kernel_size=4, strides=2, pad_mode="PAD", pad_list=2, ceil_mode=True),
  1533. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1534. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1535. ('MaxPool3DGrad', {
  1536. 'block': G.MaxPool3DGrad(kernel_size=2, strides=2, pad_mode="VALID"),
  1537. 'desc_inputs': [[3, 4, 6, 6, 6], [3, 4, 3, 3, 3], [3, 4, 3, 3, 3]],
  1538. 'desc_bprop': [[3, 4, 6, 6, 6]]}),
  1539. ('AvgPool', {
  1540. 'block': P.AvgPool(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1541. 'desc_inputs': [[100, 3, 28, 28]],
  1542. 'desc_bprop': [[100, 3, 14, 14]]}),
  1543. ('AvgPool3D_1', {
  1544. 'block': P.AvgPool3D(kernel_size=2, strides=2, pad_mode="VALID"),
  1545. 'desc_inputs': [[10, 3, 28, 28, 28]],
  1546. 'desc_bprop': [[10, 3, 14, 14, 14]]}),
  1547. ('AvgPool3D_2', {
  1548. 'block': P.AvgPool3D(kernel_size=3, strides=2, pad_mode="PAD", pad=1),
  1549. 'desc_inputs': [[10, 3, 28, 31, 24]],
  1550. 'desc_bprop': [[10, 3, 14, 16, 12]]}),
  1551. ('MaxPoolWithArgmax', {
  1552. 'block': P.MaxPoolWithArgmax(kernel_size=2, strides=2),
  1553. 'desc_inputs': [[128, 32, 32, 64]],
  1554. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 16, 32], {'dtype': np.int32})]}),
  1555. ('SoftmaxCrossEntropyWithLogits', {
  1556. 'block': P.SoftmaxCrossEntropyWithLogits(),
  1557. 'desc_inputs': [[1, 10], [1, 10]],
  1558. 'desc_bprop': [[1], [1, 10]],
  1559. 'skip': ['backward_exec']}),
  1560. ('Flatten', {
  1561. 'block': P.Flatten(),
  1562. 'desc_inputs': [[128, 32, 32, 64]],
  1563. 'desc_bprop': [[128, 65536]]}),
  1564. ('LogSoftmax', {
  1565. 'block': P.LogSoftmax(),
  1566. 'desc_inputs': [[64, 2]],
  1567. 'desc_bprop': [[64, 2]]}),
  1568. ('LogSoftmaxGrad', {
  1569. 'block': G.LogSoftmaxGrad(),
  1570. 'desc_inputs': [[16, 1234], [16, 1234]],
  1571. 'desc_bprop': [[64, 2]],
  1572. 'skip': ['backward']}),
  1573. ('L2Normalize', {
  1574. 'block': P.L2Normalize(),
  1575. 'desc_inputs': [[2, 2]],
  1576. 'desc_bprop': [[2, 2]]}),
  1577. ('L2NormalizeGrad', {
  1578. 'block': G.L2NormalizeGrad(),
  1579. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1580. 'desc_bprop': [[2, 2]],
  1581. 'skip': ['backward']}),
  1582. ('LayerNorm', {
  1583. 'block': P.LayerNorm(),
  1584. 'desc_inputs': [[2, 16], [16], [16]],
  1585. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  1586. ('LayerNormGrad', {
  1587. 'block': G.LayerNormGrad(),
  1588. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  1589. 'desc_bprop': [[2, 16], [16], [16]],
  1590. 'skip': ['backward']}),
  1591. ('BatchNorm', {
  1592. 'block': P.BatchNorm(),
  1593. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1594. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1595. 'skip': []}),
  1596. ('BatchNormGrad', {
  1597. 'block': G.BatchNormGrad(),
  1598. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64], [64]],
  1599. 'desc_bprop': [[128, 64, 32, 32], [64], [64]],
  1600. 'skip': ['backward']}),
  1601. ('SyncBatchNorm', {
  1602. 'block': inner.SyncBatchNorm(),
  1603. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1604. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1605. 'skip': []}),
  1606. ('SyncBatchNormGrad', {
  1607. 'block': G.SyncBatchNormGrad(),
  1608. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  1609. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1610. 'skip': ['backward']}),
  1611. ('TopK', {
  1612. 'block': P.TopK(),
  1613. 'desc_const': [5],
  1614. 'desc_inputs': [[20, 20, 10]],
  1615. 'desc_bprop': [[20, 20, 5]],
  1616. 'skip': ['backward']}),
  1617. ('Sort', {
  1618. 'block': P.Sort(),
  1619. 'desc_inputs': [[2, 3, 4]],
  1620. 'desc_bprop': [[2, 3, 4], ([2, 3, 4], {'dtype': np.int32})]}),
  1621. ('GatherV2_0', {
  1622. 'block': P.Gather(),
  1623. 'desc_const': [0],
  1624. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1625. 'desc_bprop': [[2, 1, 2]]}),
  1626. ('GatherV2_1', {
  1627. 'block': P.Gather(),
  1628. 'desc_const': [2],
  1629. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1630. 'desc_bprop': [[3, 1, 2]]}),
  1631. ('GatherV2_2', {
  1632. 'block': P.Gather(),
  1633. 'desc_const': [0],
  1634. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1635. 'desc_bprop': [[3, 2, 1, 3]]}),
  1636. ('GatherV2_3', {
  1637. 'block': P.Gather(),
  1638. 'desc_const': [2],
  1639. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1640. 'desc_bprop': [[3, 1, 3, 2]]}),
  1641. ('GatherV2_4', {
  1642. 'block': P.Gather(),
  1643. 'desc_const': [1],
  1644. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  1645. 'desc_bprop': [[32, 1, 1024]]}),
  1646. ('GatherV2_5', {
  1647. 'block': P.Gather(),
  1648. 'desc_const': [-1],
  1649. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1650. 'desc_bprop': [[3, 1, 2]]}),
  1651. ('GatherV2_6', {
  1652. 'block': P.Gather(),
  1653. 'desc_const': [0],
  1654. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  1655. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  1656. ('SparseGatherV2_0', {
  1657. 'block': P.SparseGatherV2(),
  1658. 'desc_const': [0],
  1659. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1660. 'desc_bprop': [[2, 1, 2]]}),
  1661. ('Range', {
  1662. 'block': inner.Range(1.0, 5.0),
  1663. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  1664. 'desc_bprop': [[10]]}),
  1665. ('UnsortedSegmentSum', {
  1666. 'block': P.UnsortedSegmentSum(),
  1667. 'desc_const': [1280],
  1668. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  1669. 'desc_bprop': [[1280, 1024]]}),
  1670. ('UnsortedSegmentSum_1', {
  1671. 'block': P.UnsortedSegmentSum(),
  1672. 'desc_const': [4],
  1673. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1674. 'desc_bprop': [[4, 1, 3]]}),
  1675. ('UnsortedSegmentMin', {
  1676. 'block': P.UnsortedSegmentMin(),
  1677. 'desc_const': [4],
  1678. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1679. 'desc_bprop': [[4, 2, 1, 3]]}),
  1680. ('UnsortedSegmentMax', {
  1681. 'block': P.UnsortedSegmentMax(),
  1682. 'desc_const': [4],
  1683. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1684. 'desc_bprop': [[4, 2, 1, 3]]}),
  1685. ('UnsortedSegmentProd', {
  1686. 'block': P.UnsortedSegmentProd(),
  1687. 'desc_const': [4],
  1688. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([0, 1, 0]).astype(np.int32))],
  1689. 'desc_bprop': [[4, 2, 1, 3]]}),
  1690. ('DropoutGenMask', {
  1691. 'block': P.DropoutGenMask(),
  1692. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  1693. 'desc_inputs': [],
  1694. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  1695. 'skip': ['backward']}),
  1696. ('DropoutDoMask', {
  1697. 'block': P.DropoutDoMask(),
  1698. 'desc_const': [Tensor(0.5)],
  1699. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  1700. 'desc_bprop': [[64, 12, 128, 128]]}),
  1701. ('Dropout', {
  1702. 'block': nn.Dropout(0.5),
  1703. 'desc_inputs': [[64, 12, 128, 128]],
  1704. 'desc_bprop': [[64, 12, 128, 128]]}),
  1705. ('ReduceMean0', {
  1706. 'block': P.ReduceMean(),
  1707. 'desc_const': [(2,)],
  1708. 'desc_inputs': [[3, 2, 2]],
  1709. 'desc_bprop': [[3, 2]]}),
  1710. ('ReduceMean1', {
  1711. 'block': P.ReduceMean(),
  1712. 'desc_const': [2],
  1713. 'desc_inputs': [[3, 2, 2]],
  1714. 'desc_bprop': [[3, 2]]}),
  1715. ('All', {
  1716. 'block': P.ReduceAll(),
  1717. 'desc_const': [(1,)],
  1718. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  1719. 'desc_bprop': [[3]],
  1720. 'skip': ['backward']}),
  1721. ('DescConst', {
  1722. 'block': Tensor(np.array([2], np.float32)),
  1723. 'desc_inputs': [],
  1724. 'desc_bprop': [[1]],
  1725. 'skip': ['backward'],
  1726. 'add_fake_input': True}),
  1727. ('Fill', {
  1728. 'block': P.Fill(),
  1729. 'desc_const': [mstype.float32, (2, 3), 1.0],
  1730. 'desc_inputs': [],
  1731. 'desc_bprop': [[2, 3]],
  1732. 'skip': ['backward'],
  1733. 'add_fake_input': True}),
  1734. ('OnesLike', {
  1735. 'block': P.OnesLike(),
  1736. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1737. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1738. }),
  1739. ('ZerosLike', {
  1740. 'block': P.ZerosLike(),
  1741. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1742. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1743. }),
  1744. ('Softmax', {
  1745. 'block': P.Softmax(),
  1746. 'desc_inputs': [[5, 5]],
  1747. 'desc_bprop': [[5, 5]]}),
  1748. ('Softsign', {
  1749. 'block': P.Softsign(),
  1750. 'desc_inputs': [[5, 5]],
  1751. 'desc_bprop': [[5, 5]]}),
  1752. ('DepthwiseConv2dNative_1', {
  1753. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  1754. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  1755. 'desc_bprop': [[10, 32, 16, 16]]}),
  1756. ('DepthwiseConv2dNative_2', {
  1757. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  1758. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  1759. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  1760. ('SigmoidCrossEntropyWithLogits', {
  1761. 'block': P.SigmoidCrossEntropyWithLogits(),
  1762. 'desc_inputs': [[128, 10], [128, 10]],
  1763. 'desc_bprop': [[128, 10]]}),
  1764. ('Pad', {
  1765. 'block': P.Pad(((1, 2), (2, 3))),
  1766. 'desc_inputs': [[7, 7]],
  1767. 'desc_bprop': [[10, 12]]}),
  1768. ('BinaryCrossEntropy', {
  1769. 'block': P.BinaryCrossEntropy(),
  1770. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  1771. 'desc_bprop': []}),
  1772. ('SparseApplyAdagrad', {
  1773. 'block': SparseApplyAdagradNet(),
  1774. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1775. 'desc_bprop': [[3, 3], [3, 3]],
  1776. 'skip': ['backward']}),
  1777. ('SparseApplyAdagradV2', {
  1778. 'block': SparseApplyAdagradV2Net(),
  1779. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1780. 'skip': ['backward']}),
  1781. ('SparseApplyFtrl', {
  1782. 'block': SparseApplyFtrlNet(),
  1783. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1784. 'skip': ['backward']}),
  1785. ('SparseApplyFtrlV2', {
  1786. 'block': SparseApplyFtrlV2Net(),
  1787. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1788. 'skip': ['backward']}),
  1789. ('ApplyProximalAdagrad', {
  1790. 'block': ApplyProximalAdagradNet(),
  1791. 'desc_inputs': [[3, 3]],
  1792. 'skip': ['backward']}),
  1793. ('SparseApplyProximalAdagrad', {
  1794. 'block': SparseApplyProximalAdagradNet(),
  1795. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1796. 'skip': ['backward']}),
  1797. ('ApplyAdaMax', {
  1798. 'block': ApplyAdaMaxNet(),
  1799. 'desc_inputs': [[3, 3]],
  1800. 'skip': ['backward']}),
  1801. ('ApplyAdadelta', {
  1802. 'block': ApplyAdadeltaNet(),
  1803. 'desc_inputs': [[3, 3]],
  1804. 'skip': ['backward']}),
  1805. ('ApplyAdagrad', {
  1806. 'block': ApplyAdagradNet(),
  1807. 'desc_inputs': [[3, 3]],
  1808. 'skip': ['backward']}),
  1809. ('ApplyAdagradV2', {
  1810. 'block': ApplyAdagradV2Net(),
  1811. 'desc_inputs': [[3, 3]],
  1812. 'skip': ['backward']}),
  1813. ('ApplyAddSign', {
  1814. 'block': ApplyAddSignNet(),
  1815. 'desc_inputs': [[3, 3]],
  1816. 'skip': ['backward']}),
  1817. ('ApplyPowerSign', {
  1818. 'block': ApplyPowerSignNet(),
  1819. 'desc_inputs': [[3, 3]],
  1820. 'skip': ['backward']}),
  1821. ('ApplyGradientDescent', {
  1822. 'block': ApplyGradientDescentNet(),
  1823. 'desc_inputs': [[3, 3]],
  1824. 'skip': ['backward']}),
  1825. ('ApplyProximalGradientDescent', {
  1826. 'block': ApplyProximalGradientDescentNet(),
  1827. 'desc_inputs': [[3, 3]],
  1828. 'skip': ['backward']}),
  1829. ('Flatten_1', {
  1830. 'block': NetForFlatten(),
  1831. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1832. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1833. 'skip': ['backward']}),
  1834. ('Flatten_2', {
  1835. 'block': NetForFlatten(),
  1836. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  1837. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  1838. 'skip': ['backward']}),
  1839. ('Flatten_3', {
  1840. 'block': NetForFlattenComposed(),
  1841. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1842. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1843. 'skip': []}),
  1844. ('ArgmaxNet', {
  1845. 'block': ArgmaxNet(),
  1846. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1847. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1848. 'skip': ['backward']}),
  1849. ('ArgminNet', {
  1850. 'block': ArgminNet(),
  1851. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1852. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1853. 'skip': ['backward']}),
  1854. ('StridedSliceNet', {
  1855. 'block': StridedSliceNet(),
  1856. 'desc_inputs': [[6, 7, 8, 9, 10]],
  1857. 'skip': ['backward']}),
  1858. ('OneHot', {
  1859. 'block': P.OneHot(),
  1860. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  1861. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  1862. 'desc_bprop': [[1, 3]]}),
  1863. ('ReduceProd_0', {
  1864. 'block': P.ReduceProd(),
  1865. 'desc_const': [0],
  1866. 'desc_inputs': [[3, 2]],
  1867. 'desc_bprop': [[2]]}),
  1868. ('ReduceProd_1', {
  1869. 'block': P.ReduceProd(keep_dims=True),
  1870. 'desc_const': [0],
  1871. 'desc_inputs': [[3, 2]],
  1872. 'desc_bprop': [[1, 2]]}),
  1873. ('CumProd', {
  1874. 'block': P.CumProd(),
  1875. 'desc_const': [0],
  1876. 'desc_inputs': [[3, 2]],
  1877. 'desc_bprop': [[3, 2]]}),
  1878. ('ApplyFtrl', {
  1879. 'block': ApplyFtrlNet(),
  1880. 'desc_inputs': [[3, 3]],
  1881. 'desc_bprop': [3, 3],
  1882. 'skip': ['backward']}),
  1883. ('ApplyRMSProp', {
  1884. 'block': ApplyRMSNet(),
  1885. 'desc_inputs': [[3, 3]],
  1886. 'desc_bprop': [3, 3],
  1887. 'skip': ['backward']}),
  1888. ('ApplyCenteredRMSProp', {
  1889. 'block': P.ApplyCenteredRMSProp(),
  1890. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  1891. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  1892. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  1893. 'desc_bprop': [1],
  1894. 'skip': ['backward']}),
  1895. ('CTCLoss', {
  1896. 'block': P.CTCLoss(),
  1897. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  1898. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  1899. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  1900. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  1901. 'desc_bprop': [[4], [6, 4, 6]]}),
  1902. ('CTCGreedyDecoder', {
  1903. 'block': CTCGreedyDecoderNet(),
  1904. 'desc_inputs': [[2, 2, 3], Tensor(np.array([2, 2]).astype(np.int32))],
  1905. 'skip': ['backward']}),
  1906. ('L2Loss_1', {
  1907. 'block': P.L2Loss(),
  1908. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  1909. 'desc_bprop': []}),
  1910. ('L2Loss_2', {
  1911. 'block': P.L2Loss(),
  1912. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  1913. 'desc_bprop': []}),
  1914. ('SoftMarginLoss', {
  1915. 'block': P.SoftMarginLoss(reduction="none"),
  1916. 'desc_inputs': [Tensor(np.array([[0.3, 0.7], [0.5, 0.5]]).astype(np.float32)),
  1917. Tensor(np.array([[-1, 1], [1, -1]]).astype(np.float32))],
  1918. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.float32))]}),
  1919. ('BCEWithLogitsLoss', {
  1920. 'block': P.BCEWithLogitsLoss(),
  1921. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1922. 'desc_bprop': []}),
  1923. ('ResizeBilinear', {
  1924. 'block': P.ResizeBilinear((5, 5)),
  1925. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  1926. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  1927. ('ResizeBilinearGrad', {
  1928. 'block': G.ResizeBilinearGrad(),
  1929. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1930. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1931. 'skip': ['backward']}),
  1932. ('ROIAlign', {
  1933. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  1934. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  1935. 'desc_bprop': [[1024, 256, 7, 7]]}),
  1936. ('ROIAlignGrad', {
  1937. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  1938. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  1939. 'desc_bprop': [[1, 1, 2, 2]],
  1940. 'skip': ['backward']}),
  1941. ('LARSUpdate', {
  1942. 'block': P.LARSUpdate(1e-05, 0.001, False),
  1943. 'desc_const': [0.0, 0.001],
  1944. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1945. 'desc_bprop': [3, 3],
  1946. 'skip': ['backward']}),
  1947. ('SGD', {
  1948. 'block': P.SGD(0.0, 0.0, False),
  1949. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  1950. 'desc_bprop': [3, 3],
  1951. 'skip': ['backward']}),
  1952. ('BinaryCrossEntropy', {
  1953. 'block': P.BinaryCrossEntropy(),
  1954. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1955. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1956. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1957. 'desc_bprop': []}),
  1958. ('BinaryCrossEntropyGrad', {
  1959. 'block': G.BinaryCrossEntropyGrad(),
  1960. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1961. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1962. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1963. 'desc_bprop': [],
  1964. 'skip': ['backward']}),
  1965. ('DataFormatDimMap', {
  1966. 'block': P.DataFormatDimMap(),
  1967. 'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
  1968. 'desc_bprop': [],
  1969. 'skip': ['backward']}),
  1970. ('MaxPoolGradGrad', {
  1971. 'block': G.MaxPoolGradGrad(),
  1972. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1973. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1974. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16)],
  1975. 'desc_bprop': [],
  1976. 'skip': ['backward']}),
  1977. ('MaxPoolGradGradWithArgmax', {
  1978. 'block': G.MaxPoolGradGradWithArgmax(),
  1979. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1980. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1981. Tensor(np.zeros((1, 1, 2, 2)), mstype.uint16)],
  1982. 'desc_bprop': [],
  1983. 'skip': ['backward']}),
  1984. ('Roll', {
  1985. 'block': nn.Roll(shift=[1, -2], axis=[0, 1]),
  1986. 'desc_inputs': [Tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]], mstype.float32)],
  1987. 'desc_bprop': [Tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]], mstype.float32)]}),
  1988. ('SoftShrink', {
  1989. 'block': P.SoftShrink(),
  1990. 'desc_inputs': [Tensor(np.array([[0.5297, 0.7871, 1.1754], [0.7836, 0.6218, -1.1542]]), mstype.float32)],
  1991. 'desc_bprop': [Tensor(np.array([[0, 0.4, 1], [1, 2, 4]]), mstype.float32)]}),
  1992. ('SoftShrinkGrad', {
  1993. 'block': G.SoftShrinkGrad(),
  1994. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  1995. Tensor(np.array([[-3, -2, 0], [1, 2, 4]]), mstype.float16)],
  1996. 'desc_bprop': [],
  1997. 'skip': ['backward']}),
  1998. ('HSigmoidGrad', {
  1999. 'block': G.HSigmoidGrad(),
  2000. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  2001. Tensor(np.array([[-4, -3, -2], [1, 2, 4]]), mstype.float16)],
  2002. 'skip': ['backward']}),
  2003. ('HSigmoid', {
  2004. 'block': P.HSigmoid(),
  2005. 'desc_inputs': [Tensor(np.array([[-4, 4, 1]]), mstype.float32)],
  2006. 'desc_bprop': [Tensor(np.array([[0, 1, 0.6666]]), mstype.float32)],
  2007. 'skip': ['backward']}),
  2008. ('HardShrink', {
  2009. 'block': P.HShrink(),
  2010. 'desc_inputs': [Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mstype.float32)],
  2011. 'desc_bprop': [],
  2012. 'skip': ['backward']}),
  2013. ('HShrinkGrad', {
  2014. 'block': G.HShrinkGrad(),
  2015. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  2016. Tensor(np.array([[-4, -3, -2], [1, 2, 4]]), mstype.float16)],
  2017. 'skip': ['backward']}),
  2018. ('ApplyAdagradDA', {
  2019. 'block': ApplyAdagradDANet(),
  2020. 'desc_inputs': [Tensor(np.array([[0.3, 0.4], [0.1, 0.2]]).astype(np.float32)),
  2021. Tensor(0.001, mstype.float32),
  2022. Tensor(0.001, mstype.float32),
  2023. Tensor(0.001, mstype.float32),
  2024. Tensor(2, mstype.int32)],
  2025. 'skip': ['backward']}),
  2026. ('SparseApplyRMSProp', {
  2027. 'block': SparseApplyRMSPropNet(0.2, 0.01, 1e-6),
  2028. 'desc_inputs': [Tensor(0.01, mstype.float32),
  2029. Tensor(np.array([[0.3, 0.7], [0.1, 0.8]]).astype(np.float32)),
  2030. Tensor(np.array([0, 1], dtype=np.int32))],
  2031. 'skip': ['backward']}),
  2032. ]
  2033. test_case_array_ops = [
  2034. ('SpaceToDepth', {
  2035. 'block': P.SpaceToDepth(2),
  2036. 'desc_inputs': [[1, 3, 2, 2]],
  2037. 'desc_bprop': [[1, 12, 1, 1]]}),
  2038. ('DepthToSpace', {
  2039. 'block': P.DepthToSpace(2),
  2040. 'desc_inputs': [[1, 12, 1, 1]],
  2041. 'desc_bprop': [[1, 3, 2, 2]]}),
  2042. ('Split', {
  2043. 'block': P.Split(1, 2),
  2044. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  2045. 'skip': ['backward']}),
  2046. ('Argmax', {
  2047. 'block': P.Argmax(),
  2048. 'desc_inputs': [[128, 32, 32, 64]],
  2049. 'desc_bprop': [0],
  2050. 'skip': ['backward']}),
  2051. ('Argmin', {
  2052. 'block': P.Argmin(),
  2053. 'desc_inputs': [[128, 32, 32, 64]],
  2054. 'desc_bprop': [1],
  2055. 'skip': ['backward']}),
  2056. ('ArgMaxWithValue', {
  2057. 'block': P.ArgMaxWithValue(),
  2058. 'desc_inputs': [[128, 32, 32, 64]],
  2059. 'desc_bprop': [[1], [1]],
  2060. 'skip': ['backward']}),
  2061. ('ArgMinWithValue', {
  2062. 'block': P.ArgMinWithValue(),
  2063. 'desc_inputs': [[128, 32, 32, 64]],
  2064. 'desc_bprop': [[1], [1]],
  2065. 'skip': ['backward']}),
  2066. ('Transpose_dim3', {
  2067. 'block': P.Transpose(),
  2068. 'desc_const': [(0, 2, 1)],
  2069. 'desc_inputs': [[1, 2, 3]],
  2070. 'desc_bprop': [[1, 3, 2]]}),
  2071. ('Transpose_dim4', {
  2072. 'block': P.Transpose(),
  2073. 'desc_const': [(0, 1, 2, 3)],
  2074. 'desc_inputs': [[1, 2, 3, 4]],
  2075. 'desc_bprop': [[1, 2, 4, 3]]}),
  2076. ('AddN', {
  2077. 'block': NetForTupleInput(P.AddN()),
  2078. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  2079. 'desc_bprop': [[2, 3, 3, 5]]}),
  2080. ('AccumulateNV2', {
  2081. 'block': NetForTupleInput(P.AccumulateNV2()),
  2082. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  2083. 'desc_bprop': [[2, 3, 3, 5]]}),
  2084. ('Shape', {
  2085. 'block': P.Shape(),
  2086. 'desc_inputs': [[3, 3, 2, 2]],
  2087. 'skip': ['backward']}),
  2088. ('Reshape', {
  2089. 'block': P.Reshape(),
  2090. 'desc_const': [(64,)],
  2091. 'desc_inputs': [[64, 1]],
  2092. 'desc_bprop': [[64]]}),
  2093. ('Cast', {
  2094. 'block': P.Cast(),
  2095. 'desc_const': [mstype.int32],
  2096. 'desc_inputs': [[2, 3, 4, 5]],
  2097. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  2098. ('ExpandDims', {
  2099. 'block': P.ExpandDims(),
  2100. 'desc_const': [0],
  2101. 'desc_inputs': [[2, 2]],
  2102. 'desc_bprop': [[1, 2, 2]]}),
  2103. ('ExpandDims_1', {
  2104. 'block': P.ExpandDims(),
  2105. 'desc_const': [-1],
  2106. 'desc_inputs': [[2, 2]],
  2107. 'desc_bprop': [[2, 2, 1]]}),
  2108. ('Squeeze', {
  2109. 'block': P.Squeeze(2),
  2110. 'desc_inputs': [[3, 2, 1]],
  2111. 'desc_bprop': [[3, 2]]}),
  2112. ('Squeeze_0', {
  2113. 'block': P.Squeeze(),
  2114. 'desc_inputs': [[3, 1, 2, 1]],
  2115. 'desc_bprop': [[3, 2]]}),
  2116. ('Squeeze_1', {
  2117. 'block': P.Squeeze(),
  2118. 'desc_inputs': [[1, 1, 1, 1]],
  2119. 'desc_bprop': [1.0],
  2120. 'skip': ['backward']}),
  2121. ('Squeeze_2', {
  2122. 'block': P.Squeeze((2, 3)),
  2123. 'desc_inputs': [[3, 2, 1, 1]],
  2124. 'desc_bprop': [[3, 2]]}),
  2125. ('Size', {
  2126. 'block': P.Size(),
  2127. 'desc_inputs': [[2, 3, 5]],
  2128. 'skip': ['backward']}),
  2129. ('Tile_0', {
  2130. 'block': P.Tile(),
  2131. 'desc_const': [(1, 2)],
  2132. 'desc_inputs': [[64, 1]],
  2133. 'desc_bprop': [[64, 2]]}),
  2134. ('Tile_1', {
  2135. 'block': P.Tile(),
  2136. 'desc_const': [(1, 1)],
  2137. 'desc_inputs': [[64, 1]],
  2138. 'desc_bprop': [[64, 1]]}),
  2139. ('Tile_2', {
  2140. 'block': P.Tile(),
  2141. 'desc_const': [(2, 1, 1, 2)],
  2142. 'desc_inputs': [[2, 2, 2]],
  2143. 'desc_bprop': [[2, 2, 2, 4]]}),
  2144. ('ReverseV2', {
  2145. 'block': P.ReverseV2(axis=[1]),
  2146. 'desc_inputs': [(Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)))],
  2147. 'desc_bprop': [(Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)))]}),
  2148. ('Rint', {
  2149. 'block': P.Rint(),
  2150. 'desc_inputs': [(Tensor(np.array([-1.6, -0.1, 1.5, 2.0]).astype(np.float32)))],
  2151. 'skip': ['backward']}),
  2152. ('ConcatV2_0', {
  2153. 'block': NetForConcat1(),
  2154. 'desc_inputs': [
  2155. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  2156. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  2157. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  2158. ('ConcatV2_1', {
  2159. 'block': NetForConcat2(),
  2160. 'desc_inputs': [Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  2161. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32))],
  2162. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  2163. ('ConcatV2_2', {
  2164. 'block': NetForConcat(),
  2165. 'desc_inputs': [[2, 2]],
  2166. 'desc_bprop': [[4, 2]]}),
  2167. ('ConcatV2_3', {
  2168. 'block': NetForConcat1(),
  2169. 'desc_inputs': [[2, 2], [2, 2]],
  2170. 'desc_bprop': [[4, 2]]}),
  2171. ('ConcatV2_4', {
  2172. 'block': NetForConcat3(),
  2173. 'desc_inputs': [
  2174. Tensor(np.ones((3, 2, 3), np.float32)),
  2175. Tensor(np.ones((5, 2, 3), np.float32)),
  2176. Tensor(np.ones((6, 2, 3), np.float32))],
  2177. 'desc_bprop': [[14, 2, 3]]}),
  2178. ('ConcatV2_5', {
  2179. 'block': NetForConcat4(),
  2180. 'desc_inputs': [Tensor(np.array([1], np.float32)),
  2181. Tensor(np.array([1], np.float32)),
  2182. Tensor(np.array([1], np.float32))],
  2183. 'desc_bprop': [[3,]]}),
  2184. ('Stack_0', {
  2185. 'block': NetForStackInput(P.Stack()),
  2186. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  2187. 'desc_bprop': [[3, 2, 2]],
  2188. }),
  2189. ('Stack_1', {
  2190. 'block': NetForStackInput(P.Stack(axis=-2)),
  2191. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  2192. 'desc_bprop': [[3, 2, 3, 3]],
  2193. }),
  2194. ('Stack_2', {
  2195. 'block': NetForStackInput(P.Stack()),
  2196. 'desc_inputs': [[128, 128], [128, 128]],
  2197. 'desc_bprop': [[2, 128, 128]],
  2198. }),
  2199. ('Stack_3', {
  2200. 'block': NetForStackInput(P.Stack()),
  2201. 'desc_inputs': [[2, 2]],
  2202. 'desc_bprop': [[1, 2, 2]]}),
  2203. ('Unpack_0', {
  2204. 'block': NetForUnpackInput(P.Unstack(axis=0)),
  2205. 'desc_inputs': [[2, 4]],
  2206. 'desc_bprop': [[4], [4]],
  2207. }),
  2208. ('Unpack_1', {
  2209. 'block': NetForUnpackInput(P.Unstack(axis=-1)),
  2210. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  2211. 'desc_bprop': [[1], [1], [1]],
  2212. }),
  2213. ('Diag_1', {
  2214. 'block': P.Diag(),
  2215. 'desc_inputs': [[4]],
  2216. 'desc_bprop': [[4, 4]],
  2217. }),
  2218. ('Diag_2', {
  2219. 'block': P.Diag(),
  2220. 'desc_inputs': [[4, 4]],
  2221. 'desc_bprop': [[4, 4, 4, 4]],
  2222. }),
  2223. ('DiagPart_1', {
  2224. 'block': P.DiagPart(),
  2225. 'desc_inputs': [[4, 4]],
  2226. 'desc_bprop': [[4]],
  2227. }),
  2228. ('DiagPart_2', {
  2229. 'block': P.DiagPart(),
  2230. 'desc_inputs': [[4, 4, 4, 4]],
  2231. 'desc_bprop': [[4, 4]],
  2232. }),
  2233. ('SpaceToBatch_1', {
  2234. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  2235. 'desc_inputs': [[1, 3, 2, 2]],
  2236. 'desc_bprop': [[4, 3, 1, 1]],
  2237. }),
  2238. ('SpaceToBatch_2', {
  2239. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  2240. 'desc_inputs': [[1, 3, 2, 2]],
  2241. 'desc_bprop': [[4, 3, 2, 3]],
  2242. }),
  2243. ('BatchToSpace_1', {
  2244. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  2245. 'desc_inputs': [[4, 3, 1, 1]],
  2246. 'desc_bprop': [[1, 3, 2, 2]],
  2247. }),
  2248. ('BatchToSpace_2', {
  2249. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  2250. 'desc_inputs': [[4, 3, 1, 1]],
  2251. 'desc_bprop': [[1, 3, 2, 1]],
  2252. }),
  2253. ('UnsortedSegmentMin_1', {
  2254. 'block': P.UnsortedSegmentMin(),
  2255. 'desc_const': [2],
  2256. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  2257. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  2258. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  2259. ('BroadcastTo', {
  2260. 'block': P.BroadcastTo((2, 3)),
  2261. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
  2262. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
  2263. ('InTopK', {
  2264. 'block': P.InTopK(2),
  2265. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
  2266. Tensor(np.array([2, 1, 2]).astype(np.int32))],
  2267. 'skip': ['backward'],
  2268. }),
  2269. ('InplaceUpdate', {
  2270. 'block': P.InplaceUpdate((0, 2)),
  2271. 'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
  2272. Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
  2273. 'skip': ['backward'],
  2274. }),
  2275. ('ReverseSequence', {
  2276. 'block': P.ReverseSequence(1, 0),
  2277. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
  2278. Tensor(np.array([1, 2, 3]).astype(np.int32))],
  2279. 'desc_bprop': [[3, 3]]}),
  2280. ('EditDistance', {
  2281. 'block': EditDistance(Tensor(np.array([1, 1, 2]).astype(np.int64)),
  2282. Tensor(np.array([2, 2, 2]).astype(np.int64))),
  2283. 'desc_inputs': [Tensor(np.array([[0, 0, 0], [1, 0, 1], [1, 1, 1]]).astype(np.int64)),
  2284. Tensor(np.array([1, 2, 3]).astype(np.float32)),
  2285. Tensor(np.array([[0, 1, 0], [0, 0, 1], [1, 1, 0], [1, 0, 1]]).astype(np.int64)),
  2286. Tensor(np.array([1, 3, 2, 1]).astype(np.float32))],
  2287. 'skip': ['backward'],
  2288. }),
  2289. ('LinSpace', {
  2290. 'block': P.LinSpace(),
  2291. 'desc_const': [5],
  2292. 'desc_inputs': [Tensor(1, mstype.float32),
  2293. Tensor(10, mstype.float32)],
  2294. 'skip': ['backward'],
  2295. }),
  2296. ('MaskedFill', {
  2297. 'block': P.MaskedFill(),
  2298. 'desc_inputs': [Tensor(np.array([[1.0, 2.0, 3.0]]), mstype.float32),
  2299. Tensor(np.array([[True, True, False]]), mstype.bool_),
  2300. Tensor(4.0, mstype.float32)],
  2301. 'desc_bprop': [Tensor(np.array([[1.0, 2.0, 3.0]]), mstype.float32)],
  2302. }),
  2303. ('MatrixDiag', {
  2304. 'block': inner.MatrixDiag(),
  2305. 'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
  2306. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2307. 'skip': ['backward'],
  2308. }),
  2309. ('MatrixDiagPart', {
  2310. 'block': inner.MatrixDiagPart(),
  2311. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  2312. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2313. 'skip': ['backward'],
  2314. }),
  2315. ('MatrixSetDiag', {
  2316. 'block': inner.MatrixSetDiag(),
  2317. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  2318. Tensor(np.arange(6).reshape(3, 2), mstype.float32),
  2319. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2320. 'skip': ['backward'],
  2321. }),
  2322. ('TransShape', {
  2323. 'block': P.TransShape(),
  2324. 'desc_const': [(1, 12, 24, 24)],
  2325. 'desc_inputs': [[1, 3, 24, 24]],
  2326. 'desc_bprop': [[1, 12, 24, 24]],
  2327. }),
  2328. ('ParallelConcat', {
  2329. 'block': ParallelConcatNet(),
  2330. 'desc_inputs': [Tensor([[1, 2]], mstype.float32),
  2331. Tensor([[5, 6]], mstype.float32)],
  2332. 'skip': ['backward'],
  2333. }),
  2334. ('SplitV', {
  2335. 'block': P.SplitV(size_splits=[1, 2], split_dim=1, num_split=2),
  2336. 'desc_inputs': [Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])],
  2337. 'desc_bprop': [(Tensor([[1], [4], [7]]),
  2338. Tensor([[2, 3], [5, 6], [8, 9]]))],
  2339. }),
  2340. ]
  2341. test_case_other_ops = [
  2342. ('ScalarLog', {
  2343. 'block': F.scalar_log,
  2344. 'desc_const': [0.0],
  2345. 'desc_inputs': [],
  2346. 'desc_bprop': [1],
  2347. 'skip': ['backward']}),
  2348. ('BoundingBoxEncode', {
  2349. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  2350. 'desc_inputs': [[256, 4], [256, 4]],
  2351. 'desc_bprop': [[256, 4]],
  2352. 'skip': ['backward']}),
  2353. ('BoundingBoxDecode', {
  2354. '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)),
  2355. 'desc_inputs': [[256, 4], [256, 4]],
  2356. 'desc_bprop': [[256, 4]],
  2357. 'skip': ['backward']}),
  2358. ('GatherNd', {
  2359. 'block': P.GatherNd(),
  2360. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  2361. Tensor(np.ones((2, 4), np.int32))),
  2362. 'desc_bprop': [[2]]}),
  2363. ('ScatterNd', {
  2364. 'block': P.ScatterNd(),
  2365. 'desc_const': [(3, 3)],
  2366. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  2367. Tensor(np.ones((2,), np.int32))),
  2368. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  2369. ('TensorScatterUpdate', {
  2370. 'block': P.TensorScatterUpdate(),
  2371. 'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
  2372. Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2373. Tensor(np.ones([2, 5], np.float32) * 99)),
  2374. 'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
  2375. ('ScatterMaxUseLocking', {
  2376. 'block': ScatterMax(use_locking=True),
  2377. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2378. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  2379. 'skip': ['backward']}),
  2380. ('ScatterMax1d', {
  2381. 'block': ScatterMax(),
  2382. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2383. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  2384. 'skip': ['backward']}),
  2385. ('ScatterMaxF32', {
  2386. 'block': ScatterMax(),
  2387. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2388. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  2389. 'skip': ['backward']}),
  2390. ('ScatterMaxF16', {
  2391. 'block': ScatterMax(np.float16),
  2392. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2393. Tensor(np.ones([2, 2, 3], np.float16) * 99)),
  2394. 'skip': ['backward']}),
  2395. ('ScatterMaxI32', {
  2396. 'block': ScatterMax(np.int32),
  2397. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2398. Tensor(np.ones([2, 2, 3], np.int32) * 99)),
  2399. 'skip': ['backward']}),
  2400. ('ScatterMinUseLocking', {
  2401. 'block': ScatterMin(use_locking=True),
  2402. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2403. Tensor(np.ones([2, 3], np.float32))),
  2404. 'skip': ['backward']}),
  2405. ('ScatterMin1d', {
  2406. 'block': ScatterMin(),
  2407. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2408. Tensor(np.ones([2, 3], np.float32))),
  2409. 'skip': ['backward']}),
  2410. ('ScatterMinF32', {
  2411. 'block': ScatterMin(),
  2412. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2413. Tensor(np.ones([2, 2, 3], np.float32))),
  2414. 'skip': ['backward']}),
  2415. ('ScatterMinF16', {
  2416. 'block': ScatterMin(np.float16),
  2417. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2418. Tensor(np.ones([2, 2, 3], np.float16))),
  2419. 'skip': ['backward']}),
  2420. ('ScatterMinI32', {
  2421. 'block': ScatterMin(np.int32),
  2422. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2423. Tensor(np.ones([2, 2, 3], np.int32))),
  2424. 'skip': ['backward']}),
  2425. ('ScatterUpdate', {
  2426. 'block': ScatterUpdate((6,)),
  2427. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2428. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2429. 'skip': ['backward']}),
  2430. ('ScatterAddUseLocking', {
  2431. 'block': ScatterAdd((6,), use_locking=True),
  2432. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2433. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2434. 'skip': ['backward']}),
  2435. ('ScatterNonAliasingAdd_1d', {
  2436. 'block': ScatterNonAliasingAdd((8,)),
  2437. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2438. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2439. 'skip': ['backward']}),
  2440. ('ScatterNdAdd', {
  2441. 'block': ScatterNdAdd((8,)),
  2442. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2443. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2444. 'skip': ['backward']}),
  2445. ('ScatterNdSub', {
  2446. 'block': ScatterNdAdd((8,)),
  2447. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2448. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2449. 'skip': ['backward']}),
  2450. ('ScatterAdd', {
  2451. 'block': ScatterAdd((6,)),
  2452. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2453. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2454. 'skip': ['backward']}),
  2455. ('ScatterAddScalar', {
  2456. 'block': ScatterAdd((6,)),
  2457. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2458. Tensor(np.array([2.0], np.float32))),
  2459. 'skip': ['backward']}),
  2460. ('ScatterAdd2d', {
  2461. 'block': ScatterAdd((3, 4)),
  2462. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2463. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2464. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2465. 'skip': ['backward']}),
  2466. ('ScatterAddF16', {
  2467. 'block': ScatterAdd((6,), np.float16),
  2468. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2469. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2470. 'skip': ['backward']}),
  2471. ('ScatterAddI8', {
  2472. 'block': ScatterAdd((6,), np.int8),
  2473. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2474. Tensor(np.array([2, 3, 4], np.int8))),
  2475. 'skip': ['backward']}),
  2476. ('ScatterAddI32', {
  2477. 'block': ScatterAdd((6,), np.int32),
  2478. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2479. Tensor(np.array([2, 3, 4], np.int32))),
  2480. 'skip': ['backward']}),
  2481. ('ScatterAddU8', {
  2482. 'block': ScatterAdd((6,), np.uint8),
  2483. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2484. Tensor(np.array([2, 3, 4], np.uint8))),
  2485. 'skip': ['backward']}),
  2486. ('ScatterMulUseLocking', {
  2487. 'block': ScatterMul((6,), use_locking=True),
  2488. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2489. Tensor(np.array([2.0], np.float32))),
  2490. 'skip': ['backward']}),
  2491. ('ScatterMulScalar', {
  2492. 'block': ScatterMul((6,)),
  2493. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2494. Tensor(np.array([2.0], np.float32))),
  2495. 'skip': ['backward']}),
  2496. ('ScatterMul2d', {
  2497. 'block': ScatterMul((3, 4)),
  2498. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2499. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2500. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2501. 'skip': ['backward']}),
  2502. ('ScatterMulF16', {
  2503. 'block': ScatterMul((6,), np.float16),
  2504. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2505. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2506. 'skip': ['backward']}),
  2507. ('ScatterMulI8', {
  2508. 'block': ScatterMul((6,), np.int8),
  2509. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2510. Tensor(np.array([2, 3, 4], np.int8))),
  2511. 'skip': ['backward']}),
  2512. ('ScatterMulI32', {
  2513. 'block': ScatterMul((6,), np.int32),
  2514. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2515. Tensor(np.array([2, 3, 4], np.int32))),
  2516. 'skip': ['backward']}),
  2517. ('ScatterMulU8', {
  2518. 'block': ScatterMul((6,), np.uint8),
  2519. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2520. Tensor(np.array([2, 3, 4], np.uint8))),
  2521. 'skip': ['backward']}),
  2522. ('ScatterDivUseLocking', {
  2523. 'block': ScatterDiv((6,), use_locking=True),
  2524. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2525. Tensor(np.array([2.0], np.float32))),
  2526. 'skip': ['backward']}),
  2527. ('ScatterDivScalar', {
  2528. 'block': ScatterDiv((6,)),
  2529. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2530. Tensor(np.array([2.0], np.float32))),
  2531. 'skip': ['backward']}),
  2532. ('ScatterDiv2d', {
  2533. 'block': ScatterDiv((3, 4)),
  2534. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2535. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2536. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2537. 'skip': ['backward']}),
  2538. ('ScatterDivF16', {
  2539. 'block': ScatterDiv((6,), np.float16),
  2540. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2541. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2542. 'skip': ['backward']}),
  2543. ('ScatterDivI8', {
  2544. 'block': ScatterDiv((6,), np.int8),
  2545. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2546. Tensor(np.array([2, 3, 4], np.int8))),
  2547. 'skip': ['backward']}),
  2548. ('ScatterDivU8', {
  2549. 'block': ScatterDiv((6,), np.uint8),
  2550. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2551. Tensor(np.array([2, 3, 4], np.uint8))),
  2552. 'skip': ['backward']}),
  2553. ('ScatterSubUseLocking', {
  2554. 'block': ScatterSub((6,), use_locking=True),
  2555. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2556. Tensor(np.array([2.0], np.float32))),
  2557. 'skip': ['backward']}),
  2558. ('ScatterSubScalar', {
  2559. 'block': ScatterSub((6,)),
  2560. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2561. Tensor(np.array([2.0], np.float32))),
  2562. 'skip': ['backward']}),
  2563. ('ScatterSub2d', {
  2564. 'block': ScatterSub((3, 4)),
  2565. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2566. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2567. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2568. 'skip': ['backward']}),
  2569. ('ScatterSubF16', {
  2570. 'block': ScatterSub((6,), np.float16),
  2571. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2572. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2573. 'skip': ['backward']}),
  2574. ('ScatterSubI32', {
  2575. 'block': ScatterSub((6,), np.int32),
  2576. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2577. Tensor(np.array([2, 3, 4], np.int32))),
  2578. 'skip': ['backward']}),
  2579. ('ScatterSubI8', {
  2580. 'block': ScatterSub((6,), np.int8),
  2581. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2582. Tensor(np.array([2, 3, 4], np.int8))),
  2583. 'skip': ['backward']}),
  2584. ('ScatterSubU8', {
  2585. 'block': ScatterSub((6,), np.uint8),
  2586. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2587. Tensor(np.array([1, 1, 0], np.uint8))),
  2588. 'skip': ['backward']}),
  2589. ('SmoothL1Loss', {
  2590. 'block': P.SmoothL1Loss(),
  2591. 'desc_inputs': [[256, 4], [256, 4]],
  2592. 'desc_bprop': [[256, 4]]}),
  2593. ('IOU', {
  2594. 'block': P.IOU(),
  2595. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  2596. 'desc_bprop': [convert([128, 256], np.float16)]}),
  2597. ('Summary', {
  2598. 'block': SummaryNet(),
  2599. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2600. Tensor(np.array([1.2]).astype(np.float32))],
  2601. 'skip': ['backward']}),
  2602. ('HistogramSummary', {
  2603. 'block': HistogramSummaryNet(),
  2604. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2605. Tensor(np.array([1.2]).astype(np.float32))],
  2606. 'skip': ['backward']}),
  2607. ('PopulationCount', {
  2608. 'block': P.PopulationCount(),
  2609. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.int16))],
  2610. 'skip': ['backward']}),
  2611. ('BasicLSTMCellNet', {
  2612. 'block': BasicLSTMCellNet(),
  2613. 'desc_inputs': [Tensor(np.random.rand(1, 32).astype(np.float16)),
  2614. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2615. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2616. Tensor(np.random.rand(96, 256).astype(np.float16)),
  2617. Tensor(np.random.rand(256,).astype(np.float16))],
  2618. 'desc_bprop': [Tensor(np.random.rand(1, 64).astype(np.float16)),
  2619. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2620. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2621. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2622. Tensor(np.random.rand(1, 64).astype(np.float16))]}),
  2623. ('DynamicGRUV2Net', {
  2624. 'block': DynamicGRUV2Net(),
  2625. 'desc_inputs': [Tensor(np.random.rand(2, 8, 64).astype(np.float16)),
  2626. Tensor(np.random.rand(64, 48).astype(np.float16)),
  2627. Tensor(np.random.rand(16, 48).astype(np.float16)),
  2628. Tensor(np.random.rand(48).astype(np.float16)),
  2629. Tensor(np.random.rand(48).astype(np.float16)),
  2630. Tensor(np.random.rand(8, 16).astype(np.float16))],
  2631. 'desc_bprop': [Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2632. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2633. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2634. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2635. Tensor(np.random.rand(2, 8, 16).astype(np.float16))]}),
  2636. ]
  2637. test_case_quant_ops = [
  2638. ('Quant_1', {
  2639. 'block': inner.Quant(0.5, 0.0, False, "Round"),
  2640. 'desc_inputs': [Tensor(np.random.rand(1, 2, 4, 4), mstype.float32)],
  2641. 'skip': ['backward']}),
  2642. ('Quant_2', {
  2643. 'block': inner.Quant(80.0, 10.0, True, "Round"),
  2644. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2645. 'skip': ['backward']}),
  2646. ('Quant_3', {
  2647. 'block': inner.Quant(80.0, 0.0, False, "Floor"),
  2648. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2649. 'skip': ['backward']}),
  2650. ('Quant_4', {
  2651. 'block': inner.Quant(80.0, 0.0, False, "Ceil"),
  2652. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2653. 'skip': ['backward']}),
  2654. ('Quant_5', {
  2655. 'block': inner.Quant(80.0, 0.0, False, "Trunc"),
  2656. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2657. 'skip': ['backward']}),
  2658. ('Quant_6', {
  2659. 'block': inner.Quant(-80.0, 10.0, False, "Round"),
  2660. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2661. 'skip': ['backward']}),
  2662. ('Quant_7', {
  2663. 'block': inner.Quant(80.0, -10.0, False, "Round"),
  2664. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2665. 'skip': ['backward']}),
  2666. ('Quant_8', {
  2667. 'block': inner.Quant(80.0, 10.0, False, "Round"),
  2668. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
  2669. 'skip': ['backward']}),
  2670. ]
  2671. test_case_quantum_ops = [
  2672. ('PQC', {
  2673. 'block': P.PQC(n_qubits=3,
  2674. encoder_params_names=['e0', 'e1', 'e2'],
  2675. ansatz_params_names=['a', 'b', 'c'],
  2676. gate_names=['RX', 'RX', 'RX', 'npg', 'npg',
  2677. 'npg', 'RX', 'npg', 'npg', 'RZ',
  2678. 'npg', 'npg', 'RY'],
  2679. gate_matrix=[[[['0.0', '0.0'], ['0.0', '0.0']],
  2680. [['0.0', '0.0'], ['0.0', '0.0']]],
  2681. [[['0.0', '0.0'], ['0.0', '0.0']],
  2682. [['0.0', '0.0'], ['0.0', '0.0']]],
  2683. [[['0.0', '0.0'], ['0.0', '0.0']],
  2684. [['0.0', '0.0'], ['0.0', '0.0']]],
  2685. [[['0.7071067811865475', '0.7071067811865475'],
  2686. ['0.7071067811865475', '-0.7071067811865475']],
  2687. [['0.0', '0.0'], ['0.0', '0.0']]],
  2688. [[['0.7071067811865475', '0.7071067811865475'],
  2689. ['0.7071067811865475', '-0.7071067811865475']],
  2690. [['0.0', '0.0'], ['0.0', '0.0']]],
  2691. [[['0.7071067811865475', '0.7071067811865475'],
  2692. ['0.7071067811865475', '-0.7071067811865475']],
  2693. [['0.0', '0.0'], ['0.0', '0.0']]],
  2694. [[['0.0', '0.0'], ['0.0', '0.0']],
  2695. [['0.0', '0.0'], ['0.0', '0.0']]],
  2696. [[['0.0', '1.0'], ['1.0', '0.0']],
  2697. [['0.0', '0.0'], ['0.0', '0.0']]],
  2698. [[['0.0', '-0.0'], ['0.0', '0.0']],
  2699. [['0.0', '-1.0'], ['1.0', '0.0']]],
  2700. [[['0.0', '0.0'], ['0.0', '0.0']],
  2701. [['0.0', '0.0'], ['0.0', '0.0']]],
  2702. [[['0.0', '1.0'], ['1.0', '0.0']],
  2703. [['0.0', '0.0'], ['0.0', '0.0']]],
  2704. [[['1.0', '0.0'], ['0.0', '-1.0']],
  2705. [['0.0', '0.0'], ['0.0', '0.0']]],
  2706. [[['0.0', '0.0'], ['0.0', '0.0']],
  2707. [['0.0', '0.0'], ['0.0', '0.0']]]],
  2708. gate_obj_qubits=[[0], [1], [2], [0], [1], [2],
  2709. [0], [1], [2], [1], [1], [0], [2]],
  2710. gate_ctrl_qubits=[[], [], [], [], [], [], [], [], [], [], [2], [], []],
  2711. gate_params_names=[['e0'], ['e1'], ['e2'], [], [], [], ['a'], [], [],
  2712. ['b'], [], [], ['c']],
  2713. gate_coeff=[[1.0], [1.0], [1.0], [], [], [], [1.0], [], [], [1.0], [],
  2714. [], [1.0]],
  2715. gate_requires_grad=[[True], [True], [True], [], [], [], [True], [], [],
  2716. [True], [], [], [True]],
  2717. hams_pauli_coeff=[[1.0]],
  2718. hams_pauli_word=[[['X', 'Y', 'Z']]],
  2719. hams_pauli_qubit=[[[0, 1, 2]]],
  2720. n_threads=1),
  2721. 'desc_inputs': [Tensor(np.array([[1.0, 2.0, 3.0]]).astype(np.float32)),
  2722. Tensor(np.array([2.0, 3.0, 4.0]).astype(np.float32))],
  2723. 'skip': ['backward']}),
  2724. ('Evolution', {
  2725. 'block': P.Evolution(n_qubits=3,
  2726. param_names=['a'],
  2727. gate_names=['npg', 'npg', 'npg', 'RY'],
  2728. gate_matrix=[[[['0.7071067811865475', '0.7071067811865475'],
  2729. ['0.7071067811865475', '-0.7071067811865475']],
  2730. [['0.0', '0.0'], ['0.0', '0.0']]],
  2731. [[['0.7071067811865475', '0.7071067811865475'],
  2732. ['0.7071067811865475', '-0.7071067811865475']],
  2733. [['0.0', '0.0'], ['0.0', '0.0']]],
  2734. [[['0.0', '1.0'], ['1.0', '0.0']],
  2735. [['0.0', '0.0'], ['0.0', '0.0']]],
  2736. [[['0.0', '0.0'], ['0.0', '0.0']],
  2737. [['0.0', '0.0'], ['0.0', '0.0']]]],
  2738. gate_obj_qubits=[[0], [1], [0], [0]],
  2739. gate_ctrl_qubits=[[], [], [1], []],
  2740. gate_params_names=[[], [], [], ['a']],
  2741. gate_coeff=[[], [], [], [1.0]],
  2742. gate_requires_grad=[[], [], [], [True]],
  2743. hams_pauli_coeff=[[1.0]],
  2744. hams_pauli_word=[[['Z']]],
  2745. hams_pauli_qubit=[[[0]]]),
  2746. 'desc_inputs': [Tensor(np.array([0.5]).astype(np.float32))],
  2747. 'skip': ['backward']}),
  2748. ]
  2749. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops,
  2750. test_case_other_ops, test_case_quant_ops, test_case_quantum_ops]
  2751. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  2752. # use -k to select certain testcast
  2753. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  2754. test_exec_case = test_case
  2755. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
  2756. @non_graph_engine
  2757. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  2758. def test_exec():
  2759. context.set_context(mode=context.GRAPH_MODE)
  2760. return test_exec_case
  2761. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  2762. def test_backward_exec():
  2763. context.set_context(mode=context.GRAPH_MODE)
  2764. return test_backward_exec_case
  2765. raise_set = [
  2766. ('Cast_Error', {
  2767. 'block': (P.Cast(), {'exception': TypeError}),
  2768. 'desc_const': [mstype.int32],
  2769. 'desc_inputs': ['wrong input'],
  2770. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  2771. ('Maximum_Error', {
  2772. 'block': (P.Maximum(), {'exception': TypeError}),
  2773. 'desc_const': [(1, 2, 3)],
  2774. 'desc_inputs': [[2, 3, 3, 5]],
  2775. 'desc_bprop': [[2, 3, 3, 5]]}),
  2776. ('Shape_error', {
  2777. 'block': (P.Shape(), {'exception': TypeError}),
  2778. 'desc_inputs': [(64, 1)],
  2779. 'desc_bprop': [[64]]}),
  2780. ('Flatten_Error', {
  2781. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  2782. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  2783. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  2784. ('ScatterNdUpdate', {
  2785. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  2786. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  2787. Tensor(np.ones((2, 2), np.float32)),
  2788. Tensor(np.ones((2,), np.float32))),
  2789. 'desc_bprop': [[2, 3]]}),
  2790. ('PReLU', {
  2791. 'block': (P.PReLU(), {'exception': ValueError}),
  2792. 'desc_inputs': [[2], [1]],
  2793. 'desc_bprop': [[1]]}),
  2794. ('SSIM', {
  2795. 'block': (nn.SSIM(), {'exception': ValueError}),
  2796. 'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
  2797. Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]})
  2798. ]
  2799. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  2800. def test_check_exception():
  2801. return raise_set