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