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