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