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