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 105 kB

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