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

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