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