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

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