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