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

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