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