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