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