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