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