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

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