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 76 kB

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