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