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 87 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  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. ('Reciprocal', {
  627. 'block': P.Reciprocal(),
  628. 'desc_inputs': [[2, 3, 3, 5]],
  629. 'desc_bprop': [[2, 3, 3, 5]]}),
  630. ('Minimum_0', {
  631. 'block': P.Minimum(),
  632. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  633. 'desc_bprop': [[2, 3, 3, 5]]}),
  634. ('Maximum', {
  635. 'block': P.Maximum(),
  636. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  637. 'desc_bprop': [[2, 3, 3, 5]]}),
  638. ('Maximum_0', {
  639. 'block': P.Maximum(),
  640. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  641. 'desc_bprop': [[2, 3, 3, 5]]}),
  642. ('MaximumGrad', {
  643. 'block': G.MaximumGrad(),
  644. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  645. 'skip': ['backward']}),
  646. ('MinimumGrad', {
  647. 'block': G.MinimumGrad(),
  648. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  649. 'skip': ['backward']}),
  650. ('StridedSlice', {
  651. 'block': P.StridedSlice(),
  652. 'desc_const': [(0, 1, 2, 1),
  653. (2, 3, 3, 4),
  654. (1, 1, 1, 1)],
  655. 'desc_inputs': [[2, 3, 3, 5]],
  656. 'desc_bprop': [[2, 2, 1, 3]]}),
  657. ('Slice_1', {
  658. 'block': P.Slice(),
  659. 'desc_const': [(0, 1, 2, 1),
  660. (1, 1, 1, 2)],
  661. 'desc_inputs': [[2, 3, 3, 5]],
  662. 'desc_bprop': [[1, 1, 1, 2]]}),
  663. ('StridedSliceGrad', {
  664. 'block': G.StridedSliceGrad(),
  665. 'desc_const': [(64, 1, 1024),
  666. (0, 1, 0),
  667. (64, 2, 1024),
  668. (1, 1, 1)],
  669. 'desc_inputs': [[64, 128, 1024]],
  670. 'skip': ['backward']}),
  671. ('RandomChoiceWithMask', {
  672. 'block': P.RandomChoiceWithMask(256),
  673. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  674. 'desc_bprop': [[256, 4], [256, 4]],
  675. 'skip': ['backward']}),
  676. ('LessEqual', {
  677. 'block': P.LessEqual(),
  678. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  679. Tensor(np.random.rand(4).astype(np.float16))],
  680. 'skip': ['backward']}),
  681. ('Less', {
  682. 'block': P.Less(),
  683. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  684. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  685. 'skip': ['backward']}),
  686. ('RealDiv_0', {
  687. 'block': P.RealDiv(),
  688. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  689. 'desc_inputs': [],
  690. 'skip': ['backward']}),
  691. ('RealDiv', {
  692. 'block': P.RealDiv(),
  693. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  694. 'desc_bprop': [[4]]}),
  695. ('RealDiv_1', {
  696. 'block': P.RealDiv(),
  697. 'desc_inputs': [[512, 1024], [512, 1024]],
  698. 'desc_bprop': [[512, 1024]]}),
  699. ('FloorDiv', {
  700. 'block': P.FloorDiv(),
  701. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  702. Tensor(np.random.rand(4).astype(np.float16))],
  703. 'skip': ['backward']}),
  704. ('FloorMod', {
  705. 'block': P.FloorMod(),
  706. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  707. 'desc_bprop': [[2, 3, 4, 5]]}),
  708. ('identity', {
  709. 'block': ops.functional.identity,
  710. 'desc_inputs': [[2, 2]],
  711. 'skip': ['backward']}),
  712. ('MatMul_1', {
  713. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  714. 'desc_inputs': [[1024, 160], [160, 1024]],
  715. 'desc_bprop': [[1024, 1024]]}),
  716. ('MatMul_2', {
  717. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  718. 'desc_inputs': [[160, 1024], [1024, 160]],
  719. 'desc_bprop': [[1024, 1024]]}),
  720. ('Sub', {
  721. 'block': P.Sub(),
  722. 'desc_inputs': [[3], [3]],
  723. 'desc_bprop': [[3]]}),
  724. ('TruncatedNormal', {
  725. 'block': P.TruncatedNormal(),
  726. 'desc_const': [(1, 2, 3)],
  727. 'desc_inputs': [],
  728. 'skip': ['backward'],
  729. 'add_fake_input': True}),
  730. ('Select', {
  731. 'block': P.Select(),
  732. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  733. [2, 3], [2, 3]],
  734. 'desc_bprop': [[2, 3]]}),
  735. ('Rank', {
  736. 'block': P.Rank(),
  737. 'desc_inputs': [[2, 3]],
  738. 'skip': ['backward']}),
  739. ('InvertPermutation', {
  740. 'block': P.InvertPermutation(),
  741. 'desc_const': [(0, 3, 1, 2)],
  742. 'desc_inputs': [],
  743. 'skip': ['backward']}),
  744. ('Square', {
  745. 'block': P.Square(),
  746. 'desc_inputs': [[4]],
  747. 'desc_bprop': [[4]]}),
  748. ('Rsqrt', {
  749. 'block': P.Rsqrt(),
  750. 'desc_inputs': [[4]],
  751. 'desc_bprop': [[4]]}),
  752. ('Sqrt', {
  753. 'block': P.Sqrt(),
  754. 'desc_inputs': [[4]],
  755. 'desc_bprop': [[4]]}),
  756. ('RealDiv', {
  757. 'block': P.RealDiv(),
  758. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  759. 'desc_bprop': [[2, 3, 4, 5]]}),
  760. ('Div', {
  761. 'block': P.Div(),
  762. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  763. 'desc_bprop': [[2, 3, 4, 5]]}),
  764. ('Equal', {
  765. 'block': P.Equal(),
  766. 'desc_inputs': [[3, 4, 5], [4, 5]],
  767. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  768. ('NotEqual', {
  769. 'block': P.NotEqual(),
  770. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  771. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  772. ('NotEqual_0', {
  773. 'block': P.NotEqual(),
  774. 'desc_inputs': [1, [2, 3, 4, 5]],
  775. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  776. 'skip': ['backward']}),
  777. ('ApproximateEqual', {
  778. 'block': P.ApproximateEqual(),
  779. 'desc_inputs': [[3, 4, 5], [3, 4, 5]],
  780. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  781. ('Greater', {
  782. 'block': P.Greater(),
  783. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  784. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  785. ('GreaterEqual', {
  786. 'block': P.GreaterEqual(),
  787. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  788. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  789. ('LogicalNot', {
  790. 'block': P.LogicalNot(),
  791. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  792. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  793. ('LogicalAnd', {
  794. 'block': P.LogicalAnd(),
  795. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  796. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  797. ('LogicalOr', {
  798. 'block': P.LogicalOr(),
  799. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  800. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  801. ('NpuAllocFloatStatus', {
  802. 'block': P.NPUAllocFloatStatus(),
  803. 'desc_inputs': [],
  804. 'add_fack_input': True,
  805. 'fack_input_type': np.float32,
  806. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  807. 'skip': ['backward']}),
  808. ('NpuGetFloatStatus', {
  809. 'block': P.NPUGetFloatStatus(),
  810. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  811. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  812. 'skip': ['backward']}),
  813. ('NpuClearFloatStatus', {
  814. 'block': P.NPUClearFloatStatus(),
  815. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  816. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  817. 'skip': ['backward']}),
  818. ('CheckValid', {
  819. 'block': P.CheckValid(),
  820. 'desc_inputs': [[20000, 4], [3]],
  821. 'desc_bprop': [[20000]],
  822. 'skip': ['backward']}),
  823. ('NMSWithMask', {
  824. 'block': P.NMSWithMask(0.5),
  825. 'desc_inputs': [[128, 5]],
  826. 'desc_bprop': [[128, 5], [128], [128]],
  827. 'skip': ['backward']}),
  828. ('Abs', {
  829. 'block': P.Abs(),
  830. 'desc_inputs': [[4]],
  831. 'desc_bprop': [[4]]}),
  832. ('CumSum', {
  833. 'block': CumSumNet(),
  834. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  835. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  836. [1, 3, 7, 9]]).astype(np.float32))]}),
  837. ('ReduceSum_3', {
  838. 'block': P.ReduceSum(),
  839. 'desc_const': [0],
  840. 'desc_inputs': [[3, 2]],
  841. 'desc_bprop': [[2]]}),
  842. ('ReduceSum_4', {
  843. 'block': P.ReduceSum(keep_dims=True),
  844. 'desc_const': [0],
  845. 'desc_inputs': [[3, 2]],
  846. 'desc_bprop': [[1, 2]]}),
  847. ('ReduceSum_5', {
  848. 'block': P.ReduceSum(keep_dims=True),
  849. 'desc_inputs': [[2, 3, 4]],
  850. 'desc_bprop': [[1, 1, 1]]}),
  851. ('ReduceSum_6', {
  852. 'block': P.ReduceSum(),
  853. 'desc_inputs': [[2, 3, 4]],
  854. 'desc_bprop': [[1]]}),
  855. ('Sum_0', {
  856. 'block': P.ReduceSum(),
  857. 'desc_const': [(1,)],
  858. 'desc_inputs': [[3, 2]],
  859. 'desc_bprop': [[3]]}),
  860. ('Sum_1', {
  861. 'block': P.ReduceSum(keep_dims=True),
  862. 'desc_const': [(1,)],
  863. 'desc_inputs': [[3, 2]],
  864. 'desc_bprop': [[3, 1]]}),
  865. ('Sum_2', {
  866. 'block': P.ReduceSum(),
  867. 'desc_const': [(0, 1)],
  868. 'desc_inputs': [[3, 2]],
  869. 'desc_bprop': [[1]]}),
  870. ('Sum_3', {
  871. 'block': P.ReduceSum(),
  872. 'desc_const': [0],
  873. 'desc_inputs': [[3, 2]],
  874. 'desc_bprop': [[2]]}),
  875. ('Sum_4', {
  876. 'block': P.ReduceSum(keep_dims=True),
  877. 'desc_const': [0],
  878. 'desc_inputs': [[3, 2]],
  879. 'desc_bprop': [[1, 2]]}),
  880. ('Sum_5', {
  881. 'block': P.ReduceSum(keep_dims=True),
  882. 'desc_const': [()],
  883. 'desc_inputs': [[2, 3, 4]],
  884. 'desc_bprop': [[1, 1, 1]]}),
  885. ('Sum_6', {
  886. 'block': P.ReduceSum(),
  887. 'desc_const': [()],
  888. 'desc_inputs': [[2, 3, 4]],
  889. 'desc_bprop': [[1]]}),
  890. ('Sign', {
  891. 'block': P.Sign(),
  892. 'desc_inputs': [[3]],
  893. 'desc_bprop': [[3]]}),
  894. ('Round', {
  895. 'block': P.Round(),
  896. 'desc_inputs': [[3]],
  897. 'desc_bprop': [[3]]}),
  898. ('Atan2', {
  899. 'block': P.Atan2(),
  900. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  901. Tensor(np.array([1, 1]).astype(np.float32))],
  902. 'desc_bprop': [[2]]}),
  903. ('SquareSumAll', {
  904. 'block': P.SquareSumAll(),
  905. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  906. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  907. 'skip': ['backward']}),
  908. ('Cos', {
  909. 'block': P.Cos(),
  910. 'desc_inputs': [[2, 3]],
  911. 'desc_bprop': [[2, 3]]}),
  912. ('ReduceAll', {
  913. 'block': P.ReduceAll(),
  914. 'desc_const': [1],
  915. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  916. 'desc_bprop': []}),
  917. ('BesselI0e', {
  918. 'block': P.BesselI0e(),
  919. 'desc_inputs': [[2, 3]],
  920. 'desc_bprop': [[2, 3]]}),
  921. ('BesselI1e', {
  922. 'block': P.BesselI1e(),
  923. 'desc_inputs': [[2, 3]],
  924. 'desc_bprop': [[2, 3]]}),
  925. ('Atan', {
  926. 'block': P.Atan(),
  927. 'desc_inputs': [[2, 3]],
  928. 'desc_bprop': [[2, 3]]}),
  929. ('AtanGrad', {
  930. 'block': G.AtanGrad(),
  931. 'desc_inputs': [[2, 3], [2, 3]],
  932. 'skip': ['backward']}),
  933. ('Atanh', {
  934. 'block': P.Atanh(),
  935. 'desc_inputs': [[2, 3]],
  936. 'desc_bprop': [[2, 3]]}),
  937. ('Cosh', {
  938. 'block': P.Cosh(),
  939. 'desc_inputs': [[3, 4, 5]],
  940. 'desc_bprop': [[3, 4, 5]]}),
  941. ('Sinh', {
  942. 'block': P.Sinh(),
  943. 'desc_inputs': [[3, 4, 5]],
  944. 'desc_bprop': [[3, 4, 5]]}),
  945. ('Inv', {
  946. 'block': P.Inv(),
  947. 'desc_inputs': [[21, 9, 12, 5]],
  948. 'desc_bprop': [[21, 9, 12, 5]]}),
  949. ('Invert', {
  950. 'block': P.Invert(),
  951. 'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
  952. 'desc_bprop': [],
  953. 'skip': ['backward']}),
  954. ('HistogramFixedWidth', {
  955. 'block': P.HistogramFixedWidth(5),
  956. 'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
  957. 'desc_bprop': [],
  958. 'skip': ['backward']}),
  959. ('Normal', {
  960. 'block': NormalNet((3, 2, 4), 0.0, 1.0, 0),
  961. 'desc_inputs': [],
  962. 'skip': ['backward']}),
  963. ('Mod', {
  964. 'block': P.Mod(),
  965. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  966. 'desc_bprop': [[2, 3, 4, 5]]}),
  967. ]
  968. test_case_nn_ops = [
  969. ('BiasAdd', {
  970. 'block': P.BiasAdd(),
  971. 'desc_inputs': [[1, 3, 3, 3], [3]],
  972. 'desc_bprop': [[1, 3, 3, 3]]}),
  973. ('BiasAddGrad', {
  974. 'block': G.BiasAddGrad(),
  975. 'desc_inputs': [[1, 3, 3, 3]],
  976. 'skip': ['backward']}),
  977. ('Gelu', {
  978. 'block': P.Gelu(),
  979. 'desc_inputs': [[1, 3, 4, 4]],
  980. 'desc_bprop': [[1, 3, 4, 4]]}),
  981. ('GeluGrad', {
  982. 'block': G.GeluGrad(),
  983. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  984. 'desc_bprop': [[2, 2]],
  985. 'skip': ['backward']}),
  986. ('Tanh', {
  987. 'block': P.Tanh(),
  988. 'desc_inputs': [[1, 3, 4, 4]],
  989. 'desc_bprop': [[1, 3, 4, 4]]}),
  990. ('TanhGrad', {
  991. 'block': G.TanhGrad(),
  992. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  993. 'desc_bprop': [[1, 3, 4, 4]],
  994. 'skip': ['backward']}),
  995. ('ReLU', {
  996. 'block': P.ReLU(),
  997. 'desc_inputs': [[1, 3, 4, 4]],
  998. 'desc_bprop': [[1, 3, 4, 4]]}),
  999. ('ReLU6', {
  1000. 'block': P.ReLU6(),
  1001. 'desc_inputs': [[1, 3, 4, 4]],
  1002. 'desc_bprop': [[1, 3, 4, 4]]}),
  1003. ('ReLUV2', {
  1004. 'block': P.ReLUV2(),
  1005. 'desc_inputs': [[1, 3, 4, 4]],
  1006. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  1007. ('ReLUGrad', {
  1008. 'block': G.ReluGrad(),
  1009. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1010. 'skip': ['backward']}),
  1011. ('Softplus', {
  1012. 'block': P.Softplus(),
  1013. 'desc_inputs': [[1, 3, 4, 4]],
  1014. 'desc_bprop': [[1, 3, 4, 4]]}),
  1015. ('SoftplusGrad', {
  1016. 'block': G.SoftplusGrad(),
  1017. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1018. 'skip': ['backward']}),
  1019. ('Elu', {
  1020. 'block': P.Elu(),
  1021. 'desc_inputs': [[2, 3, 4]],
  1022. 'desc_bprop': [[2, 3, 4]]}),
  1023. ('EluGrad', {
  1024. 'block': G.EluGrad(),
  1025. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  1026. 'desc_bprop': [[2, 3, 4]],
  1027. 'skip': ['backward']}),
  1028. ('Sigmoid', {
  1029. 'block': P.Sigmoid(),
  1030. 'desc_inputs': [[1, 3, 4, 4]],
  1031. 'desc_bprop': [[1, 3, 4, 4]]}),
  1032. ('MaxPool', {
  1033. 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1034. 'desc_inputs': [[100, 3, 28, 28]],
  1035. 'desc_bprop': [[100, 3, 14, 14]]}),
  1036. ('MaxPoolGrad', {
  1037. 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1038. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  1039. 'desc_bprop': [[3, 4, 6, 6]],
  1040. 'skip': ['backward']}),
  1041. ('AvgPool', {
  1042. 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1043. 'desc_inputs': [[100, 3, 28, 28]],
  1044. 'desc_bprop': [[100, 3, 14, 14]]}),
  1045. ('AvgPoolGrad', {
  1046. 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
  1047. 'desc_const': [(3, 4, 6, 6)],
  1048. 'const_first': True,
  1049. 'desc_inputs': [[3, 4, 6, 6]],
  1050. 'desc_bprop': [[3, 4, 6, 6]],
  1051. 'skip': ['backward']}),
  1052. ('MaxPoolWithArgmax', {
  1053. 'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
  1054. 'desc_inputs': [[128, 32, 32, 64]],
  1055. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
  1056. ('SoftmaxCrossEntropyWithLogits', {
  1057. 'block': P.SoftmaxCrossEntropyWithLogits(),
  1058. 'desc_inputs': [[1, 10], [1, 10]],
  1059. 'desc_bprop': [[1], [1, 10]],
  1060. 'skip': ['backward_exec']}),
  1061. ('Flatten', {
  1062. 'block': P.Flatten(),
  1063. 'desc_inputs': [[128, 32, 32, 64]],
  1064. 'desc_bprop': [[128, 65536]]}),
  1065. ('LogSoftmax', {
  1066. 'block': P.LogSoftmax(),
  1067. 'desc_inputs': [[64, 2]],
  1068. 'desc_bprop': [[64, 2]]}),
  1069. ('LogSoftmaxGrad', {
  1070. 'block': G.LogSoftmaxGrad(),
  1071. 'desc_inputs': [[16, 1234], [16, 1234]],
  1072. 'desc_bprop': [[64, 2]],
  1073. 'skip': ['backward']}),
  1074. ('L2Normalize', {
  1075. 'block': P.L2Normalize(),
  1076. 'desc_inputs': [[2, 2]],
  1077. 'desc_bprop': [[2, 2]]}),
  1078. ('L2NormalizeGrad', {
  1079. 'block': G.L2NormalizeGrad(),
  1080. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1081. 'desc_bprop': [[2, 2]],
  1082. 'skip': ['backward']}),
  1083. ('LayerNorm', {
  1084. 'block': P.LayerNorm(),
  1085. 'desc_inputs': [[2, 16], [16], [16]],
  1086. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  1087. ('LayerNormGrad', {
  1088. 'block': G.LayerNormGrad(),
  1089. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  1090. 'desc_bprop': [[2, 16], [16], [16]],
  1091. 'skip': ['backward']}),
  1092. ('FusedBatchNorm', {
  1093. 'block': P.FusedBatchNorm(),
  1094. 'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1095. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1096. 'skip': []}),
  1097. ('FusedBatchNormGrad', {
  1098. 'block': G.FusedBatchNormGrad(),
  1099. 'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
  1100. 'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
  1101. 'skip': ['backward']}),
  1102. ('BatchNorm', {
  1103. 'block': P.BatchNorm(),
  1104. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1105. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1106. 'skip': []}),
  1107. ('BatchNormGrad', {
  1108. 'block': G.BatchNormGrad(),
  1109. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  1110. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1111. 'skip': ['backward']}),
  1112. ('BasicLSTMCell', {
  1113. 'block': P.BasicLSTMCell(keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'),
  1114. 'desc_inputs': [[128, 128], [128, 128], [128, 128], [512, 256, 1, 1], [512, 1, 1, 1]],
  1115. 'desc_bprop': [[128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128]],
  1116. 'skip': []}),
  1117. ('TopK', {
  1118. 'block': P.TopK(),
  1119. 'desc_const': [5],
  1120. 'desc_inputs': [[20, 20, 10]],
  1121. 'desc_bprop': [[20, 20, 5]],
  1122. 'skip': ['backward']}),
  1123. ('GatherV2_0', {
  1124. 'block': P.GatherV2(),
  1125. 'desc_const': [0],
  1126. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1127. 'desc_bprop': [[2, 1, 2]]}),
  1128. ('GatherV2_1', {
  1129. 'block': P.GatherV2(),
  1130. 'desc_const': [2],
  1131. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1132. 'desc_bprop': [[3, 1, 2]]}),
  1133. ('GatherV2_2', {
  1134. 'block': P.GatherV2(),
  1135. 'desc_const': [0],
  1136. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1137. 'desc_bprop': [[3, 2, 1, 3]]}),
  1138. ('GatherV2_3', {
  1139. 'block': P.GatherV2(),
  1140. 'desc_const': [2],
  1141. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1142. 'desc_bprop': [[3, 1, 3, 2]]}),
  1143. ('GatherV2_4', {
  1144. 'block': P.GatherV2(),
  1145. 'desc_const': [1],
  1146. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  1147. 'desc_bprop': [[32, 1, 1024]]}),
  1148. ('GatherV2_5', {
  1149. 'block': P.GatherV2(),
  1150. 'desc_const': [-1],
  1151. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1152. 'desc_bprop': [[3, 1, 2]]}),
  1153. ('GatherV2_6', {
  1154. 'block': P.GatherV2(),
  1155. 'desc_const': [0],
  1156. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  1157. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  1158. ('SparseGatherV2_0', {
  1159. 'block': P.SparseGatherV2(),
  1160. 'desc_const': [0],
  1161. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1162. 'desc_bprop': [[2, 1, 2]]}),
  1163. ('Range', {
  1164. 'block': inner.Range(1.0, 5.0),
  1165. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  1166. 'desc_bprop': [[10]]}),
  1167. ('UnsortedSegmentSum', {
  1168. 'block': P.UnsortedSegmentSum(),
  1169. 'desc_const': [1280],
  1170. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  1171. 'desc_bprop': [[8192, 1024]],
  1172. 'skip': ['backward']}),
  1173. ('UnsortedSegmentSum_1', {
  1174. 'block': P.UnsortedSegmentSum(),
  1175. 'desc_const': [4],
  1176. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1177. 'desc_bprop': [[4, 1, 3]],
  1178. 'skip': ['backward']}),
  1179. ('UnsortedSegmentMin', {
  1180. 'block': P.UnsortedSegmentMin(),
  1181. 'desc_const': [4],
  1182. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1183. 'desc_bprop': [[4, 2, 1, 3]]}),
  1184. ('UnsortedSegmentProd', {
  1185. 'block': P.UnsortedSegmentProd(),
  1186. 'desc_const': [4],
  1187. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([0, 1, 0]).astype(np.int32))],
  1188. 'desc_bprop': [[4, 2, 1, 3]]}),
  1189. ('DropoutGenMask', {
  1190. 'block': P.DropoutGenMask(),
  1191. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  1192. 'desc_inputs': [],
  1193. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  1194. 'skip': ['backward']}),
  1195. ('DropoutDoMask', {
  1196. 'block': P.DropoutDoMask(),
  1197. 'desc_const': [Tensor(0.5)],
  1198. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  1199. 'desc_bprop': [[64, 12, 128, 128]]}),
  1200. ('Dropout', {
  1201. 'block': nn.Dropout(0.5),
  1202. 'desc_inputs': [[64, 12, 128, 128]],
  1203. 'desc_bprop': [[64, 12, 128, 128]]}),
  1204. ('ReduceMean0', {
  1205. 'block': P.ReduceMean(),
  1206. 'desc_const': [(2,)],
  1207. 'desc_inputs': [[3, 2, 2]],
  1208. 'desc_bprop': [[3, 2]]}),
  1209. ('ReduceMean1', {
  1210. 'block': P.ReduceMean(),
  1211. 'desc_const': [2],
  1212. 'desc_inputs': [[3, 2, 2]],
  1213. 'desc_bprop': [[3, 2]]}),
  1214. ('All', {
  1215. 'block': P.ReduceAll(),
  1216. 'desc_const': [(1,)],
  1217. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  1218. 'desc_bprop': [[3]],
  1219. 'skip': ['backward']}),
  1220. ('DescConst', {
  1221. 'block': Tensor(np.array([2], np.float32)),
  1222. 'desc_inputs': [],
  1223. 'desc_bprop': [[1]],
  1224. 'skip': ['backward'],
  1225. 'add_fake_input': True}),
  1226. ('Fill', {
  1227. 'block': P.Fill(),
  1228. 'desc_const': [mstype.float32, (2, 3), 1.0],
  1229. 'desc_inputs': [],
  1230. 'desc_bprop': [[2, 3]],
  1231. 'skip': ['backward'],
  1232. 'add_fake_input': True}),
  1233. ('OnesLike', {
  1234. 'block': P.OnesLike(),
  1235. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1236. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1237. }),
  1238. ('ZerosLike', {
  1239. 'block': P.ZerosLike(),
  1240. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1241. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1242. }),
  1243. ('Softmax', {
  1244. 'block': P.Softmax(),
  1245. 'desc_inputs': [[5, 5]],
  1246. 'desc_bprop': [[5, 5]]}),
  1247. ('Softsign', {
  1248. 'block': P.Softsign(),
  1249. 'desc_inputs': [[5, 5]],
  1250. 'desc_bprop': [[5, 5]]}),
  1251. ('DepthwiseConv2dNative_1', {
  1252. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  1253. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  1254. 'desc_bprop': [[10, 32, 16, 16]]}),
  1255. ('DepthwiseConv2dNative_2', {
  1256. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  1257. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  1258. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  1259. ('SigmoidCrossEntropyWithLogits', {
  1260. 'block': P.SigmoidCrossEntropyWithLogits(),
  1261. 'desc_inputs': [[128, 10], [128, 10]],
  1262. 'desc_bprop': [[128, 10]]}),
  1263. ('Pad', {
  1264. 'block': P.Pad(((1, 2), (2, 3))),
  1265. 'desc_inputs': [[7, 7]],
  1266. 'desc_bprop': [[10, 12]]}),
  1267. ('BinaryCrossEntropy', {
  1268. 'block': P.BinaryCrossEntropy(),
  1269. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  1270. 'desc_bprop': []}),
  1271. ('SparseApplyAdagrad', {
  1272. 'block': SparseApplyAdagradNet(),
  1273. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1274. 'desc_bprop': [[3, 3], [3, 3]],
  1275. 'skip': ['backward']}),
  1276. ('SparseApplyAdagradV2', {
  1277. 'block': SparseApplyAdagradV2Net(),
  1278. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1279. 'skip': ['backward']}),
  1280. ('SparseApplyFtrl', {
  1281. 'block': SparseApplyFtrlNet(),
  1282. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1283. 'skip': ['backward']}),
  1284. ('SparseApplyFtrlV2', {
  1285. 'block': SparseApplyFtrlV2Net(),
  1286. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1287. 'skip': ['backward']}),
  1288. ('ApplyProximalAdagrad', {
  1289. 'block': ApplyProximalAdagradNet(),
  1290. 'desc_inputs': [[3, 3]],
  1291. 'skip': ['backward']}),
  1292. ('SparseApplyProximalAdagrad', {
  1293. 'block': SparseApplyProximalAdagradNet(),
  1294. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1295. 'skip': ['backward']}),
  1296. ('ApplyAdaMax', {
  1297. 'block': ApplyAdaMaxNet(),
  1298. 'desc_inputs': [[3, 3]],
  1299. 'skip': ['backward']}),
  1300. ('ApplyAdadelta', {
  1301. 'block': ApplyAdadeltaNet(),
  1302. 'desc_inputs': [[3, 3]],
  1303. 'skip': ['backward']}),
  1304. ('ApplyAdagrad', {
  1305. 'block': ApplyAdagradNet(),
  1306. 'desc_inputs': [[3, 3]],
  1307. 'skip': ['backward']}),
  1308. ('ApplyAdagradV2', {
  1309. 'block': ApplyAdagradV2Net(),
  1310. 'desc_inputs': [[3, 3]],
  1311. 'skip': ['backward']}),
  1312. ('ApplyAddSign', {
  1313. 'block': ApplyAddSignNet(),
  1314. 'desc_inputs': [[3, 3]],
  1315. 'skip': ['backward']}),
  1316. ('ApplyPowerSign', {
  1317. 'block': ApplyPowerSignNet(),
  1318. 'desc_inputs': [[3, 3]],
  1319. 'skip': ['backward']}),
  1320. ('ApplyGradientDescent', {
  1321. 'block': ApplyGradientDescentNet(),
  1322. 'desc_inputs': [[3, 3]],
  1323. 'skip': ['backward']}),
  1324. ('ApplyProximalGradientDescent', {
  1325. 'block': ApplyProximalGradientDescentNet(),
  1326. 'desc_inputs': [[3, 3]],
  1327. 'skip': ['backward']}),
  1328. ('Flatten_1', {
  1329. 'block': NetForFlatten(),
  1330. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1331. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1332. 'skip': ['backward']}),
  1333. ('Flatten_2', {
  1334. 'block': NetForFlatten(),
  1335. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  1336. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  1337. 'skip': ['backward']}),
  1338. ('Flatten_3', {
  1339. 'block': NetForFlattenComposed(),
  1340. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1341. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1342. 'skip': []}),
  1343. ('ArgmaxNet', {
  1344. 'block': ArgmaxNet(),
  1345. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1346. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1347. 'skip': ['backward']}),
  1348. ('ArgminNet', {
  1349. 'block': ArgminNet(),
  1350. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1351. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1352. 'skip': ['backward']}),
  1353. ('StridedSliceNet', {
  1354. 'block': StridedSliceNet(),
  1355. 'desc_inputs': [[6, 7, 8, 9, 10]],
  1356. 'skip': ['backward']}),
  1357. ('OneHot', {
  1358. 'block': P.OneHot(),
  1359. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  1360. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  1361. 'desc_bprop': [[1, 3]]}),
  1362. ('ReduceProd_0', {
  1363. 'block': P.ReduceProd(),
  1364. 'desc_const': [0],
  1365. 'desc_inputs': [[3, 2]],
  1366. 'desc_bprop': [[2]]}),
  1367. ('ReduceProd_1', {
  1368. 'block': P.ReduceProd(keep_dims=True),
  1369. 'desc_const': [0],
  1370. 'desc_inputs': [[3, 2]],
  1371. 'desc_bprop': [[1, 2]]}),
  1372. ('CumProd', {
  1373. 'block': P.CumProd(),
  1374. 'desc_const': [0],
  1375. 'desc_inputs': [[3, 2]],
  1376. 'desc_bprop': [[3, 2]]}),
  1377. ('ApplyFtrl', {
  1378. 'block': ApplyFtrlNet(),
  1379. 'desc_inputs': [[3, 3]],
  1380. 'desc_bprop': [3, 3],
  1381. 'skip': ['backward']}),
  1382. ('ApplyRMSProp', {
  1383. 'block': ApplyRMSNet(),
  1384. 'desc_inputs': [[3, 3]],
  1385. 'desc_bprop': [3, 3],
  1386. 'skip': ['backward']}),
  1387. ('ApplyCenteredRMSProp', {
  1388. 'block': P.ApplyCenteredRMSProp(),
  1389. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  1390. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  1391. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  1392. 'desc_bprop': [1],
  1393. 'skip': ['backward']}),
  1394. ('CTCLoss', {
  1395. 'block': P.CTCLoss(),
  1396. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  1397. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  1398. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  1399. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  1400. 'desc_bprop': [[4], [6, 4, 6]]}),
  1401. ('L2Loss_1', {
  1402. 'block': P.L2Loss(),
  1403. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  1404. 'desc_bprop': []}),
  1405. ('L2Loss_2', {
  1406. 'block': P.L2Loss(),
  1407. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  1408. 'desc_bprop': []}),
  1409. ('ResizeBilinear', {
  1410. 'block': P.ResizeBilinear((5, 5)),
  1411. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  1412. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  1413. ('ResizeBilinearGrad', {
  1414. 'block': G.ResizeBilinearGrad(),
  1415. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1416. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  1417. 'skip': ['backward']}),
  1418. ('ROIAlign', {
  1419. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  1420. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  1421. 'desc_bprop': [[7, 7]]}),
  1422. ('ROIAlignGrad', {
  1423. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  1424. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  1425. 'desc_bprop': [[1, 1, 2, 2]],
  1426. 'skip': ['backward']}),
  1427. ('LARSUpdate', {
  1428. 'block': P.LARSUpdate(1e-05, 0.001, False),
  1429. 'desc_const': [0.0, 0.001],
  1430. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  1431. 'desc_bprop': [3, 3],
  1432. 'skip': ['backward']}),
  1433. ('SGD', {
  1434. 'block': P.SGD(0.0, 0.0, False),
  1435. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  1436. 'desc_bprop': [3, 3],
  1437. 'skip': ['backward']}),
  1438. ('BinaryCrossEntropy', {
  1439. 'block': P.BinaryCrossEntropy(),
  1440. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1441. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  1442. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1443. 'desc_bprop': []}),
  1444. ('BinaryCrossEntropyGrad', {
  1445. 'block': G.BinaryCrossEntropyGrad(),
  1446. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  1447. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  1448. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  1449. 'desc_bprop': [],
  1450. 'skip': ['backward']}),
  1451. ('DataFormatDimMap', {
  1452. 'block': P.DataFormatDimMap(),
  1453. 'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
  1454. 'desc_bprop': [],
  1455. 'skip': ['backward']}),
  1456. ('MaxPoolGradGrad', {
  1457. 'block': G.MaxPoolGradGrad(),
  1458. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1459. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1460. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16)],
  1461. 'desc_bprop': [],
  1462. 'skip': ['backward']}),
  1463. ('MaxPoolGradGradWithArgmax', {
  1464. 'block': G.MaxPoolGradGradWithArgmax(),
  1465. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1466. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  1467. Tensor(np.zeros((1, 1, 2, 2)), mstype.uint16)],
  1468. 'desc_bprop': [],
  1469. 'skip': ['backward']}),
  1470. ]
  1471. test_case_array_ops = [
  1472. ('SpaceToDepth', {
  1473. 'block': P.SpaceToDepth(2),
  1474. 'desc_inputs': [[1, 3, 2, 2]],
  1475. 'desc_bprop': [[1, 12, 1, 1]]}),
  1476. ('DepthToSpace', {
  1477. 'block': P.DepthToSpace(2),
  1478. 'desc_inputs': [[1, 12, 1, 1]],
  1479. 'desc_bprop': [[1, 3, 2, 2]]}),
  1480. ('Split', {
  1481. 'block': P.Split(1, 2),
  1482. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  1483. 'skip': ['backward']}),
  1484. ('Argmax', {
  1485. 'block': P.Argmax(),
  1486. 'desc_inputs': [[128, 32, 32, 64]],
  1487. 'desc_bprop': [0],
  1488. 'skip': ['backward']}),
  1489. ('Argmin', {
  1490. 'block': P.Argmin(),
  1491. 'desc_inputs': [[128, 32, 32, 64]],
  1492. 'desc_bprop': [1],
  1493. 'skip': ['backward']}),
  1494. ('ArgMaxWithValue', {
  1495. 'block': P.ArgMaxWithValue(),
  1496. 'desc_inputs': [[128, 32, 32, 64]],
  1497. 'desc_bprop': [[1], [1]],
  1498. 'skip': ['backward']}),
  1499. ('ArgMinWithValue', {
  1500. 'block': P.ArgMinWithValue(),
  1501. 'desc_inputs': [[128, 32, 32, 64]],
  1502. 'desc_bprop': [[1], [1]],
  1503. 'skip': ['backward']}),
  1504. ('Transpose_dim3', {
  1505. 'block': P.Transpose(),
  1506. 'desc_const': [(0, 2, 1)],
  1507. 'desc_inputs': [[1, 2, 3]],
  1508. 'desc_bprop': [[1, 3, 2]]}),
  1509. ('Transpose_dim4', {
  1510. 'block': P.Transpose(),
  1511. 'desc_const': [(0, 1, 2, 3)],
  1512. 'desc_inputs': [[1, 2, 3, 4]],
  1513. 'desc_bprop': [[1, 2, 4, 3]]}),
  1514. ('AddN', {
  1515. 'block': NetForTupleInput(P.AddN()),
  1516. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1517. 'desc_bprop': [[2, 3, 3, 5]],
  1518. 'skip': ['backward']}),
  1519. ('AccumulateNV2', {
  1520. 'block': NetForTupleInput(P.AccumulateNV2()),
  1521. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  1522. 'desc_bprop': [[2, 3, 3, 5]],
  1523. 'skip': ['backward']}),
  1524. ('Shape', {
  1525. 'block': P.Shape(),
  1526. 'desc_inputs': [[3, 3, 2, 2]],
  1527. 'skip': ['backward']}),
  1528. ('Reshape', {
  1529. 'block': P.Reshape(),
  1530. 'desc_const': [(64,)],
  1531. 'desc_inputs': [[64, 1]],
  1532. 'desc_bprop': [[64]]}),
  1533. ('Cast', {
  1534. 'block': P.Cast(),
  1535. 'desc_const': [mstype.int32],
  1536. 'desc_inputs': [[2, 3, 4, 5]],
  1537. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  1538. ('ExpandDims', {
  1539. 'block': P.ExpandDims(),
  1540. 'desc_const': [0],
  1541. 'desc_inputs': [[2, 2]],
  1542. 'desc_bprop': [[1, 2, 2]]}),
  1543. ('ExpandDims_1', {
  1544. 'block': P.ExpandDims(),
  1545. 'desc_const': [-1],
  1546. 'desc_inputs': [[2, 2]],
  1547. 'desc_bprop': [[2, 2, 1]]}),
  1548. ('Squeeze', {
  1549. 'block': P.Squeeze(2),
  1550. 'desc_inputs': [[3, 2, 1]],
  1551. 'desc_bprop': [[3, 2]]}),
  1552. ('Squeeze_0', {
  1553. 'block': P.Squeeze(),
  1554. 'desc_inputs': [[3, 1, 2, 1]],
  1555. 'desc_bprop': [[3, 2]]}),
  1556. ('Squeeze_1', {
  1557. 'block': P.Squeeze(),
  1558. 'desc_inputs': [[1, 1, 1, 1]],
  1559. 'desc_bprop': [1.0],
  1560. 'skip': ['backward']}),
  1561. ('Squeeze_2', {
  1562. 'block': P.Squeeze((2, 3)),
  1563. 'desc_inputs': [[3, 2, 1, 1]],
  1564. 'desc_bprop': [[3, 2]]}),
  1565. ('Size', {
  1566. 'block': P.Size(),
  1567. 'desc_inputs': [[2, 3, 5]],
  1568. 'skip': ['backward']}),
  1569. ('Tile_0', {
  1570. 'block': P.Tile(),
  1571. 'desc_const': [(1, 2)],
  1572. 'desc_inputs': [[64, 1]],
  1573. 'desc_bprop': [[64, 2]]}),
  1574. ('Tile_1', {
  1575. 'block': P.Tile(),
  1576. 'desc_const': [(1, 1)],
  1577. 'desc_inputs': [[64, 1]],
  1578. 'desc_bprop': [[64, 1]]}),
  1579. ('Tile_2', {
  1580. 'block': P.Tile(),
  1581. 'desc_const': [(2, 1, 1, 2)],
  1582. 'desc_inputs': [[2, 2, 2]],
  1583. 'desc_bprop': [[2, 2, 2, 4]]}),
  1584. ('ConcatV2_0', {
  1585. 'block': P.Concat(),
  1586. 'desc_inputs': [
  1587. (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  1588. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
  1589. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  1590. ('ConcatV2_1', {
  1591. 'block': P.Concat(axis=2),
  1592. 'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  1593. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
  1594. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  1595. ('ConcatV2_2', {
  1596. 'block': NetForConcat(),
  1597. 'desc_inputs': [[2, 2]],
  1598. 'desc_bprop': [[4, 2]]}),
  1599. ('ConcatV2_3', {
  1600. 'block': NetForConcat1(),
  1601. 'desc_inputs': [[2, 2], [2, 2]],
  1602. 'desc_bprop': [[4, 2]]}),
  1603. ('ConcatV2_4', {
  1604. 'block': P.Concat(axis=0),
  1605. 'desc_inputs': [
  1606. (Tensor(np.ones((3, 2, 3), np.float32)),
  1607. Tensor(np.ones((5, 2, 3), np.float32)),
  1608. Tensor(np.ones((6, 2, 3), np.float32)))],
  1609. 'desc_bprop': [[14, 2, 3]]}),
  1610. ('ConcatV2_5', {
  1611. 'block': P.Concat(axis=-1),
  1612. 'desc_inputs': [(Tensor(np.array([1], np.float32)),
  1613. Tensor(np.array([1], np.float32)),
  1614. Tensor(np.array([1], np.float32)))],
  1615. 'desc_bprop': [[3, ]]}),
  1616. ('Pack_0', {
  1617. 'block': NetForPackInput(P.Pack()),
  1618. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1619. 'desc_bprop': [[3, 2, 2]],
  1620. }),
  1621. ('Pack_1', {
  1622. 'block': NetForPackInput(P.Pack(axis=-2)),
  1623. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  1624. 'desc_bprop': [[3, 2, 3, 3]],
  1625. }),
  1626. ('Pack_2', {
  1627. 'block': NetForPackInput(P.Pack()),
  1628. 'desc_inputs': [[128, 128], [128, 128]],
  1629. 'desc_bprop': [[2, 128, 128]],
  1630. }),
  1631. ('Pack_3', {
  1632. 'block': NetForPackInput(P.Pack()),
  1633. 'desc_inputs': [[2, 2]],
  1634. 'desc_bprop': [[1, 2, 2]]}),
  1635. ('Unpack_0', {
  1636. 'block': NetForUnpackInput(P.Unpack(axis=0)),
  1637. 'desc_inputs': [[2, 4]],
  1638. 'desc_bprop': [[4], [4]],
  1639. }),
  1640. ('Unpack_1', {
  1641. 'block': NetForUnpackInput(P.Unpack(axis=-1)),
  1642. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  1643. 'desc_bprop': [[1], [1], [1]],
  1644. }),
  1645. ('Diag_1', {
  1646. 'block': P.Diag(),
  1647. 'desc_inputs': [[4]],
  1648. 'desc_bprop': [[4, 4]],
  1649. }),
  1650. ('Diag_2', {
  1651. 'block': P.Diag(),
  1652. 'desc_inputs': [[4, 4]],
  1653. 'desc_bprop': [[4, 4, 4, 4]],
  1654. }),
  1655. ('DiagPart_1', {
  1656. 'block': P.DiagPart(),
  1657. 'desc_inputs': [[4, 4]],
  1658. 'desc_bprop': [[4]],
  1659. }),
  1660. ('DiagPart_2', {
  1661. 'block': P.DiagPart(),
  1662. 'desc_inputs': [[4, 4, 4, 4]],
  1663. 'desc_bprop': [[4, 4]],
  1664. }),
  1665. ('SpaceToBatch_1', {
  1666. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  1667. 'desc_inputs': [[1, 3, 2, 2]],
  1668. 'desc_bprop': [[4, 3, 1, 1]],
  1669. }),
  1670. ('SpaceToBatch_2', {
  1671. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  1672. 'desc_inputs': [[1, 3, 2, 2]],
  1673. 'desc_bprop': [[4, 3, 2, 3]],
  1674. }),
  1675. ('BatchToSpace_1', {
  1676. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  1677. 'desc_inputs': [[4, 3, 1, 1]],
  1678. 'desc_bprop': [[1, 3, 2, 2]],
  1679. }),
  1680. ('BatchToSpace_2', {
  1681. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  1682. 'desc_inputs': [[4, 3, 1, 1]],
  1683. 'desc_bprop': [[1, 3, 2, 1]],
  1684. }),
  1685. ('UnsortedSegmentMin_1', {
  1686. 'block': P.UnsortedSegmentMin(),
  1687. 'desc_const': [2],
  1688. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  1689. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  1690. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  1691. ('BroadcastTo', {
  1692. 'block': P.BroadcastTo((2, 3)),
  1693. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
  1694. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
  1695. ('InTopK', {
  1696. 'block': P.InTopK(2),
  1697. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
  1698. Tensor(np.array([2, 1, 2]).astype(np.int32))],
  1699. 'skip': ['backward'],
  1700. }),
  1701. ('InplaceUpdate', {
  1702. 'block': P.InplaceUpdate((0, 2)),
  1703. 'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
  1704. Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
  1705. 'skip': ['backward'],
  1706. }),
  1707. ('ReverseSequence', {
  1708. 'block': P.ReverseSequence(1, 0),
  1709. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
  1710. Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1711. 'desc_bprop': [[3, 3]]}),
  1712. ('LinSpace', {
  1713. 'block': inner.LinSpace(),
  1714. 'desc_inputs': [Tensor([5, 5.5], mstype.float32),
  1715. Tensor(1, mstype.float32),
  1716. Tensor(10, mstype.float32),
  1717. Tensor(5, mstype.int32)],
  1718. 'skip': ['backward'],
  1719. }),
  1720. ('MatrixDiag', {
  1721. 'block': inner.MatrixDiag(),
  1722. 'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
  1723. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1724. 'skip': ['backward'],
  1725. }),
  1726. ('MatrixDiagPart', {
  1727. 'block': inner.MatrixDiagPart(),
  1728. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1729. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1730. 'skip': ['backward'],
  1731. }),
  1732. ('MatrixSetDiag', {
  1733. 'block': inner.MatrixSetDiag(),
  1734. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  1735. Tensor(np.arange(6).reshape(3, 2), mstype.float32),
  1736. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  1737. 'skip': ['backward'],
  1738. }),
  1739. ('TransShape', {
  1740. 'block': P.TransShape(),
  1741. 'desc_const': [(1, 12, 24, 24)],
  1742. 'desc_inputs': [[1, 3, 24, 24]],
  1743. 'desc_bprop': [[1, 12, 24, 24]],
  1744. }),
  1745. ('ParallelConcat', {
  1746. 'block': ParallelConcatNet(),
  1747. 'desc_inputs': [Tensor([[1, 2]], mstype.float32),
  1748. Tensor([[5, 6]], mstype.float32)],
  1749. 'skip': ['backward'],
  1750. }),
  1751. ]
  1752. test_case_other_ops = [
  1753. ('ScalarLog', {
  1754. 'block': F.scalar_log,
  1755. 'desc_const': [0.0],
  1756. 'desc_inputs': [],
  1757. 'desc_bprop': [1],
  1758. 'skip': ['backward']}),
  1759. ('BoundingBoxEncode', {
  1760. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  1761. 'desc_inputs': [[256, 4], [256, 4]],
  1762. 'desc_bprop': [[256, 4]],
  1763. 'skip': ['backward']}),
  1764. ('BoundingBoxDecode', {
  1765. '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)),
  1766. 'desc_inputs': [[256, 4], [256, 4]],
  1767. 'desc_bprop': [[256, 4]],
  1768. 'skip': ['backward']}),
  1769. ('GatherNd', {
  1770. 'block': P.GatherNd(),
  1771. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  1772. Tensor(np.ones((2, 4), np.int32))),
  1773. 'desc_bprop': [[2]]}),
  1774. ('ScatterNd', {
  1775. 'block': P.ScatterNd(),
  1776. 'desc_const': [(3, 3)],
  1777. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  1778. Tensor(np.ones((2,), np.int32))),
  1779. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  1780. ('TensorScatterUpdate', {
  1781. 'block': P.TensorScatterUpdate(),
  1782. 'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
  1783. Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1784. Tensor(np.ones([2, 5], np.float32) * 99)),
  1785. 'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
  1786. ('ScatterMaxUseLocking', {
  1787. 'block': ScatterMax(use_locking=True),
  1788. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1789. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  1790. 'skip': ['backward']}),
  1791. ('ScatterMax1d', {
  1792. 'block': ScatterMax(),
  1793. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1794. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  1795. 'skip': ['backward']}),
  1796. ('ScatterMaxF32', {
  1797. 'block': ScatterMax(),
  1798. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1799. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  1800. 'skip': ['backward']}),
  1801. ('ScatterMaxF16', {
  1802. 'block': ScatterMax(np.float16),
  1803. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1804. Tensor(np.ones([2, 2, 3], np.float16) * 99)),
  1805. 'skip': ['backward']}),
  1806. ('ScatterMaxI32', {
  1807. 'block': ScatterMax(np.int32),
  1808. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1809. Tensor(np.ones([2, 2, 3], np.int32) * 99)),
  1810. 'skip': ['backward']}),
  1811. ('ScatterMinUseLocking', {
  1812. 'block': ScatterMin(use_locking=True),
  1813. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1814. Tensor(np.ones([2, 3], np.float32))),
  1815. 'skip': ['backward']}),
  1816. ('ScatterMin1d', {
  1817. 'block': ScatterMin(),
  1818. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  1819. Tensor(np.ones([2, 3], np.float32))),
  1820. 'skip': ['backward']}),
  1821. ('ScatterMinF32', {
  1822. 'block': ScatterMin(),
  1823. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1824. Tensor(np.ones([2, 2, 3], np.float32))),
  1825. 'skip': ['backward']}),
  1826. ('ScatterMinF16', {
  1827. 'block': ScatterMin(np.float16),
  1828. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1829. Tensor(np.ones([2, 2, 3], np.float16))),
  1830. 'skip': ['backward']}),
  1831. ('ScatterMinI32', {
  1832. 'block': ScatterMin(np.int32),
  1833. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  1834. Tensor(np.ones([2, 2, 3], np.int32))),
  1835. 'skip': ['backward']}),
  1836. ('ScatterUpdate', {
  1837. 'block': ScatterUpdate((6,)),
  1838. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1839. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1840. 'skip': ['backward']}),
  1841. ('ScatterAddUseLocking', {
  1842. 'block': ScatterAdd((6,), use_locking=True),
  1843. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1844. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1845. 'skip': ['backward']}),
  1846. ('ScatterAdd', {
  1847. 'block': ScatterAdd((6,)),
  1848. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1849. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  1850. 'skip': ['backward']}),
  1851. ('ScatterAddScalar', {
  1852. 'block': ScatterAdd((6,)),
  1853. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1854. Tensor(np.array([2.0], np.float32))),
  1855. 'skip': ['backward']}),
  1856. ('ScatterAdd2d', {
  1857. 'block': ScatterAdd((3, 4)),
  1858. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1859. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1860. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1861. 'skip': ['backward']}),
  1862. ('ScatterAddF16', {
  1863. 'block': ScatterAdd((6,), np.float16),
  1864. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1865. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1866. 'skip': ['backward']}),
  1867. ('ScatterAddI8', {
  1868. 'block': ScatterAdd((6,), np.int8),
  1869. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1870. Tensor(np.array([2, 3, 4], np.int8))),
  1871. 'skip': ['backward']}),
  1872. ('ScatterAddI32', {
  1873. 'block': ScatterAdd((6,), np.int32),
  1874. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1875. Tensor(np.array([2, 3, 4], np.int32))),
  1876. 'skip': ['backward']}),
  1877. ('ScatterAddU8', {
  1878. 'block': ScatterAdd((6,), np.uint8),
  1879. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1880. Tensor(np.array([2, 3, 4], np.uint8))),
  1881. 'skip': ['backward']}),
  1882. ('ScatterMulUseLocking', {
  1883. 'block': ScatterMul((6,), use_locking=True),
  1884. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1885. Tensor(np.array([2.0], np.float32))),
  1886. 'skip': ['backward']}),
  1887. ('ScatterMulScalar', {
  1888. 'block': ScatterMul((6,)),
  1889. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1890. Tensor(np.array([2.0], np.float32))),
  1891. 'skip': ['backward']}),
  1892. ('ScatterMul2d', {
  1893. 'block': ScatterMul((3, 4)),
  1894. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1895. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1896. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1897. 'skip': ['backward']}),
  1898. ('ScatterMulF16', {
  1899. 'block': ScatterMul((6,), np.float16),
  1900. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1901. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1902. 'skip': ['backward']}),
  1903. ('ScatterMulI8', {
  1904. 'block': ScatterMul((6,), np.int8),
  1905. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1906. Tensor(np.array([2, 3, 4], np.int8))),
  1907. 'skip': ['backward']}),
  1908. ('ScatterMulI32', {
  1909. 'block': ScatterMul((6,), np.int32),
  1910. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1911. Tensor(np.array([2, 3, 4], np.int32))),
  1912. 'skip': ['backward']}),
  1913. ('ScatterMulU8', {
  1914. 'block': ScatterMul((6,), np.uint8),
  1915. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1916. Tensor(np.array([2, 3, 4], np.uint8))),
  1917. 'skip': ['backward']}),
  1918. ('ScatterDivUseLocking', {
  1919. 'block': ScatterDiv((6,), use_locking=True),
  1920. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1921. Tensor(np.array([2.0], np.float32))),
  1922. 'skip': ['backward']}),
  1923. ('ScatterDivScalar', {
  1924. 'block': ScatterDiv((6,)),
  1925. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1926. Tensor(np.array([2.0], np.float32))),
  1927. 'skip': ['backward']}),
  1928. ('ScatterDiv2d', {
  1929. 'block': ScatterDiv((3, 4)),
  1930. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1931. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1932. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1933. 'skip': ['backward']}),
  1934. ('ScatterDivF16', {
  1935. 'block': ScatterDiv((6,), np.float16),
  1936. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1937. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1938. 'skip': ['backward']}),
  1939. ('ScatterDivI8', {
  1940. 'block': ScatterDiv((6,), np.int8),
  1941. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1942. Tensor(np.array([2, 3, 4], np.int8))),
  1943. 'skip': ['backward']}),
  1944. ('ScatterDivU8', {
  1945. 'block': ScatterDiv((6,), np.uint8),
  1946. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1947. Tensor(np.array([2, 3, 4], np.uint8))),
  1948. 'skip': ['backward']}),
  1949. ('ScatterSubUseLocking', {
  1950. 'block': ScatterSub((6,), use_locking=True),
  1951. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1952. Tensor(np.array([2.0], np.float32))),
  1953. 'skip': ['backward']}),
  1954. ('ScatterSubScalar', {
  1955. 'block': ScatterSub((6,)),
  1956. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  1957. Tensor(np.array([2.0], np.float32))),
  1958. 'skip': ['backward']}),
  1959. ('ScatterSub2d', {
  1960. 'block': ScatterSub((3, 4)),
  1961. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  1962. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  1963. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  1964. 'skip': ['backward']}),
  1965. ('ScatterSubF16', {
  1966. 'block': ScatterSub((6,), np.float16),
  1967. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1968. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  1969. 'skip': ['backward']}),
  1970. ('ScatterSubI32', {
  1971. 'block': ScatterSub((6,), np.int32),
  1972. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1973. Tensor(np.array([2, 3, 4], np.int32))),
  1974. 'skip': ['backward']}),
  1975. ('ScatterSubI8', {
  1976. 'block': ScatterSub((6,), np.int8),
  1977. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1978. Tensor(np.array([2, 3, 4], np.int8))),
  1979. 'skip': ['backward']}),
  1980. ('ScatterSubU8', {
  1981. 'block': ScatterSub((6,), np.uint8),
  1982. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  1983. Tensor(np.array([1, 1, 0], np.uint8))),
  1984. 'skip': ['backward']}),
  1985. ('SmoothL1Loss', {
  1986. 'block': P.SmoothL1Loss(),
  1987. 'desc_inputs': [[256, 4], [256, 4]],
  1988. 'desc_bprop': [[256, 4]]}),
  1989. ('IOU', {
  1990. 'block': P.IOU(),
  1991. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  1992. 'desc_bprop': [[128, 256]]}),
  1993. ('Summary', {
  1994. 'block': SummaryNet(),
  1995. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  1996. Tensor(np.array([1.2]).astype(np.float32))],
  1997. 'skip': ['backward']}),
  1998. ('ConfusionMulGrad_1', {
  1999. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
  2000. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  2001. 'desc_bprop': [[3, 2], [2]],
  2002. 'skip': ['backward']}),
  2003. ('ConfusionMulGrad_2', {
  2004. 'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
  2005. 'desc_inputs': [[3, 2], [3, 2], [3, 2]],
  2006. 'desc_bprop': [[3, 2], [1, 2]],
  2007. 'skip': ['backward']}),
  2008. ('ConfusionMulGrad_3', {
  2009. 'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
  2010. 'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
  2011. 'desc_bprop': [[2, 3, 4], [1, 1, 1]],
  2012. 'skip': ['backward']}),
  2013. ('HistogramSummary', {
  2014. 'block': HistogramSummaryNet(),
  2015. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2016. Tensor(np.array([1.2]).astype(np.float32))],
  2017. 'skip': ['backward']}),
  2018. ('PopulationCount', {
  2019. 'block': P.PopulationCount(),
  2020. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.int16))],
  2021. 'skip': ['backward']}),
  2022. ]
  2023. test_case_quant_ops = [
  2024. ('AscendQuant_1', {
  2025. 'block': inner.AscendQuant(0.5, 0.0, False, "Round"),
  2026. 'desc_inputs': [Tensor(np.random.rand(1, 2, 4, 4), mstype.float32)],
  2027. 'skip': ['backward']}),
  2028. ('AscendQuant_2', {
  2029. 'block': inner.AscendQuant(80.0, 10.0, True, "Round"),
  2030. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2031. 'skip': ['backward']}),
  2032. ('AscendQuant_3', {
  2033. 'block': inner.AscendQuant(80.0, 0.0, False, "Floor"),
  2034. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2035. 'skip': ['backward']}),
  2036. ('AscendQuant_4', {
  2037. 'block': inner.AscendQuant(80.0, 0.0, False, "Ceil"),
  2038. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2039. 'skip': ['backward']}),
  2040. ('AscendQuant_5', {
  2041. 'block': inner.AscendQuant(80.0, 0.0, False, "Trunc"),
  2042. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2043. 'skip': ['backward']}),
  2044. ('AscendQuant_6', {
  2045. 'block': inner.AscendQuant(-80.0, 10.0, False, "Round"),
  2046. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2047. 'skip': ['backward']}),
  2048. ('AscendQuant_7', {
  2049. 'block': inner.AscendQuant(80.0, -10.0, False, "Round"),
  2050. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2051. 'skip': ['backward']}),
  2052. ('AscendQuant_8', {
  2053. 'block': inner.AscendQuant(80.0, 10.0, False, "Round"),
  2054. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
  2055. 'skip': ['backward']}),
  2056. ]
  2057. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops, test_case_quant_ops]
  2058. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  2059. # use -k to select certain testcast
  2060. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  2061. test_exec_case = test_case
  2062. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
  2063. @non_graph_engine
  2064. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  2065. def test_exec():
  2066. context.set_context(mode=context.GRAPH_MODE)
  2067. return test_exec_case
  2068. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  2069. def test_backward_exec():
  2070. context.set_context(mode=context.GRAPH_MODE)
  2071. return test_backward_exec_case
  2072. raise_set = [
  2073. ('Cast_Error', {
  2074. 'block': (P.Cast(), {'exception': TypeError}),
  2075. 'desc_const': [mstype.int32],
  2076. 'desc_inputs': ['wrong input'],
  2077. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  2078. ('Maximum_Error', {
  2079. 'block': (P.Maximum(), {'exception': TypeError}),
  2080. 'desc_const': [(1, 2, 3)],
  2081. 'desc_inputs': [[2, 3, 3, 5]],
  2082. 'desc_bprop': [[2, 3, 3, 5]]}),
  2083. ('Shape_error', {
  2084. 'block': (P.Shape(), {'exception': TypeError}),
  2085. 'desc_inputs': [(64, 1)],
  2086. 'desc_bprop': [[64]]}),
  2087. ('Flatten_Error', {
  2088. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  2089. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  2090. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  2091. ('ScatterNdUpdate', {
  2092. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  2093. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  2094. Tensor(np.ones((2, 2), np.float32)),
  2095. Tensor(np.ones((2,), np.float32))),
  2096. 'desc_bprop': [[2, 3]]}),
  2097. ('PReLU', {
  2098. 'block': (P.PReLU(), {'exception': ValueError}),
  2099. 'desc_inputs': [[2], [1]],
  2100. 'desc_bprop': [[1]]}),
  2101. ('SSIM', {
  2102. 'block': (nn.SSIM(), {'exception': ValueError}),
  2103. 'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
  2104. Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]}),
  2105. ('StridedSlice_0', {
  2106. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2107. 'desc_const': [(1, 2.2, 3), (3, 4, 5), (1, 1, 1)],
  2108. 'desc_inputs': [[4, 5, 6, 7]]}),
  2109. ('StridedSlice_1', {
  2110. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2111. 'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1)],
  2112. 'desc_inputs': [[4, 5, 6, 7]]}),
  2113. ('StridedSlice_2', {
  2114. 'block': (P.StridedSlice(), {'exception': ValueError}),
  2115. 'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1, 0)],
  2116. 'desc_inputs': [[4, 5, 6, 7]]}),
  2117. ]
  2118. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  2119. def test_check_exception():
  2120. return raise_set