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

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