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