You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_ops.py 120 kB

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