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 132 kB

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