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