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