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

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