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