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