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

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