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

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