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 128 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
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
5 years ago
5 years ago
4 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224
  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. ('Ger', {
  805. 'block': P.Ger(),
  806. 'desc_inputs': [[3,], [4,]],
  807. 'desc_bprop': [[3, 4]]}),
  808. ('BitwiseAnd', {
  809. 'block': P.BitwiseAnd(),
  810. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  811. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  812. 'skip': ['backward']}),
  813. ('BitwiseAnd_1', {
  814. 'block': P.BitwiseAnd(),
  815. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  816. Tensor(np.array([1, 1, 1]), mstype.int16)],
  817. 'skip': ['backward']}),
  818. ('BitwiseOr', {
  819. 'block': P.BitwiseOr(),
  820. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  821. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  822. 'skip': ['backward']}),
  823. ('BitwiseOr_1', {
  824. 'block': P.BitwiseOr(),
  825. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  826. Tensor(np.array([1, 1, 1]), mstype.int16)],
  827. 'skip': ['backward']}),
  828. ('BitwiseXor', {
  829. 'block': P.BitwiseXor(),
  830. 'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
  831. Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
  832. 'skip': ['backward']}),
  833. ('BitwiseXor_1', {
  834. 'block': P.BitwiseXor(),
  835. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
  836. Tensor(np.array([1, 1, 1]), mstype.int16)],
  837. 'skip': ['backward']}),
  838. ('Neg', {
  839. 'block': P.Neg(),
  840. 'desc_inputs': [[1, 3, 4, 4]],
  841. 'desc_bprop': [[1, 3, 4, 4]]}),
  842. ('Sub', {
  843. 'block': P.Sub(),
  844. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  845. 'desc_bprop': [[2, 3, 3, 5]]}),
  846. ('Add', {
  847. 'block': P.Add(),
  848. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  849. 'desc_bprop': [[2, 3, 3, 5]]}),
  850. ('Mul0', {
  851. 'block': P.Mul(),
  852. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  853. 'desc_bprop': [[2, 3, 3, 5]]}),
  854. ('Mul1', {
  855. 'block': P.Mul(),
  856. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  857. 'desc_bprop': [[2, 3, 3, 5]]}),
  858. ('Mul2', {
  859. 'block': P.Mul(),
  860. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  861. 'desc_bprop': [[2, 3, 3, 5]],
  862. 'skip': ['backward']}),
  863. ('Mul3', {
  864. 'block': P.Mul(),
  865. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  866. 'desc_bprop': [[2, 3, 3, 5]],
  867. 'skip': ['backward']}),
  868. ('Mul4', {
  869. 'block': P.Mul(),
  870. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  871. 'desc_bprop': [[2, 3, 3, 5]],
  872. 'skip': ['backward']}),
  873. ('Add0', {
  874. 'block': P.Add(),
  875. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  876. 'desc_bprop': [[2, 3, 3, 5]]}),
  877. ('Add1', {
  878. 'block': P.Add(),
  879. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  880. 'desc_bprop': [[2, 3, 3, 5]],
  881. 'skip': ['backward']}),
  882. ('Add2', {
  883. 'block': P.Add(),
  884. 'desc_inputs': [[2, 3, 3, 5], [3, 5]],
  885. 'desc_bprop': [[2, 3, 3, 5]],
  886. 'skip': ['backward']}),
  887. ('Add3', {
  888. 'block': P.Add(),
  889. 'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
  890. 'desc_bprop': [[2, 3, 3, 5]],
  891. 'skip': ['backward']}),
  892. ('Add4', {
  893. 'block': P.Add(),
  894. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
  895. 'desc_bprop': [[2, 3, 3, 5]],
  896. 'skip': ['backward']}),
  897. ('Minimum', {
  898. 'block': P.Minimum(),
  899. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  900. 'desc_bprop': [[2, 3, 3, 5]]}),
  901. ('Pow_0', {
  902. 'block': P.Pow(),
  903. 'desc_const': [2.0],
  904. 'desc_inputs': [[2, 3, 3, 5]],
  905. 'desc_bprop': [[2, 3, 3, 5]]}),
  906. ('Pow_1', {
  907. 'block': P.Pow(),
  908. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  909. 'desc_bprop': [[2, 3, 3, 5]]}),
  910. ('Exp', {
  911. 'block': P.Exp(),
  912. 'desc_inputs': [[2, 3]],
  913. 'desc_bprop': [[2, 3]]}),
  914. ('Expm1', {
  915. 'block': P.Expm1(),
  916. 'desc_inputs': [[2, 3]],
  917. 'desc_bprop': [[2, 3]]}),
  918. ('Erf', {
  919. 'block': P.Erf(),
  920. 'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
  921. 'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
  922. ('Floor', {
  923. 'block': P.Floor(),
  924. 'desc_inputs': [[2, 512, 56, 56]],
  925. 'desc_bprop': [[2, 512, 56, 56]],
  926. 'skip': ['backward']}),
  927. ('Ceil', {
  928. 'block': P.Ceil(),
  929. 'desc_inputs': [[2, 512, 56, 56]],
  930. 'desc_bprop': [[2, 512, 56, 56]],
  931. 'skip': ['backward']}),
  932. ('IsNan', {
  933. 'block': P.IsNan(),
  934. 'desc_inputs': [Tensor(np.array([np.log(-1), 1, np.log(0)]).astype(np.float32))],
  935. 'desc_bprop': [],
  936. 'skip': ['backward']}),
  937. ('InplaceAdd', {
  938. 'block': InplaceAddNet(),
  939. 'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
  940. Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
  941. 'skip': ['backward']}),
  942. ('InplaceSub', {
  943. 'block': InplaceSubNet(),
  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. ('IsInf', {
  948. 'block': P.IsInf(),
  949. 'desc_inputs': [Tensor(np.array([np.log(-1), 1, np.log(0)]).astype(np.float32))],
  950. 'desc_bprop': []}),
  951. ('IsClose', {
  952. 'block': P.IsClose(rtol=1e-05, atol=1e-08, equal_nan=True),
  953. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(2.0, mstype.float32)],
  954. 'skip': ['backward']}),
  955. ('ACos', {
  956. 'block': P.ACos(),
  957. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  958. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  959. ('ACosGrad', {
  960. 'block': G.ACosGrad(),
  961. 'desc_inputs': [[2, 3], [2, 3]],
  962. 'skip': ['backward']}),
  963. ('Acosh', {
  964. 'block': P.Acosh(),
  965. 'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
  966. 'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
  967. ('AcoshGrad', {
  968. 'block': G.AcoshGrad(),
  969. 'desc_inputs': [[2, 3], [2, 3]],
  970. 'skip': ['backward']}),
  971. ('Sin', {
  972. 'block': P.Sin(),
  973. 'desc_inputs': [[2, 3]],
  974. 'desc_bprop': [[2, 3]]}),
  975. ('Asin', {
  976. 'block': P.Asin(),
  977. 'desc_inputs': [[2, 3]],
  978. 'desc_bprop': [[2, 3]]}),
  979. ('Asinh', {
  980. 'block': P.Asinh(),
  981. 'desc_inputs': [[3, 4, 5]],
  982. 'desc_bprop': [[3, 4, 5]]}),
  983. ('Tan', {
  984. 'block': P.Tan(),
  985. 'desc_inputs': [[2, 3]],
  986. 'desc_bprop': [[2, 3]]}),
  987. ('Reciprocal', {
  988. 'block': P.Reciprocal(),
  989. 'desc_inputs': [[2, 3, 3, 5]],
  990. 'desc_bprop': [[2, 3, 3, 5]]}),
  991. ('Minimum_0', {
  992. 'block': P.Minimum(),
  993. 'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
  994. 'desc_bprop': [[2, 3, 3, 5]]}),
  995. ('Maximum', {
  996. 'block': P.Maximum(),
  997. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  998. 'desc_bprop': [[2, 3, 3, 5]]}),
  999. ('Maximum_0', {
  1000. 'block': P.Maximum(),
  1001. 'desc_inputs': [[3, 5], [2, 3, 3, 5]],
  1002. 'desc_bprop': [[2, 3, 3, 5]]}),
  1003. ('MaximumGrad', {
  1004. 'block': G.MaximumGrad(),
  1005. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  1006. 'skip': ['backward']}),
  1007. ('MinimumGrad', {
  1008. 'block': G.MinimumGrad(),
  1009. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
  1010. 'skip': ['backward']}),
  1011. ('StridedSlice_00', {
  1012. 'block': P.StridedSlice(shrink_axis_mask=0),
  1013. 'desc_const': [(0, 1, 2, 1),
  1014. (2, 3, 3, 4),
  1015. (1, 1, 1, 2)],
  1016. 'desc_inputs': [[2, 3, 3, 5]],
  1017. 'desc_bprop': [[2, 2, 1, 3]],
  1018. 'skip': ['backward']}),
  1019. ('Slice_1', {
  1020. 'block': P.Slice(),
  1021. 'desc_const': [(0, 1, 2, 1),
  1022. (1, 1, 1, 2)],
  1023. 'desc_inputs': [[2, 3, 3, 5]],
  1024. 'desc_bprop': [[1, 1, 1, 2]]}),
  1025. ('StridedSliceGrad', {
  1026. 'block': G.StridedSliceGrad(),
  1027. 'desc_const': [(64, 1, 1024),
  1028. (0, 1, 0),
  1029. (64, 2, 1024),
  1030. (1, 1, 1)],
  1031. 'desc_inputs': [[64, 128, 1024]],
  1032. 'skip': ['backward']}),
  1033. ('Normal', {
  1034. 'block': NormalNet((3, 2, 4), 0),
  1035. 'desc_inputs': [Tensor(0.0, mstype.float32), Tensor(1.0, mstype.float32)],
  1036. 'skip': ['backward']}),
  1037. ('Laplace', {
  1038. 'block': LaplaceNet((3, 2, 4), 0),
  1039. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  1040. 'skip': ['backward']}),
  1041. ('LpNorm', {
  1042. 'block': P.LpNorm(axis=[0, 1], p=2, keep_dims=False),
  1043. 'desc_inputs': [Tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], mstype.float32)],
  1044. 'desc_bprop': [Tensor([1, 2], mstype.float32)]}),
  1045. ('Gamma', {
  1046. 'block': GammaNet((3, 2, 4), 0),
  1047. 'desc_inputs': [Tensor(1.0, mstype.float32), Tensor(1.0, mstype.float32)],
  1048. 'skip': ['backward']}),
  1049. ('Poisson', {
  1050. 'block': PoissonNet((3, 2, 4), 0),
  1051. 'desc_inputs': [Tensor(2.0, mstype.float32)],
  1052. 'skip': ['backward']}),
  1053. ('Uniform', {
  1054. 'block': UniformNet((3, 2, 4), 0),
  1055. 'desc_inputs': [Tensor(0.0, mstype.float32), Tensor(1.0, mstype.float32)],
  1056. 'skip': ['backward']}),
  1057. ('RandomChoiceWithMask', {
  1058. 'block': P.RandomChoiceWithMask(256),
  1059. 'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
  1060. 'desc_bprop': [[256, 4], [256, 4]],
  1061. 'skip': ['backward']}),
  1062. ('Lerp', {
  1063. 'block': P.Lerp(),
  1064. 'desc_inputs': [Tensor(np.array([1., 2., 3., 4.]).astype(np.float32)),
  1065. Tensor(np.array([10., 10., 10., 10.]).astype(np.float32)),
  1066. Tensor(0.5, mstype.float32)],
  1067. 'desc_bprop': [Tensor(np.array([1., 2., 3., 4.]).astype(np.float32))]}),
  1068. ('LessEqual', {
  1069. 'block': P.LessEqual(),
  1070. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  1071. Tensor(np.random.rand(4).astype(np.float16))],
  1072. 'skip': ['backward']}),
  1073. ('Less', {
  1074. 'block': P.Less(),
  1075. 'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
  1076. 'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
  1077. 'skip': ['backward']}),
  1078. ('RealDiv_0', {
  1079. 'block': P.RealDiv(),
  1080. 'desc_const': [Tensor(2048.0), Tensor(0.0)],
  1081. 'desc_inputs': [],
  1082. 'skip': ['backward']}),
  1083. ('RealDiv', {
  1084. 'block': P.RealDiv(),
  1085. 'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
  1086. 'desc_bprop': [[4]]}),
  1087. ('RealDiv_1', {
  1088. 'block': P.RealDiv(),
  1089. 'desc_inputs': [[512, 1024], [512, 1024]],
  1090. 'desc_bprop': [[512, 1024]]}),
  1091. ('FloorDiv', {
  1092. 'block': P.FloorDiv(),
  1093. 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
  1094. Tensor(np.random.rand(4).astype(np.float16))],
  1095. 'skip': ['backward']}),
  1096. ('FloorMod', {
  1097. 'block': P.FloorMod(),
  1098. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1099. 'desc_bprop': [[2, 3, 4, 5]]}),
  1100. ('TruncateDiv', {
  1101. 'block': P.TruncateDiv(),
  1102. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1103. 'desc_bprop': [[2, 3, 4, 5]]}),
  1104. ('TruncateMod', {
  1105. 'block': P.TruncateMod(),
  1106. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1107. 'desc_bprop': [[2, 3, 4, 5]]}),
  1108. ('identity', {
  1109. 'block': ops.functional.identity,
  1110. 'desc_inputs': [[2, 2]],
  1111. 'skip': ['backward']}),
  1112. ('MatMul_1', {
  1113. 'block': P.MatMul(transpose_a=False, transpose_b=False),
  1114. 'desc_inputs': [[1024, 160], [160, 1024]],
  1115. 'desc_bprop': [[1024, 1024]]}),
  1116. ('MatMul_2', {
  1117. 'block': P.MatMul(transpose_a=True, transpose_b=True),
  1118. 'desc_inputs': [[160, 1024], [1024, 160]],
  1119. 'desc_bprop': [[1024, 1024]]}),
  1120. ('Sub', {
  1121. 'block': P.Sub(),
  1122. 'desc_inputs': [[3], [3]],
  1123. 'desc_bprop': [[3]]}),
  1124. ('TruncatedNormal', {
  1125. 'block': P.TruncatedNormal(),
  1126. 'desc_const': [(1, 2, 3)],
  1127. 'desc_inputs': [],
  1128. 'skip': ['backward'],
  1129. 'add_fake_input': True}),
  1130. ('Select', {
  1131. 'block': P.Select(),
  1132. 'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
  1133. [2, 3], [2, 3]],
  1134. 'desc_bprop': [[2, 3]]}),
  1135. ('ClipByNorm_1', {
  1136. 'block': ClipByNorm(),
  1137. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1138. Tensor(np.array([0.01]).astype(np.float32))],
  1139. 'skip': ['backward']}),
  1140. ('ClipByNorm_2', {
  1141. 'block': ClipByNorm(axis=0),
  1142. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1143. Tensor(np.array([0.01]).astype(np.float32))],
  1144. 'skip': ['backward']}),
  1145. ('ClipByGlobalNorm', {
  1146. 'block': ClipByGlobalNorm(x=Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32)),
  1147. clip_norm=1.0, use_norm=None),
  1148. 'desc_inputs': [],
  1149. 'skip': ['backward']}),
  1150. ('Cdist', {
  1151. 'block': P.Cdist(p=2.0),
  1152. 'desc_inputs': [Tensor(np.array([[[1.0, 1.0], [2.0, 2.0]]]).astype(np.float32)),
  1153. Tensor(np.array([[[3.0, 3.0], [3.0, 3.0]]]).astype(np.float32))],
  1154. 'desc_bprop': [Tensor(np.array([[[1.0, 1.0], [2.0, 2.0]]]).astype(np.float32))]}),
  1155. ('CholeskyInverse', {
  1156. 'block': P.CholeskyInverse(upper=False),
  1157. '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))],
  1158. '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))]}),
  1159. ('Embedding_1', {
  1160. 'block': Embedding(vocab_size=10, embedding_size=3),
  1161. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1162. 'skip': ['backward']}),
  1163. ('Embedding_2', {
  1164. 'block': Embedding(vocab_size=10, embedding_size=3, padding_idx=2),
  1165. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1166. 'skip': ['backward']}),
  1167. ('EmbeddingLookup_1', {
  1168. 'block': EmbeddingLookup(vocab_size=10, embedding_size=3),
  1169. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1170. 'skip': ['backward']}),
  1171. ('EmbeddingLookup_2', {
  1172. 'block': EmbeddingLookup(vocab_size=10, embedding_size=3, max_norm=0.01),
  1173. 'desc_inputs': [Tensor(np.array([0, 2, 2, 7]).astype(np.int32))],
  1174. 'skip': ['backward']}),
  1175. ('Moments', {
  1176. 'block': Moments(axis=(), keep_dims=False),
  1177. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32))],
  1178. 'skip': ['backward']}),
  1179. ('NLLLoss', {
  1180. 'block': NLLLoss(reduction="mean"),
  1181. 'desc_inputs': [Tensor(np.random.rand(3, 16), mstype.float32),
  1182. Tensor(np.random.rand(3), mstype.int32),
  1183. Tensor(np.random.rand(16), mstype.float32)],
  1184. 'desc_bprop': [(Tensor(np.random.rand(1), mstype.float32), Tensor(np.random.rand(1), mstype.float32))]}),
  1185. ('BatchNorm3d', {
  1186. 'block': BatchNorm3d(num_features=3),
  1187. 'desc_inputs': [Tensor(np.random.rand(3, 3, 3, 5, 4).astype(np.float32))],
  1188. 'skip': ['backward']}),
  1189. ('Conv3D', {
  1190. 'block': Conv3D(out_channel=32, kernel_size=(4, 3, 3), mode=1, pad_mode='valid', pad=0,
  1191. stride=1, dilation=1, group=1, data_format="NCDHW"),
  1192. 'desc_inputs': [Tensor(np.random.random((16, 3, 10, 32, 32)).astype(np.float16)),
  1193. Tensor(np.random.random((32, 3, 4, 3, 3)).astype(np.float16))],
  1194. 'skip': ['backward']}),
  1195. ('Conv3DBackpropInput', {
  1196. 'block': Conv3DBackpropInput(input_shape=(16, 32, 13, 37, 33), out_channel=32, kernel_size=(4, 6, 2), mode=1,
  1197. pad_mode='valid', pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1198. 'desc_inputs': [Tensor(np.random.random((32, 32, 4, 6, 2)).astype(np.float16)),
  1199. Tensor(np.random.random((16, 32, 10, 32, 32)).astype(np.float16))],
  1200. 'skip': ['backward']}),
  1201. ('Conv3DBackpropFilter', {
  1202. 'block': Conv3DBackpropFilter(w_shape=(32, 32, 4, 6, 2), out_channel=32, kernel_size=(4, 6, 2), mode=1,
  1203. pad_mode='valid', pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1204. 'desc_inputs': [Tensor(np.random.random((16, 32, 13, 37, 33)).astype(np.float16)),
  1205. Tensor(np.random.random((16, 32, 10, 32, 32)).astype(np.float16))],
  1206. 'skip': ['backward']}),
  1207. ('Conv3DTranspose', {
  1208. 'block': Conv3DTranspose(in_channel=32, out_channel=3, kernel_size=(4, 6, 2), mode=1,
  1209. pad=0, stride=1, dilation=1, group=1, data_format="NCDHW"),
  1210. 'desc_inputs': [Tensor(np.random.random((32, 3, 10, 32, 32)).astype(np.float16)),
  1211. Tensor(np.random.random((3, 3, 4, 6, 2)).astype(np.float16))],
  1212. 'skip': ['backward']}),
  1213. ('CountNonZero', {
  1214. 'block': CountNonZero(axis=(), keep_dims=False, dtype=mstype.int32),
  1215. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4).astype(np.float32))],
  1216. 'skip': ['backward']}),
  1217. ('FakeQuantWithMinMaxVars', {
  1218. 'block': Q.FakeQuantWithMinMaxVars(num_bits=8, narrow_range=False),
  1219. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 5), mstype.float32),
  1220. Tensor(np.array([-6]), mstype.float32),
  1221. Tensor(np.array([6]), mstype.float32)],
  1222. 'desc_bprop': [Tensor(np.random.rand(3, 16, 5, 5), mstype.float32)]}),
  1223. ('FakeQuantWithMinMaxVarsPerChannel', {
  1224. 'block': Q.FakeQuantWithMinMaxVarsPerChannel(num_bits=8, narrow_range=False),
  1225. 'desc_inputs': [Tensor(np.random.rand(3, 16, 5, 4), mstype.float32),
  1226. Tensor(np.array([-6, -1, -2, -3]), mstype.float32),
  1227. Tensor(np.array([6, 1, 2, 3]), mstype.float32)],
  1228. 'desc_bprop': [Tensor(np.random.rand(3, 16, 5, 4), mstype.float32)]}),
  1229. ('Mish', {
  1230. 'block': Mish(),
  1231. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1232. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1233. ('SeLU', {
  1234. 'block': SeLU(),
  1235. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1236. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1237. ('MulNoNan', {
  1238. 'block': MulNoNan(),
  1239. 'desc_inputs': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32),
  1240. Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)],
  1241. 'desc_bprop': [Tensor(np.random.rand(3, 6, 16, 16), mstype.float32)]}),
  1242. ('Rank', {
  1243. 'block': P.Rank(),
  1244. 'desc_inputs': [[2, 3]],
  1245. 'skip': ['backward']}),
  1246. ('InvertPermutation', {
  1247. 'block': P.InvertPermutation(),
  1248. 'desc_const': [(0, 3, 1, 2)],
  1249. 'desc_inputs': [],
  1250. 'skip': ['backward']}),
  1251. ('Xdivy', {
  1252. 'block': P.Xdivy(),
  1253. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1254. 'desc_bprop': [[2, 3, 4, 5]]}),
  1255. ('Xlogy', {
  1256. 'block': P.Xlogy(),
  1257. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1258. 'desc_bprop': [[2, 3, 4, 5]]}),
  1259. ('SquaredDifference', {
  1260. 'block': P.SquaredDifference(),
  1261. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1262. 'desc_bprop': [[2, 3, 4, 5]]}),
  1263. ('Square', {
  1264. 'block': P.Square(),
  1265. 'desc_inputs': [[4]],
  1266. 'desc_bprop': [[4]]}),
  1267. ('LuSolve', {
  1268. 'block': P.LuSolve(),
  1269. 'desc_inputs': [Tensor(np.random.rand(3, 3), mstype.float32),
  1270. Tensor(np.random.rand(3, 3), mstype.float32),
  1271. Tensor(np.random.rand(3), mstype.int32)],
  1272. 'skip': ['backward']}),
  1273. ('Rsqrt', {
  1274. 'block': P.Rsqrt(),
  1275. 'desc_inputs': [[4]],
  1276. 'desc_bprop': [[4]]}),
  1277. ('Sqrt', {
  1278. 'block': P.Sqrt(),
  1279. 'desc_inputs': [[4]],
  1280. 'desc_bprop': [[4]]}),
  1281. ('RealDiv', {
  1282. 'block': P.RealDiv(),
  1283. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1284. 'desc_bprop': [[2, 3, 4, 5]]}),
  1285. ('IsFinite', {
  1286. 'block': P.IsFinite(),
  1287. 'desc_inputs': [Tensor(np.random.random((3, 4, 5)).astype(np.float32))],
  1288. 'desc_bprop': [Tensor(np.random.random((3, 4, 5)).astype(np.bool))]}),
  1289. ('Div', {
  1290. 'block': P.Div(),
  1291. 'desc_inputs': [[4, 5], [2, 3, 4, 5]],
  1292. 'desc_bprop': [[2, 3, 4, 5]]}),
  1293. ('Equal', {
  1294. 'block': P.Equal(),
  1295. 'desc_inputs': [[3, 4, 5], [4, 5]],
  1296. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1297. ('NotEqual', {
  1298. 'block': P.NotEqual(),
  1299. 'desc_inputs': [[4, 1], [2, 3, 4, 5]],
  1300. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1301. ('NotEqual_0', {
  1302. 'block': P.NotEqual(),
  1303. 'desc_inputs': [Tensor(np.array(1).astype(np.int32)), [2, 3, 4, 5]],
  1304. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
  1305. 'skip': ['backward']}),
  1306. ('ApproximateEqual', {
  1307. 'block': P.ApproximateEqual(),
  1308. 'desc_inputs': [[3, 4, 5], [3, 4, 5]],
  1309. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1310. ('Greater', {
  1311. 'block': P.Greater(),
  1312. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  1313. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1314. ('GreaterEqual', {
  1315. 'block': P.GreaterEqual(),
  1316. 'desc_inputs': [[2, 3, 4, 1], [4, 5]],
  1317. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
  1318. ('LogicalNot', {
  1319. 'block': P.LogicalNot(),
  1320. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
  1321. 'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
  1322. ('LogicalAnd', {
  1323. 'block': P.LogicalAnd(),
  1324. 'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
  1325. 'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
  1326. ('LogicalOr', {
  1327. 'block': P.LogicalOr(),
  1328. 'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
  1329. 'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
  1330. ('NpuAllocFloatStatus', {
  1331. 'block': P.NPUAllocFloatStatus(),
  1332. 'desc_inputs': [],
  1333. 'add_fack_input': True,
  1334. 'fack_input_type': np.float32,
  1335. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1336. 'skip': ['backward']}),
  1337. ('NpuGetFloatStatus', {
  1338. 'block': P.NPUGetFloatStatus(),
  1339. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  1340. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1341. 'skip': ['backward']}),
  1342. ('NpuClearFloatStatus', {
  1343. 'block': P.NPUClearFloatStatus(),
  1344. 'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
  1345. 'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
  1346. 'skip': ['backward']}),
  1347. ('CheckValid', {
  1348. 'block': P.CheckValid(),
  1349. 'desc_inputs': [[20000, 4], [3]],
  1350. 'desc_bprop': [[20000]],
  1351. 'skip': ['backward']}),
  1352. ('NMSWithMask', {
  1353. 'block': P.NMSWithMask(0.5),
  1354. 'desc_inputs': [[128, 5]],
  1355. 'desc_bprop': [[128, 5], [128], [128]],
  1356. 'skip': ['backward']}),
  1357. ('Abs', {
  1358. 'block': P.Abs(),
  1359. 'desc_inputs': [[4]],
  1360. 'desc_bprop': [[4]]}),
  1361. ('CumSum', {
  1362. 'block': CumSumNet(),
  1363. 'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
  1364. 'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
  1365. [1, 3, 7, 9]]).astype(np.float32))]}),
  1366. ('ReduceSum_3', {
  1367. 'block': P.ReduceSum(),
  1368. 'desc_const': [0],
  1369. 'desc_inputs': [[3, 2]],
  1370. 'desc_bprop': [[2]]}),
  1371. ('ReduceSum_4', {
  1372. 'block': P.ReduceSum(keep_dims=True),
  1373. 'desc_const': [0],
  1374. 'desc_inputs': [[3, 2]],
  1375. 'desc_bprop': [[1, 2]]}),
  1376. ('ReduceSum_5', {
  1377. 'block': P.ReduceSum(keep_dims=True),
  1378. 'desc_inputs': [[2, 3, 4]],
  1379. 'desc_bprop': [[1, 1, 1]]}),
  1380. ('ReduceSum_6', {
  1381. 'block': P.ReduceSum(),
  1382. 'desc_inputs': [[2, 3, 4]],
  1383. 'desc_bprop': [[1]]}),
  1384. ('Sum_0', {
  1385. 'block': P.ReduceSum(),
  1386. 'desc_const': [(1,)],
  1387. 'desc_inputs': [[3, 2]],
  1388. 'desc_bprop': [[3]]}),
  1389. ('Sum_1', {
  1390. 'block': P.ReduceSum(keep_dims=True),
  1391. 'desc_const': [(1,)],
  1392. 'desc_inputs': [[3, 2]],
  1393. 'desc_bprop': [[3, 1]]}),
  1394. ('Sum_2', {
  1395. 'block': P.ReduceSum(),
  1396. 'desc_const': [(0, 1)],
  1397. 'desc_inputs': [[3, 2]],
  1398. 'desc_bprop': [[1]]}),
  1399. ('Sum_3', {
  1400. 'block': P.ReduceSum(),
  1401. 'desc_const': [0],
  1402. 'desc_inputs': [[3, 2]],
  1403. 'desc_bprop': [[2]]}),
  1404. ('Sum_4', {
  1405. 'block': P.ReduceSum(keep_dims=True),
  1406. 'desc_const': [0],
  1407. 'desc_inputs': [[3, 2]],
  1408. 'desc_bprop': [[1, 2]]}),
  1409. ('Sum_5', {
  1410. 'block': P.ReduceSum(keep_dims=True),
  1411. 'desc_const': [()],
  1412. 'desc_inputs': [[2, 3, 4]],
  1413. 'desc_bprop': [[1, 1, 1]]}),
  1414. ('Sum_6', {
  1415. 'block': P.ReduceSum(),
  1416. 'desc_const': [()],
  1417. 'desc_inputs': [[2, 3, 4]],
  1418. 'desc_bprop': [[1]]}),
  1419. ('Sign', {
  1420. 'block': P.Sign(),
  1421. 'desc_inputs': [[3]],
  1422. 'desc_bprop': [[3]]}),
  1423. ('Round', {
  1424. 'block': P.Round(),
  1425. 'desc_inputs': [[3]],
  1426. 'desc_bprop': [[3]]}),
  1427. ('Atan2', {
  1428. 'block': P.Atan2(),
  1429. 'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
  1430. Tensor(np.array([1, 1]).astype(np.float32))],
  1431. 'desc_bprop': [[2]]}),
  1432. ('SquareSumAll', {
  1433. 'block': P.SquareSumAll(),
  1434. 'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
  1435. Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
  1436. 'desc_bprop': [Tensor(np.array(0.1).astype(np.float32)),
  1437. Tensor(np.array(0.1).astype(np.float32))]}),
  1438. ('Cos', {
  1439. 'block': P.Cos(),
  1440. 'desc_inputs': [[2, 3]],
  1441. 'desc_bprop': [[2, 3]]}),
  1442. ('ReduceAll', {
  1443. 'block': P.ReduceAll(),
  1444. 'desc_const': [1],
  1445. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  1446. 'desc_bprop': []}),
  1447. ('ReduceAny', {
  1448. 'block': P.ReduceAny(),
  1449. 'desc_const': [1],
  1450. 'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
  1451. 'desc_bprop': []}),
  1452. ('BesselI0', {
  1453. 'block': P.BesselI0(),
  1454. 'desc_inputs': [[2, 3]],
  1455. 'desc_bprop': [[2, 3]]}),
  1456. ('BesselI1', {
  1457. 'block': P.BesselI1(),
  1458. 'desc_inputs': [[2, 3]],
  1459. 'desc_bprop': [[2, 3]]}),
  1460. ('BesselI0e', {
  1461. 'block': P.BesselI0e(),
  1462. 'desc_inputs': [[2, 3]],
  1463. 'desc_bprop': [[2, 3]]}),
  1464. ('BesselI1e', {
  1465. 'block': P.BesselI1e(),
  1466. 'desc_inputs': [[2, 3]],
  1467. 'desc_bprop': [[2, 3]]}),
  1468. ('Atan', {
  1469. 'block': P.Atan(),
  1470. 'desc_inputs': [[2, 3]],
  1471. 'desc_bprop': [[2, 3]]}),
  1472. ('AtanGrad', {
  1473. 'block': G.AtanGrad(),
  1474. 'desc_inputs': [[2, 3], [2, 3]],
  1475. 'skip': ['backward']}),
  1476. ('Atanh', {
  1477. 'block': P.Atanh(),
  1478. 'desc_inputs': [[2, 3]],
  1479. 'desc_bprop': [[2, 3]]}),
  1480. ('Cosh', {
  1481. 'block': P.Cosh(),
  1482. 'desc_inputs': [[3, 4, 5]],
  1483. 'desc_bprop': [[3, 4, 5]]}),
  1484. ('Sinh', {
  1485. 'block': P.Sinh(),
  1486. 'desc_inputs': [[3, 4, 5]],
  1487. 'desc_bprop': [[3, 4, 5]]}),
  1488. ('Inv', {
  1489. 'block': P.Inv(),
  1490. 'desc_inputs': [[21, 9, 12, 5]],
  1491. 'desc_bprop': [[21, 9, 12, 5]]}),
  1492. ('Invert', {
  1493. 'block': P.Invert(),
  1494. 'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
  1495. 'desc_bprop': [],
  1496. 'skip': ['backward']}),
  1497. ('HistogramFixedWidth', {
  1498. 'block': P.HistogramFixedWidth(5),
  1499. 'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
  1500. 'desc_bprop': [],
  1501. 'skip': ['backward']}),
  1502. ('Mod', {
  1503. 'block': P.Mod(),
  1504. 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
  1505. 'desc_bprop': [[2, 3, 4, 5]]}),
  1506. ('IFMR', {
  1507. 'block': Q.IFMR(min_percentile=0.2, max_percentile=0.9, search_range=(1.0, 2.0),
  1508. search_step=1.0, with_offset=False),
  1509. 'desc_inputs': [[3, 4, 5], Tensor([0.1], mstype.float32), Tensor([0.9], mstype.float32),
  1510. Tensor(np.random.rand(4).astype(np.int32))],
  1511. 'desc_bprop': [],
  1512. 'skip': ['backward']}),
  1513. ('MatrixInverse', {
  1514. 'block': P.MatrixInverse(),
  1515. 'desc_inputs': [Tensor(np.array([[[-1, -2], [-3, -4]], [[5, 6], [7, 8]]]).astype(np.float32))],
  1516. 'desc_bprop': [Tensor(np.array([[[-1, -2], [-3, -4]], [[5, 6], [7, 8]]]).astype(np.float32))]}),
  1517. ('MatrixDeterminant', {
  1518. 'block': P.MatrixDeterminant(),
  1519. 'desc_inputs': [Tensor(np.array([[[-1, -2], [-3, -4]], [[5, 6], [7, 8]]]).astype(np.float32))],
  1520. 'desc_bprop': [Tensor(np.array([1.0, 2.0]).astype(np.float32))]}),
  1521. ('LogMatrixDeterminant', {
  1522. 'block': P.LogMatrixDeterminant(),
  1523. 'desc_inputs': [Tensor(np.array([[[-1, -2], [-3, -4]], [[5, 6], [7, 8]]]).astype(np.float32))],
  1524. 'desc_bprop': [(Tensor(np.array([1, 2]).astype(np.float32)), Tensor(np.array([1, 2]).astype(np.float32)))]}),
  1525. ('Erfinv', {
  1526. 'block': P.Erfinv(),
  1527. 'desc_inputs': [Tensor(np.array([0.1, 0.1, 0.1]).astype(np.float16))],
  1528. 'desc_bprop': [Tensor(np.array([1, 1, 1]).astype(np.float16))]}),
  1529. ('IndexAdd', {
  1530. 'block': IndexAdd(1),
  1531. 'desc_inputs': (Tensor(np.array([0, 1, 2]).astype(np.int32)),
  1532. Tensor(np.array([[0.5, 1.0, 1.5], [1.0, 1.5, 2.0], [2.0, 2.5, 3.0]]).astype(np.float32))),
  1533. 'desc_bprop': [Tensor(np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]).astype(np.float32))]}),
  1534. ('Addcdiv', {
  1535. 'block': P.Addcdiv(),
  1536. 'desc_inputs': [Tensor(np.array([1, 1, 1, 1]).astype(np.float32)),
  1537. Tensor(np.array([1, 2, 3, 4]).astype(np.float32)),
  1538. Tensor(np.array([4, 3, 2, 1]).astype(np.float32)),
  1539. Tensor(np.array(1).astype(np.float32))],
  1540. 'desc_bprop': [Tensor(np.array([1, 1, 1, 1]).astype(np.float32))]}),
  1541. ('Addcmul', {
  1542. 'block': P.Addcmul(),
  1543. 'desc_inputs': [Tensor(np.array([1, 1, 1]).astype(np.float32)),
  1544. Tensor(np.array([[1], [2], [3]]).astype(np.float32)),
  1545. Tensor(np.array([[1, 2, 3]]).astype(np.float32)),
  1546. Tensor(np.array(1).astype(np.float32))],
  1547. 'desc_bprop': [Tensor(np.array([[2, 3, 4], [3, 5, 7], [4, 7, 10]]).astype(np.float32))]}),
  1548. ('Real', {
  1549. 'block': P.Real(),
  1550. 'desc_inputs': [[2, 2]],
  1551. 'skip': ['backward']}),
  1552. ('Imag', {
  1553. 'block': P.Imag(),
  1554. 'desc_inputs': [[2, 2]],
  1555. 'skip': ['backward']}),
  1556. ('Conj', {
  1557. 'block': P.Real(),
  1558. 'desc_inputs': [[2, 2]],
  1559. 'skip': ['backward']}),
  1560. ]
  1561. test_case_nn_ops = [
  1562. ('CeLU', {
  1563. 'block': P.CeLU(),
  1564. 'desc_inputs': [[1, 2, 3]],
  1565. 'desc_bprop': [[1, 2, 3]]}),
  1566. ('BiasAdd', {
  1567. 'block': P.BiasAdd(),
  1568. 'desc_inputs': [[1, 3, 3, 3], [3]],
  1569. 'desc_bprop': [[1, 3, 3, 3]]}),
  1570. ('BiasAddGrad', {
  1571. 'block': G.BiasAddGrad(),
  1572. 'desc_inputs': [[1, 3, 3, 3]],
  1573. 'skip': ['backward']}),
  1574. ('GeLU', {
  1575. 'block': P.GeLU(),
  1576. 'desc_inputs': [[1, 3, 4, 4]],
  1577. 'desc_bprop': [[1, 3, 4, 4]]}),
  1578. ('GeLUGrad', {
  1579. 'block': G.GeLUGrad(),
  1580. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1581. 'desc_bprop': [[2, 2]],
  1582. 'skip': ['backward']}),
  1583. ('Tanh', {
  1584. 'block': P.Tanh(),
  1585. 'desc_inputs': [[1, 3, 4, 4]],
  1586. 'desc_bprop': [[1, 3, 4, 4]]}),
  1587. ('TanhGrad', {
  1588. 'block': G.TanhGrad(),
  1589. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1590. 'desc_bprop': [[1, 3, 4, 4]],
  1591. 'skip': ['backward']}),
  1592. ('ReLU', {
  1593. 'block': P.ReLU(),
  1594. 'desc_inputs': [[1, 3, 4, 4]],
  1595. 'desc_bprop': [[1, 3, 4, 4]]}),
  1596. ('ReLU6', {
  1597. 'block': P.ReLU6(),
  1598. 'desc_inputs': [[1, 3, 4, 4]],
  1599. 'desc_bprop': [[1, 3, 4, 4]]}),
  1600. ('ReLUV2', {
  1601. 'block': P.ReLUV2(),
  1602. 'desc_inputs': [[1, 3, 4, 4]],
  1603. 'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
  1604. ('ReLUGrad', {
  1605. 'block': G.ReluGrad(),
  1606. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1607. 'skip': ['backward']}),
  1608. ('Softplus', {
  1609. 'block': P.Softplus(),
  1610. 'desc_inputs': [[1, 3, 4, 4]],
  1611. 'desc_bprop': [[1, 3, 4, 4]]}),
  1612. ('SoftplusGrad', {
  1613. 'block': G.SoftplusGrad(),
  1614. 'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
  1615. 'skip': ['backward']}),
  1616. ('Elu', {
  1617. 'block': P.Elu(),
  1618. 'desc_inputs': [[2, 3, 4]],
  1619. 'desc_bprop': [[2, 3, 4]]}),
  1620. ('EluGrad', {
  1621. 'block': G.EluGrad(),
  1622. 'desc_inputs': [[2, 3, 4], [2, 3, 4]],
  1623. 'desc_bprop': [[2, 3, 4]],
  1624. 'skip': ['backward']}),
  1625. ('Sigmoid', {
  1626. 'block': P.Sigmoid(),
  1627. 'desc_inputs': [[1, 3, 4, 4]],
  1628. 'desc_bprop': [[1, 3, 4, 4]]}),
  1629. ('MaxPool', {
  1630. 'block': P.MaxPool(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1631. 'desc_inputs': [[100, 3, 28, 28]],
  1632. 'desc_bprop': [[100, 3, 14, 14]]}),
  1633. ('MaxPoolGrad', {
  1634. 'block': G.MaxPoolGrad(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1635. 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
  1636. 'desc_bprop': [[3, 4, 6, 6]],
  1637. 'skip': ['backward']}),
  1638. ('MaxPool3D', {
  1639. 'block': P.MaxPool3D(kernel_size=2, strides=2, pad_mode="VALID"),
  1640. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1641. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1642. ('MaxPool3D', {
  1643. 'block': P.MaxPool3D(kernel_size=4, strides=2, pad_mode="PAD", pad_list=2, ceil_mode=False),
  1644. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1645. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1646. ('MaxPool3D', {
  1647. 'block': P.MaxPool3D(kernel_size=4, strides=2, pad_mode="PAD", pad_list=2, ceil_mode=True),
  1648. 'desc_inputs': [[100, 3, 28, 28, 28]],
  1649. 'desc_bprop': [[100, 3, 14, 14, 14]]}),
  1650. ('MaxPool3DGrad', {
  1651. 'block': G.MaxPool3DGrad(kernel_size=2, strides=2, pad_mode="VALID"),
  1652. 'desc_inputs': [[3, 4, 6, 6, 6], [3, 4, 3, 3, 3], [3, 4, 3, 3, 3]],
  1653. 'desc_bprop': [[3, 4, 6, 6, 6]]}),
  1654. ('AvgPool', {
  1655. 'block': P.AvgPool(kernel_size=(2, 2), strides=(2, 2), pad_mode="VALID"),
  1656. 'desc_inputs': [[100, 3, 28, 28]],
  1657. 'desc_bprop': [[100, 3, 14, 14]]}),
  1658. ('AvgPool3D_1', {
  1659. 'block': P.AvgPool3D(kernel_size=2, strides=2, pad_mode="VALID"),
  1660. 'desc_inputs': [[10, 3, 28, 28, 28]],
  1661. 'desc_bprop': [[10, 3, 14, 14, 14]]}),
  1662. ('AvgPool3D_2', {
  1663. 'block': P.AvgPool3D(kernel_size=3, strides=2, pad_mode="PAD", pad=1),
  1664. 'desc_inputs': [[10, 3, 28, 31, 24]],
  1665. 'desc_bprop': [[10, 3, 14, 16, 12]]}),
  1666. ('MaxPoolWithArgmax', {
  1667. 'block': P.MaxPoolWithArgmax(kernel_size=2, strides=2),
  1668. 'desc_inputs': [[128, 32, 32, 64]],
  1669. 'desc_bprop': [[128, 32, 16, 32], ([128, 32, 16, 32], {'dtype': np.int32})]}),
  1670. ('SoftmaxCrossEntropyWithLogits', {
  1671. 'block': P.SoftmaxCrossEntropyWithLogits(),
  1672. 'desc_inputs': [[1, 10], [1, 10]],
  1673. 'desc_bprop': [[1], [1, 10]],
  1674. 'skip': ['backward_exec']}),
  1675. ('Flatten', {
  1676. 'block': P.Flatten(),
  1677. 'desc_inputs': [[128, 32, 32, 64]],
  1678. 'desc_bprop': [[128, 65536]]}),
  1679. ('LogSoftmax', {
  1680. 'block': P.LogSoftmax(),
  1681. 'desc_inputs': [[64, 2]],
  1682. 'desc_bprop': [[64, 2]]}),
  1683. ('LogSoftmaxGrad', {
  1684. 'block': G.LogSoftmaxGrad(),
  1685. 'desc_inputs': [[16, 1234], [16, 1234]],
  1686. 'desc_bprop': [[64, 2]],
  1687. 'skip': ['backward']}),
  1688. ('L2Normalize', {
  1689. 'block': P.L2Normalize(),
  1690. 'desc_inputs': [[2, 2]],
  1691. 'desc_bprop': [[2, 2]]}),
  1692. ('L2NormalizeGrad', {
  1693. 'block': G.L2NormalizeGrad(),
  1694. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  1695. 'desc_bprop': [[2, 2]],
  1696. 'skip': ['backward']}),
  1697. ('LayerNorm', {
  1698. 'block': P.LayerNorm(),
  1699. 'desc_inputs': [[2, 16], [16], [16]],
  1700. 'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
  1701. ('LayerNormGrad', {
  1702. 'block': G.LayerNormGrad(),
  1703. 'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
  1704. 'desc_bprop': [[2, 16], [16], [16]],
  1705. 'skip': ['backward']}),
  1706. ('BatchNorm', {
  1707. 'block': P.BatchNorm(),
  1708. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1709. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1710. 'skip': []}),
  1711. ('BatchNormGrad', {
  1712. 'block': G.BatchNormGrad(),
  1713. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64], [64]],
  1714. 'desc_bprop': [[128, 64, 32, 32], [64], [64]],
  1715. 'skip': ['backward']}),
  1716. ('SyncBatchNorm', {
  1717. 'block': inner.SyncBatchNorm(),
  1718. 'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1719. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1720. 'skip': []}),
  1721. ('SyncBatchNormGrad', {
  1722. 'block': G.SyncBatchNormGrad(),
  1723. 'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
  1724. 'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
  1725. 'skip': ['backward']}),
  1726. ('TopK', {
  1727. 'block': P.TopK(),
  1728. 'desc_const': [5],
  1729. 'desc_inputs': [[20, 20, 10]],
  1730. 'desc_bprop': [[20, 20, 5]],
  1731. 'skip': ['backward']}),
  1732. ('Sort', {
  1733. 'block': P.Sort(),
  1734. 'desc_inputs': [[2, 3, 4]],
  1735. 'desc_bprop': [[2, 3, 4], ([2, 3, 4], {'dtype': np.int32})]}),
  1736. ('GatherV2_0', {
  1737. 'block': P.Gather(),
  1738. 'desc_const': [0],
  1739. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1740. 'desc_bprop': [[2, 1, 2]]}),
  1741. ('GatherV2_1', {
  1742. 'block': P.Gather(),
  1743. 'desc_const': [2],
  1744. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1745. 'desc_bprop': [[3, 1, 2]]}),
  1746. ('GatherV2_2', {
  1747. 'block': P.Gather(),
  1748. 'desc_const': [0],
  1749. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1750. 'desc_bprop': [[3, 2, 1, 3]]}),
  1751. ('GatherV2_3', {
  1752. 'block': P.Gather(),
  1753. 'desc_const': [2],
  1754. 'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1755. 'desc_bprop': [[3, 1, 3, 2]]}),
  1756. ('GatherV2_4', {
  1757. 'block': P.Gather(),
  1758. 'desc_const': [1],
  1759. 'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
  1760. 'desc_bprop': [[32, 1, 1024]]}),
  1761. ('GatherV2_5', {
  1762. 'block': P.Gather(),
  1763. 'desc_const': [-1],
  1764. 'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
  1765. 'desc_bprop': [[3, 1, 2]]}),
  1766. ('GatherV2_6', {
  1767. 'block': P.Gather(),
  1768. 'desc_const': [0],
  1769. 'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
  1770. 'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
  1771. ('SparseGatherV2_0', {
  1772. 'block': P.SparseGatherV2(),
  1773. 'desc_const': [0],
  1774. 'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
  1775. 'desc_bprop': [[2, 1, 2]]}),
  1776. ('Range', {
  1777. 'block': inner.Range(1.0, 5.0),
  1778. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  1779. 'desc_bprop': [[10]]}),
  1780. ('UnsortedSegmentSum', {
  1781. 'block': P.UnsortedSegmentSum(),
  1782. 'desc_const': [1280],
  1783. 'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
  1784. 'desc_bprop': [[1280, 1024]]}),
  1785. ('UnsortedSegmentSum_1', {
  1786. 'block': P.UnsortedSegmentSum(),
  1787. 'desc_const': [4],
  1788. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
  1789. 'desc_bprop': [[4, 1, 3]]}),
  1790. ('UnsortedSegmentMin', {
  1791. 'block': P.UnsortedSegmentMin(),
  1792. 'desc_const': [4],
  1793. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1794. 'desc_bprop': [[4, 2, 1, 3]]}),
  1795. ('UnsortedSegmentMax', {
  1796. 'block': P.UnsortedSegmentMax(),
  1797. 'desc_const': [4],
  1798. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
  1799. 'desc_bprop': [[4, 2, 1, 3]]}),
  1800. ('UnsortedSegmentProd', {
  1801. 'block': P.UnsortedSegmentProd(),
  1802. 'desc_const': [4],
  1803. 'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([0, 1, 0]).astype(np.int32))],
  1804. 'desc_bprop': [[4, 2, 1, 3]]}),
  1805. ('DropoutGenMask', {
  1806. 'block': P.DropoutGenMask(),
  1807. 'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
  1808. 'desc_inputs': [],
  1809. 'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
  1810. 'skip': ['backward']}),
  1811. ('DropoutDoMask', {
  1812. 'block': P.DropoutDoMask(),
  1813. 'desc_const': [Tensor(0.5)],
  1814. 'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
  1815. 'desc_bprop': [[64, 12, 128, 128]]}),
  1816. ('Dropout', {
  1817. 'block': nn.Dropout(0.5),
  1818. 'desc_inputs': [[64, 12, 128, 128]],
  1819. 'desc_bprop': [[64, 12, 128, 128]]}),
  1820. ('ReduceMean0', {
  1821. 'block': P.ReduceMean(),
  1822. 'desc_const': [(2,)],
  1823. 'desc_inputs': [[3, 2, 2]],
  1824. 'desc_bprop': [[3, 2]]}),
  1825. ('ReduceMean1', {
  1826. 'block': P.ReduceMean(),
  1827. 'desc_const': [2],
  1828. 'desc_inputs': [[3, 2, 2]],
  1829. 'desc_bprop': [[3, 2]]}),
  1830. ('All', {
  1831. 'block': P.ReduceAll(),
  1832. 'desc_const': [(1,)],
  1833. 'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
  1834. 'desc_bprop': [[3]],
  1835. 'skip': ['backward']}),
  1836. ('DescConst', {
  1837. 'block': Tensor(np.array([2], np.float32)),
  1838. 'desc_inputs': [],
  1839. 'desc_bprop': [[1]],
  1840. 'skip': ['backward'],
  1841. 'add_fake_input': True}),
  1842. ('Fill', {
  1843. 'block': P.Fill(),
  1844. 'desc_const': [mstype.float32, (2, 3), 1.0],
  1845. 'desc_inputs': [],
  1846. 'desc_bprop': [[2, 3]],
  1847. 'skip': ['backward'],
  1848. 'add_fake_input': True}),
  1849. ('OnesLike', {
  1850. 'block': P.OnesLike(),
  1851. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1852. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1853. }),
  1854. ('ZerosLike', {
  1855. 'block': P.ZerosLike(),
  1856. 'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  1857. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
  1858. }),
  1859. ('Softmax', {
  1860. 'block': P.Softmax(),
  1861. 'desc_inputs': [[5, 5]],
  1862. 'desc_bprop': [[5, 5]]}),
  1863. ('Softsign', {
  1864. 'block': P.Softsign(),
  1865. 'desc_inputs': [[5, 5]],
  1866. 'desc_bprop': [[5, 5]]}),
  1867. ('DepthwiseConv2dNative_1', {
  1868. 'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
  1869. 'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
  1870. 'desc_bprop': [[10, 32, 16, 16]]}),
  1871. ('DepthwiseConv2dNative_2', {
  1872. 'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
  1873. 'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
  1874. 'desc_bprop': [[2592, 2048, 4, 4]]}),
  1875. ('SigmoidCrossEntropyWithLogits', {
  1876. 'block': P.SigmoidCrossEntropyWithLogits(),
  1877. 'desc_inputs': [[128, 10], [128, 10]],
  1878. 'desc_bprop': [[128, 10]]}),
  1879. ('Pad', {
  1880. 'block': P.Pad(((1, 2), (2, 3))),
  1881. 'desc_inputs': [[7, 7]],
  1882. 'desc_bprop': [[10, 12]]}),
  1883. ('BinaryCrossEntropy', {
  1884. 'block': P.BinaryCrossEntropy(),
  1885. 'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
  1886. 'desc_bprop': []}),
  1887. ('SparseApplyAdagrad', {
  1888. 'block': SparseApplyAdagradNet(),
  1889. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1890. 'desc_bprop': [[3, 3], [3, 3]],
  1891. 'skip': ['backward']}),
  1892. ('SparseApplyAdagradV2', {
  1893. 'block': SparseApplyAdagradV2Net(),
  1894. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1895. 'skip': ['backward']}),
  1896. ('SparseApplyFtrl', {
  1897. 'block': SparseApplyFtrlNet(),
  1898. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1899. 'skip': ['backward']}),
  1900. ('SparseApplyFtrlV2', {
  1901. 'block': SparseApplyFtrlV2Net(),
  1902. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1903. 'skip': ['backward']}),
  1904. ('ApplyProximalAdagrad', {
  1905. 'block': ApplyProximalAdagradNet(),
  1906. 'desc_inputs': [[3, 3]],
  1907. 'skip': ['backward']}),
  1908. ('SparseApplyProximalAdagrad', {
  1909. 'block': SparseApplyProximalAdagradNet(),
  1910. 'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
  1911. 'skip': ['backward']}),
  1912. ('ApplyAdaMax', {
  1913. 'block': ApplyAdaMaxNet(),
  1914. 'desc_inputs': [[3, 3]],
  1915. 'skip': ['backward']}),
  1916. ('ApplyAdadelta', {
  1917. 'block': ApplyAdadeltaNet(),
  1918. 'desc_inputs': [[3, 3]],
  1919. 'skip': ['backward']}),
  1920. ('ApplyAdagrad', {
  1921. 'block': ApplyAdagradNet(),
  1922. 'desc_inputs': [[3, 3]],
  1923. 'skip': ['backward']}),
  1924. ('ApplyAdagradV2', {
  1925. 'block': ApplyAdagradV2Net(),
  1926. 'desc_inputs': [[3, 3]],
  1927. 'skip': ['backward']}),
  1928. ('ApplyAddSign', {
  1929. 'block': ApplyAddSignNet(),
  1930. 'desc_inputs': [[3, 3]],
  1931. 'skip': ['backward']}),
  1932. ('ApplyPowerSign', {
  1933. 'block': ApplyPowerSignNet(),
  1934. 'desc_inputs': [[3, 3]],
  1935. 'skip': ['backward']}),
  1936. ('ApplyGradientDescent', {
  1937. 'block': ApplyGradientDescentNet(),
  1938. 'desc_inputs': [[3, 3]],
  1939. 'skip': ['backward']}),
  1940. ('ApplyProximalGradientDescent', {
  1941. 'block': ApplyProximalGradientDescentNet(),
  1942. 'desc_inputs': [[3, 3]],
  1943. 'skip': ['backward']}),
  1944. ('Flatten_1', {
  1945. 'block': NetForFlatten(),
  1946. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1947. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1948. 'skip': ['backward']}),
  1949. ('Flatten_2', {
  1950. 'block': NetForFlatten(),
  1951. 'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
  1952. 'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
  1953. 'skip': ['backward']}),
  1954. ('Flatten_3', {
  1955. 'block': NetForFlattenComposed(),
  1956. 'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
  1957. 'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
  1958. 'skip': []}),
  1959. ('ArgmaxNet', {
  1960. 'block': ArgmaxNet(),
  1961. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1962. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1963. 'skip': ['backward']}),
  1964. ('ArgminNet', {
  1965. 'block': ArgminNet(),
  1966. 'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1967. 'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
  1968. 'skip': ['backward']}),
  1969. ('StridedSliceNet', {
  1970. 'block': StridedSliceNet(),
  1971. 'desc_inputs': [[6, 7, 8, 9, 10]],
  1972. 'skip': ['backward']}),
  1973. ('OneHot', {
  1974. 'block': P.OneHot(),
  1975. 'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
  1976. 'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
  1977. 'desc_bprop': [[1, 3]]}),
  1978. ('ReduceProd_0', {
  1979. 'block': P.ReduceProd(),
  1980. 'desc_const': [0],
  1981. 'desc_inputs': [[3, 2]],
  1982. 'desc_bprop': [[2]]}),
  1983. ('ReduceProd_1', {
  1984. 'block': P.ReduceProd(keep_dims=True),
  1985. 'desc_const': [0],
  1986. 'desc_inputs': [[3, 2]],
  1987. 'desc_bprop': [[1, 2]]}),
  1988. ('CumProd', {
  1989. 'block': P.CumProd(),
  1990. 'desc_const': [0],
  1991. 'desc_inputs': [[3, 2]],
  1992. 'desc_bprop': [[3, 2]]}),
  1993. ('Cummin', {
  1994. 'block': inner.Cummin(axis=0),
  1995. 'desc_inputs': [[1, 3, 3, 3]],
  1996. 'skip': ['backward']}),
  1997. ('ApplyFtrl', {
  1998. 'block': ApplyFtrlNet(),
  1999. 'desc_inputs': [[3, 3]],
  2000. 'desc_bprop': [3, 3],
  2001. 'skip': ['backward']}),
  2002. ('ApplyRMSProp', {
  2003. 'block': ApplyRMSNet(),
  2004. 'desc_inputs': [[3, 3]],
  2005. 'desc_bprop': [3, 3],
  2006. 'skip': ['backward']}),
  2007. ('ApplyCenteredRMSProp', {
  2008. 'block': P.ApplyCenteredRMSProp(),
  2009. 'desc_const': [0.9, 0.0, 1e-10, 0.001],
  2010. 'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
  2011. Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
  2012. 'desc_bprop': [1],
  2013. 'skip': ['backward']}),
  2014. ('CTCLoss', {
  2015. 'block': P.CTCLoss(),
  2016. 'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
  2017. Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
  2018. Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
  2019. Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
  2020. 'desc_bprop': [[4], [6, 4, 6]]}),
  2021. ('CTCGreedyDecoder', {
  2022. 'block': CTCGreedyDecoderNet(),
  2023. 'desc_inputs': [[2, 2, 3], Tensor(np.array([2, 2]).astype(np.int32))],
  2024. 'skip': ['backward']}),
  2025. ('L2Loss_1', {
  2026. 'block': P.L2Loss(),
  2027. 'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
  2028. 'desc_bprop': []}),
  2029. ('L2Loss_2', {
  2030. 'block': P.L2Loss(),
  2031. 'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
  2032. 'desc_bprop': []}),
  2033. ('SoftMarginLoss', {
  2034. 'block': P.SoftMarginLoss(reduction="none"),
  2035. 'desc_inputs': [Tensor(np.array([[0.3, 0.7], [0.5, 0.5]]).astype(np.float32)),
  2036. Tensor(np.array([[-1, 1], [1, -1]]).astype(np.float32))],
  2037. 'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.float32))]}),
  2038. ('BCEWithLogitsLoss', {
  2039. 'block': P.BCEWithLogitsLoss(),
  2040. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  2041. 'desc_bprop': []}),
  2042. ('ResizeBilinear', {
  2043. 'block': P.ResizeBilinear((5, 5)),
  2044. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
  2045. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
  2046. ('ResizeBilinearGrad', {
  2047. 'block': G.ResizeBilinearGrad(),
  2048. 'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  2049. 'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
  2050. 'skip': ['backward']}),
  2051. ('ROIAlign', {
  2052. 'block': P.ROIAlign(7, 7, 0.03125, 2),
  2053. 'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
  2054. 'desc_bprop': [[1024, 256, 7, 7]]}),
  2055. ('ROIAlignGrad', {
  2056. 'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
  2057. 'desc_inputs': [[1, 1, 2, 2], [1, 5]],
  2058. 'desc_bprop': [[1, 1, 2, 2]],
  2059. 'skip': ['backward']}),
  2060. ('LARSUpdate', {
  2061. 'block': P.LARSUpdate(1e-05, 0.001, False),
  2062. 'desc_const': [0.0, 0.001],
  2063. 'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
  2064. 'desc_bprop': [3, 3],
  2065. 'skip': ['backward']}),
  2066. ('SGD', {
  2067. 'block': P.SGD(0.0, 0.0, False),
  2068. 'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
  2069. 'desc_bprop': [3, 3],
  2070. 'skip': ['backward']}),
  2071. ('BinaryCrossEntropy', {
  2072. 'block': P.BinaryCrossEntropy(),
  2073. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  2074. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
  2075. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  2076. 'desc_bprop': []}),
  2077. ('BinaryCrossEntropyGrad', {
  2078. 'block': G.BinaryCrossEntropyGrad(),
  2079. 'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
  2080. Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
  2081. Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
  2082. 'desc_bprop': [],
  2083. 'skip': ['backward']}),
  2084. ('DataFormatDimMap', {
  2085. 'block': P.DataFormatDimMap(),
  2086. 'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
  2087. 'desc_bprop': [],
  2088. 'skip': ['backward']}),
  2089. ('MaxPoolGradGrad', {
  2090. 'block': G.MaxPoolGradGrad(),
  2091. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  2092. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  2093. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16)],
  2094. 'desc_bprop': [],
  2095. 'skip': ['backward']}),
  2096. ('MaxPoolGradGradWithArgmax', {
  2097. 'block': G.MaxPoolGradGradWithArgmax(),
  2098. 'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  2099. Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
  2100. Tensor(np.zeros((1, 1, 2, 2)), mstype.uint16)],
  2101. 'desc_bprop': [],
  2102. 'skip': ['backward']}),
  2103. ('Roll', {
  2104. 'block': nn.Roll(shift=[1, -2], axis=[0, 1]),
  2105. 'desc_inputs': [Tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]], mstype.float32)],
  2106. 'desc_bprop': [Tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]], mstype.float32)]}),
  2107. ('SoftShrink', {
  2108. 'block': P.SoftShrink(),
  2109. 'desc_inputs': [Tensor(np.array([[0.5297, 0.7871, 1.1754], [0.7836, 0.6218, -1.1542]]), mstype.float32)],
  2110. 'desc_bprop': [Tensor(np.array([[0, 0.4, 1], [1, 2, 4]]), mstype.float32)]}),
  2111. ('SoftShrinkGrad', {
  2112. 'block': G.SoftShrinkGrad(),
  2113. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  2114. Tensor(np.array([[-3, -2, 0], [1, 2, 4]]), mstype.float16)],
  2115. 'desc_bprop': [],
  2116. 'skip': ['backward']}),
  2117. ('HSigmoidGrad', {
  2118. 'block': G.HSigmoidGrad(),
  2119. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  2120. Tensor(np.array([[-4, -3, -2], [1, 2, 4]]), mstype.float16)],
  2121. 'skip': ['backward']}),
  2122. ('HSigmoid', {
  2123. 'block': P.HSigmoid(),
  2124. 'desc_inputs': [Tensor(np.array([[-4, 4, 1]]), mstype.float32)],
  2125. 'desc_bprop': [Tensor(np.array([[0, 1, 0.6666]]), mstype.float32)],
  2126. 'skip': ['backward']}),
  2127. ('HardShrink', {
  2128. 'block': P.HShrink(),
  2129. 'desc_inputs': [Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mstype.float32)],
  2130. 'desc_bprop': [],
  2131. 'skip': ['backward']}),
  2132. ('SparseApplyAdadelta', {
  2133. 'block': SparseApplyAdadeltaNet(1e-6),
  2134. 'desc_inputs': [Tensor(np.random.rand(3, 3), mstype.float32),
  2135. Tensor(np.ones((3,)), mstype.int32)],
  2136. 'skip': ['backward']}),
  2137. ('HShrinkGrad', {
  2138. 'block': G.HShrinkGrad(),
  2139. 'desc_inputs': [Tensor(np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), mstype.float16),
  2140. Tensor(np.array([[-4, -3, -2], [1, 2, 4]]), mstype.float16)],
  2141. 'skip': ['backward']}),
  2142. ('ApplyAdagradDA', {
  2143. 'block': ApplyAdagradDANet(),
  2144. 'desc_inputs': [Tensor(np.array([[0.3, 0.4], [0.1, 0.2]]).astype(np.float32)),
  2145. Tensor(0.001, mstype.float32),
  2146. Tensor(0.001, mstype.float32),
  2147. Tensor(0.001, mstype.float32),
  2148. Tensor(2, mstype.int32)],
  2149. 'desc_bprop': [],
  2150. 'skip': ['backward']}),
  2151. ('ApplyAdamWithAmsgrad', {
  2152. 'block': ApplyAdamWithAmsgradNet(),
  2153. 'desc_inputs': [Tensor(0.3, mstype.float32),
  2154. Tensor(0.3, mstype.float32),
  2155. Tensor(0.3, mstype.float32),
  2156. Tensor(np.array([[0.3, 0.2], [0.4, 0.1]]).astype(np.float32))],
  2157. 'desc_bprop': [],
  2158. 'skip': ['backward']}),
  2159. ('SparseApplyRMSProp', {
  2160. 'block': SparseApplyRMSPropNet(0.2, 0.01, 1e-6),
  2161. 'desc_inputs': [Tensor(0.01, mstype.float32),
  2162. Tensor(np.array([[0.3, 0.7], [0.1, 0.8]]).astype(np.float32)),
  2163. Tensor(np.array([0, 1], dtype=np.int32))],
  2164. 'skip': ['backward']}),
  2165. ('ApplyKerasMomentum', {
  2166. 'block': ApplyKerasMomentumNet(),
  2167. 'desc_inputs': [Tensor(0.001, mstype.float32),
  2168. Tensor(np.array([[0.3, 0.2], [0.4, 0.1]]).astype(np.float32)),
  2169. Tensor(0.99, mstype.float32)],
  2170. 'skip': ['backward']}),
  2171. ('GridSampler3D', {
  2172. 'block': P.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=False),
  2173. 'desc_inputs': [Tensor(np.arange(32).reshape((2, 2, 2, 2, 2)).astype(np.float32)),
  2174. Tensor(np.arange(-0.2, 1, 0.1).reshape((2, 2, 1, 1, 3)).astype(np.float32))],
  2175. 'desc_bprop': [Tensor(np.arange(-1, 1, 0.25).reshape((2, 2, 2, 1, 1)).astype(np.float32))]}),
  2176. ]
  2177. test_case_array_ops = [
  2178. ('SpaceToDepth', {
  2179. 'block': P.SpaceToDepth(2),
  2180. 'desc_inputs': [[1, 3, 2, 2]],
  2181. 'desc_bprop': [[1, 12, 1, 1]]}),
  2182. ('DepthToSpace', {
  2183. 'block': P.DepthToSpace(2),
  2184. 'desc_inputs': [[1, 12, 1, 1]],
  2185. 'desc_bprop': [[1, 3, 2, 2]]}),
  2186. ('Split', {
  2187. 'block': P.Split(1, 2),
  2188. 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
  2189. 'skip': ['backward']}),
  2190. ('Argmax', {
  2191. 'block': P.Argmax(),
  2192. 'desc_inputs': [[128, 32, 32, 64]],
  2193. 'desc_bprop': [0],
  2194. 'skip': ['backward']}),
  2195. ('Argmin', {
  2196. 'block': P.Argmin(),
  2197. 'desc_inputs': [[128, 32, 32, 64]],
  2198. 'desc_bprop': [1],
  2199. 'skip': ['backward']}),
  2200. ('ArgMaxWithValue', {
  2201. 'block': P.ArgMaxWithValue(),
  2202. 'desc_inputs': [[128, 32, 32, 64]],
  2203. 'desc_bprop': [[1], [1]],
  2204. 'skip': ['backward']}),
  2205. ('ArgMinWithValue', {
  2206. 'block': P.ArgMinWithValue(),
  2207. 'desc_inputs': [[128, 32, 32, 64]],
  2208. 'desc_bprop': [[1], [1]],
  2209. 'skip': ['backward']}),
  2210. ('Transpose_dim3', {
  2211. 'block': P.Transpose(),
  2212. 'desc_const': [(0, 2, 1)],
  2213. 'desc_inputs': [[1, 2, 3]],
  2214. 'desc_bprop': [[1, 3, 2]]}),
  2215. ('Transpose_dim4', {
  2216. 'block': P.Transpose(),
  2217. 'desc_const': [(0, 1, 2, 3)],
  2218. 'desc_inputs': [[1, 2, 3, 4]],
  2219. 'desc_bprop': [[1, 2, 4, 3]]}),
  2220. ('AddN', {
  2221. 'block': NetForTupleInput(P.AddN()),
  2222. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  2223. 'desc_bprop': [[2, 3, 3, 5]]}),
  2224. ('AccumulateNV2', {
  2225. 'block': NetForTupleInput(P.AccumulateNV2()),
  2226. 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
  2227. 'desc_bprop': [[2, 3, 3, 5]]}),
  2228. ('Shape', {
  2229. 'block': P.Shape(),
  2230. 'desc_inputs': [[3, 3, 2, 2]],
  2231. 'skip': ['backward']}),
  2232. ('Reshape', {
  2233. 'block': P.Reshape(),
  2234. 'desc_const': [(64,)],
  2235. 'desc_inputs': [[64, 1]],
  2236. 'desc_bprop': [[64]]}),
  2237. ('Cast', {
  2238. 'block': P.Cast(),
  2239. 'desc_const': [mstype.int32],
  2240. 'desc_inputs': [[2, 3, 4, 5]],
  2241. 'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
  2242. ('ExpandDims', {
  2243. 'block': P.ExpandDims(),
  2244. 'desc_const': [0],
  2245. 'desc_inputs': [[2, 2]],
  2246. 'desc_bprop': [[1, 2, 2]]}),
  2247. ('ExpandDims_1', {
  2248. 'block': P.ExpandDims(),
  2249. 'desc_const': [-1],
  2250. 'desc_inputs': [[2, 2]],
  2251. 'desc_bprop': [[2, 2, 1]]}),
  2252. ('Squeeze', {
  2253. 'block': P.Squeeze(2),
  2254. 'desc_inputs': [[3, 2, 1]],
  2255. 'desc_bprop': [[3, 2]]}),
  2256. ('Squeeze_0', {
  2257. 'block': P.Squeeze(),
  2258. 'desc_inputs': [[3, 1, 2, 1]],
  2259. 'desc_bprop': [[3, 2]]}),
  2260. ('Squeeze_1', {
  2261. 'block': P.Squeeze(),
  2262. 'desc_inputs': [[1, 1, 1, 1]],
  2263. 'desc_bprop': [1.0],
  2264. 'skip': ['backward']}),
  2265. ('Squeeze_2', {
  2266. 'block': P.Squeeze((2, 3)),
  2267. 'desc_inputs': [[3, 2, 1, 1]],
  2268. 'desc_bprop': [[3, 2]]}),
  2269. ('Size', {
  2270. 'block': P.Size(),
  2271. 'desc_inputs': [[2, 3, 5]],
  2272. 'skip': ['backward']}),
  2273. ('Tile_0', {
  2274. 'block': P.Tile(),
  2275. 'desc_const': [(1, 2)],
  2276. 'desc_inputs': [[64, 1]],
  2277. 'desc_bprop': [[64, 2]]}),
  2278. ('Tile_1', {
  2279. 'block': P.Tile(),
  2280. 'desc_const': [(1, 1)],
  2281. 'desc_inputs': [[64, 1]],
  2282. 'desc_bprop': [[64, 1]]}),
  2283. ('Tile_2', {
  2284. 'block': P.Tile(),
  2285. 'desc_const': [(2, 1, 1, 2)],
  2286. 'desc_inputs': [[2, 2, 2]],
  2287. 'desc_bprop': [[2, 2, 2, 4]]}),
  2288. ('ReverseV2', {
  2289. 'block': P.ReverseV2(axis=[1]),
  2290. 'desc_inputs': [(Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)))],
  2291. 'desc_bprop': [(Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)))]}),
  2292. ('Rint', {
  2293. 'block': P.Rint(),
  2294. 'desc_inputs': [(Tensor(np.array([-1.6, -0.1, 1.5, 2.0]).astype(np.float32)))],
  2295. 'skip': ['backward']}),
  2296. ('ConcatV2_0', {
  2297. 'block': NetForConcat1(),
  2298. 'desc_inputs': [
  2299. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
  2300. Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
  2301. 'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
  2302. ('ConcatV2_1', {
  2303. 'block': NetForConcat2(),
  2304. 'desc_inputs': [Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
  2305. Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32))],
  2306. 'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
  2307. ('ConcatV2_2', {
  2308. 'block': NetForConcat(),
  2309. 'desc_inputs': [[2, 2]],
  2310. 'desc_bprop': [[4, 2]]}),
  2311. ('ConcatV2_3', {
  2312. 'block': NetForConcat1(),
  2313. 'desc_inputs': [[2, 2], [2, 2]],
  2314. 'desc_bprop': [[4, 2]]}),
  2315. ('ConcatV2_4', {
  2316. 'block': NetForConcat3(),
  2317. 'desc_inputs': [
  2318. Tensor(np.ones((3, 2, 3), np.float32)),
  2319. Tensor(np.ones((5, 2, 3), np.float32)),
  2320. Tensor(np.ones((6, 2, 3), np.float32))],
  2321. 'desc_bprop': [[14, 2, 3]]}),
  2322. ('ConcatV2_5', {
  2323. 'block': NetForConcat4(),
  2324. 'desc_inputs': [Tensor(np.array([1], np.float32)),
  2325. Tensor(np.array([1], np.float32)),
  2326. Tensor(np.array([1], np.float32))],
  2327. 'desc_bprop': [[3,]]}),
  2328. ('Stack_0', {
  2329. 'block': NetForStackInput(P.Stack()),
  2330. 'desc_inputs': [[2, 2], [2, 2], [2, 2]],
  2331. 'desc_bprop': [[3, 2, 2]],
  2332. }),
  2333. ('Stack_1', {
  2334. 'block': NetForStackInput(P.Stack(axis=-2)),
  2335. 'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
  2336. 'desc_bprop': [[3, 2, 3, 3]],
  2337. }),
  2338. ('Stack_2', {
  2339. 'block': NetForStackInput(P.Stack()),
  2340. 'desc_inputs': [[128, 128], [128, 128]],
  2341. 'desc_bprop': [[2, 128, 128]],
  2342. }),
  2343. ('Stack_3', {
  2344. 'block': NetForStackInput(P.Stack()),
  2345. 'desc_inputs': [[2, 2]],
  2346. 'desc_bprop': [[1, 2, 2]]}),
  2347. ('Unpack_0', {
  2348. 'block': NetForUnpackInput(P.Unstack(axis=0)),
  2349. 'desc_inputs': [[2, 4]],
  2350. 'desc_bprop': [[4], [4]],
  2351. }),
  2352. ('Unpack_1', {
  2353. 'block': NetForUnpackInput(P.Unstack(axis=-1)),
  2354. 'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
  2355. 'desc_bprop': [[1], [1], [1]],
  2356. }),
  2357. ('Diag_1', {
  2358. 'block': P.Diag(),
  2359. 'desc_inputs': [[4]],
  2360. 'desc_bprop': [[4, 4]],
  2361. }),
  2362. ('Diag_2', {
  2363. 'block': P.Diag(),
  2364. 'desc_inputs': [[4, 4]],
  2365. 'desc_bprop': [[4, 4, 4, 4]],
  2366. }),
  2367. ('DiagPart_1', {
  2368. 'block': P.DiagPart(),
  2369. 'desc_inputs': [[4, 4]],
  2370. 'desc_bprop': [[4]],
  2371. }),
  2372. ('DiagPart_2', {
  2373. 'block': P.DiagPart(),
  2374. 'desc_inputs': [[4, 4, 4, 4]],
  2375. 'desc_bprop': [[4, 4]],
  2376. }),
  2377. ('SpaceToBatch_1', {
  2378. 'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
  2379. 'desc_inputs': [[1, 3, 2, 2]],
  2380. 'desc_bprop': [[4, 3, 1, 1]],
  2381. }),
  2382. ('SpaceToBatch_2', {
  2383. 'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
  2384. 'desc_inputs': [[1, 3, 2, 2]],
  2385. 'desc_bprop': [[4, 3, 2, 3]],
  2386. }),
  2387. ('BatchToSpace_1', {
  2388. 'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
  2389. 'desc_inputs': [[4, 3, 1, 1]],
  2390. 'desc_bprop': [[1, 3, 2, 2]],
  2391. }),
  2392. ('BatchToSpace_2', {
  2393. 'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
  2394. 'desc_inputs': [[4, 3, 1, 1]],
  2395. 'desc_bprop': [[1, 3, 2, 1]],
  2396. }),
  2397. ('UnsortedSegmentMin_1', {
  2398. 'block': P.UnsortedSegmentMin(),
  2399. 'desc_const': [2],
  2400. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
  2401. Tensor(np.array([0, 1, 1]).astype(np.int32))],
  2402. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
  2403. ('BroadcastTo', {
  2404. 'block': P.BroadcastTo((2, 3)),
  2405. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
  2406. 'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
  2407. ('InTopK', {
  2408. 'block': P.InTopK(2),
  2409. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
  2410. Tensor(np.array([2, 1, 2]).astype(np.int32))],
  2411. 'skip': ['backward'],
  2412. }),
  2413. ('InplaceUpdate', {
  2414. 'block': P.InplaceUpdate((0, 2)),
  2415. 'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
  2416. Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
  2417. 'skip': ['backward'],
  2418. }),
  2419. ('ReverseSequence', {
  2420. 'block': P.ReverseSequence(1, 0),
  2421. 'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
  2422. Tensor(np.array([1, 2, 3]).astype(np.int32))],
  2423. 'desc_bprop': [[3, 3]]}),
  2424. ('EditDistance', {
  2425. 'block': EditDistance(Tensor(np.array([1, 1, 2]).astype(np.int64)),
  2426. Tensor(np.array([2, 2, 2]).astype(np.int64))),
  2427. 'desc_inputs': [Tensor(np.array([[0, 0, 0], [1, 0, 1], [1, 1, 1]]).astype(np.int64)),
  2428. Tensor(np.array([1, 2, 3]).astype(np.float32)),
  2429. Tensor(np.array([[0, 1, 0], [0, 0, 1], [1, 1, 0], [1, 0, 1]]).astype(np.int64)),
  2430. Tensor(np.array([1, 3, 2, 1]).astype(np.float32))],
  2431. 'skip': ['backward'],
  2432. }),
  2433. ('LinSpace', {
  2434. 'block': P.LinSpace(),
  2435. 'desc_const': [5],
  2436. 'desc_inputs': [Tensor(1, mstype.float32),
  2437. Tensor(10, mstype.float32)],
  2438. 'skip': ['backward'],
  2439. }),
  2440. ('MaskedFill', {
  2441. 'block': P.MaskedFill(),
  2442. 'desc_inputs': [Tensor(np.array([[1.0, 2.0, 3.0]]), mstype.float32),
  2443. Tensor(np.array([[True, True, False]]), mstype.bool_),
  2444. Tensor(4.0, mstype.float32)],
  2445. 'desc_bprop': [Tensor(np.array([[1.0, 2.0, 3.0]]), mstype.float32)],
  2446. }),
  2447. ('MatrixDiag', {
  2448. 'block': inner.MatrixDiag(),
  2449. 'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
  2450. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2451. 'skip': ['backward'],
  2452. }),
  2453. ('MatrixDiagPart', {
  2454. 'block': inner.MatrixDiagPart(),
  2455. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  2456. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2457. 'skip': ['backward'],
  2458. }),
  2459. ('MatrixSetDiag', {
  2460. 'block': inner.MatrixSetDiag(),
  2461. 'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
  2462. Tensor(np.arange(6).reshape(3, 2), mstype.float32),
  2463. Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
  2464. 'skip': ['backward'],
  2465. }),
  2466. ('TransShape', {
  2467. 'block': P.TransShape(),
  2468. 'desc_const': [(1, 12, 24, 24)],
  2469. 'desc_inputs': [[1, 3, 24, 24]],
  2470. 'desc_bprop': [[1, 12, 24, 24]],
  2471. }),
  2472. ('ParallelConcat', {
  2473. 'block': ParallelConcatNet(),
  2474. 'desc_inputs': [Tensor([[1, 2]], mstype.float32),
  2475. Tensor([[5, 6]], mstype.float32)],
  2476. 'skip': ['backward'],
  2477. }),
  2478. ('SplitV', {
  2479. 'block': P.SplitV(size_splits=[1, 2], split_dim=1, num_split=2),
  2480. 'desc_inputs': [Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])],
  2481. 'desc_bprop': [(Tensor([[1], [4], [7]]),
  2482. Tensor([[2, 3], [5, 6], [8, 9]]))],
  2483. }),
  2484. ('ExtractVolumePatches', {
  2485. 'block': P.ExtractVolumePatches(kernel_size=[1, 1, 2, 2, 2], strides=[1, 1, 1, 1, 1], padding="VALID"),
  2486. 'desc_inputs': [Tensor(np.random.rand(1, 1, 3, 3, 3), mstype.float16)],
  2487. 'desc_bprop': [Tensor(np.random.rand(1, 8, 2, 2, 2), mstype.float16)],
  2488. }),
  2489. ('Lstsq', {
  2490. 'block': P.Lstsq(l2_regularizer=0.0, fast=True),
  2491. 'desc_inputs': [Tensor(np.array([[2, 1, 5], [3, 5, 1], [1, 1, 1]]), mstype.float32),
  2492. Tensor(np.array([[10, 5], [15, 8], [7, 4]]), mstype.float32)],
  2493. 'skip': ['backward']}),
  2494. ('LowerBound', {
  2495. 'block': P.LowerBound(),
  2496. 'desc_inputs': [Tensor(np.arange(20).reshape(4, 5), mstype.int8),
  2497. Tensor([[3], [5], [7], [8]], mstype.int8)],
  2498. 'skip': ['backward'],
  2499. }),
  2500. ]
  2501. test_case_image_ops = [
  2502. ('NonMaxSuppressionV3', {
  2503. 'block': P.NonMaxSuppressionV3(),
  2504. 'desc_inputs': [Tensor(np.array([[20, 5, 200, 100],
  2505. [50, 50, 200, 200],
  2506. [20, 120, 150, 150],
  2507. [250, 250, 400, 350],
  2508. [90, 10, 300, 300],
  2509. [40, 220, 280, 380]]).astype(np.float32)),
  2510. Tensor(np.array([0.353, 0.624, 0.667, 0.5, 0.3, 0.46]).astype(np.float32)),
  2511. Tensor(4, mstype.int32),
  2512. Tensor(0.1, mstype.float32),
  2513. Tensor(0, mstype.float32)],
  2514. 'skip': ['backward']}),
  2515. ]
  2516. test_case_other_ops = [
  2517. ('ScalarLog', {
  2518. 'block': F.scalar_log,
  2519. 'desc_const': [0.0],
  2520. 'desc_inputs': [],
  2521. 'desc_bprop': [1],
  2522. 'skip': ['backward']}),
  2523. ('BoundingBoxEncode', {
  2524. 'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
  2525. 'desc_inputs': [[256, 4], [256, 4]],
  2526. 'desc_bprop': [[256, 4]],
  2527. 'skip': ['backward']}),
  2528. ('BoundingBoxDecode', {
  2529. '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)),
  2530. 'desc_inputs': [[256, 4], [256, 4]],
  2531. 'desc_bprop': [[256, 4]],
  2532. 'skip': ['backward']}),
  2533. ('GatherNd', {
  2534. 'block': P.GatherNd(),
  2535. 'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
  2536. Tensor(np.ones((2, 4), np.int32))),
  2537. 'desc_bprop': [[2]]}),
  2538. ('ScatterNd', {
  2539. 'block': P.ScatterNd(),
  2540. 'desc_const': [(3, 3)],
  2541. 'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
  2542. Tensor(np.ones((2,), np.int32))),
  2543. 'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
  2544. ('TensorScatterUpdate', {
  2545. 'block': P.TensorScatterUpdate(),
  2546. 'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
  2547. Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2548. Tensor(np.ones([2, 5], np.float32) * 99)),
  2549. 'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
  2550. ('ScatterMaxUseLocking', {
  2551. 'block': ScatterMax(use_locking=True),
  2552. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2553. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  2554. 'skip': ['backward']}),
  2555. ('ScatterMax1d', {
  2556. 'block': ScatterMax(),
  2557. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2558. Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
  2559. 'skip': ['backward']}),
  2560. ('ScatterMaxF32', {
  2561. 'block': ScatterMax(),
  2562. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2563. Tensor(np.ones([2, 2, 3], np.float32) * 99)),
  2564. 'skip': ['backward']}),
  2565. ('ScatterMaxF16', {
  2566. 'block': ScatterMax(np.float16),
  2567. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2568. Tensor(np.ones([2, 2, 3], np.float16) * 99)),
  2569. 'skip': ['backward']}),
  2570. ('ScatterMaxI32', {
  2571. 'block': ScatterMax(np.int32),
  2572. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2573. Tensor(np.ones([2, 2, 3], np.int32) * 99)),
  2574. 'skip': ['backward']}),
  2575. ('ScatterMinUseLocking', {
  2576. 'block': ScatterMin(use_locking=True),
  2577. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2578. Tensor(np.ones([2, 3], np.float32))),
  2579. 'skip': ['backward']}),
  2580. ('ScatterMin1d', {
  2581. 'block': ScatterMin(),
  2582. 'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
  2583. Tensor(np.ones([2, 3], np.float32))),
  2584. 'skip': ['backward']}),
  2585. ('ScatterMinF32', {
  2586. 'block': ScatterMin(),
  2587. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2588. Tensor(np.ones([2, 2, 3], np.float32))),
  2589. 'skip': ['backward']}),
  2590. ('ScatterMinF16', {
  2591. 'block': ScatterMin(np.float16),
  2592. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2593. Tensor(np.ones([2, 2, 3], np.float16))),
  2594. 'skip': ['backward']}),
  2595. ('ScatterMinI32', {
  2596. 'block': ScatterMin(np.int32),
  2597. 'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
  2598. Tensor(np.ones([2, 2, 3], np.int32))),
  2599. 'skip': ['backward']}),
  2600. ('ScatterUpdate', {
  2601. 'block': ScatterUpdate((6,)),
  2602. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2603. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2604. 'skip': ['backward']}),
  2605. ('ScatterAddUseLocking', {
  2606. 'block': ScatterAdd((6,), use_locking=True),
  2607. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2608. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2609. 'skip': ['backward']}),
  2610. ('ScatterNonAliasingAdd_1d', {
  2611. 'block': ScatterNonAliasingAdd((8,)),
  2612. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2613. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2614. 'skip': ['backward']}),
  2615. ('ScatterNdAdd', {
  2616. 'block': ScatterNdAdd((8,)),
  2617. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2618. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2619. 'skip': ['backward']}),
  2620. ('ScatterNdSub', {
  2621. 'block': ScatterNdAdd((8,)),
  2622. 'desc_inputs': (Tensor(np.array([[2], [3], [4], [5]], np.int32)),
  2623. Tensor(np.array([2.0, 3.0, 4.0, 8.0], np.float32))),
  2624. 'skip': ['backward']}),
  2625. ('ScatterAdd', {
  2626. 'block': ScatterAdd((6,)),
  2627. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2628. Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
  2629. 'skip': ['backward']}),
  2630. ('ScatterAddScalar', {
  2631. 'block': ScatterAdd((6,)),
  2632. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2633. Tensor(np.array([2.0], np.float32))),
  2634. 'skip': ['backward']}),
  2635. ('ScatterAdd2d', {
  2636. 'block': ScatterAdd((3, 4)),
  2637. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2638. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2639. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2640. 'skip': ['backward']}),
  2641. ('ScatterAddF16', {
  2642. 'block': ScatterAdd((6,), np.float16),
  2643. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2644. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2645. 'skip': ['backward']}),
  2646. ('ScatterAddI8', {
  2647. 'block': ScatterAdd((6,), np.int8),
  2648. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2649. Tensor(np.array([2, 3, 4], np.int8))),
  2650. 'skip': ['backward']}),
  2651. ('ScatterAddI32', {
  2652. 'block': ScatterAdd((6,), np.int32),
  2653. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2654. Tensor(np.array([2, 3, 4], np.int32))),
  2655. 'skip': ['backward']}),
  2656. ('ScatterAddU8', {
  2657. 'block': ScatterAdd((6,), np.uint8),
  2658. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2659. Tensor(np.array([2, 3, 4], np.uint8))),
  2660. 'skip': ['backward']}),
  2661. ('ScatterMulUseLocking', {
  2662. 'block': ScatterMul((6,), use_locking=True),
  2663. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2664. Tensor(np.array([2.0], np.float32))),
  2665. 'skip': ['backward']}),
  2666. ('ScatterMulScalar', {
  2667. 'block': ScatterMul((6,)),
  2668. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2669. Tensor(np.array([2.0], np.float32))),
  2670. 'skip': ['backward']}),
  2671. ('ScatterMul2d', {
  2672. 'block': ScatterMul((3, 4)),
  2673. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2674. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2675. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2676. 'skip': ['backward']}),
  2677. ('ScatterMulF16', {
  2678. 'block': ScatterMul((6,), np.float16),
  2679. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2680. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2681. 'skip': ['backward']}),
  2682. ('ScatterMulI8', {
  2683. 'block': ScatterMul((6,), np.int8),
  2684. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2685. Tensor(np.array([2, 3, 4], np.int8))),
  2686. 'skip': ['backward']}),
  2687. ('ScatterMulI32', {
  2688. 'block': ScatterMul((6,), np.int32),
  2689. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2690. Tensor(np.array([2, 3, 4], np.int32))),
  2691. 'skip': ['backward']}),
  2692. ('ScatterMulU8', {
  2693. 'block': ScatterMul((6,), np.uint8),
  2694. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2695. Tensor(np.array([2, 3, 4], np.uint8))),
  2696. 'skip': ['backward']}),
  2697. ('ScatterDivUseLocking', {
  2698. 'block': ScatterDiv((6,), use_locking=True),
  2699. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2700. Tensor(np.array([2.0], np.float32))),
  2701. 'skip': ['backward']}),
  2702. ('ScatterDivScalar', {
  2703. 'block': ScatterDiv((6,)),
  2704. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2705. Tensor(np.array([2.0], np.float32))),
  2706. 'skip': ['backward']}),
  2707. ('ScatterDiv2d', {
  2708. 'block': ScatterDiv((3, 4)),
  2709. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2710. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2711. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2712. 'skip': ['backward']}),
  2713. ('ScatterDivF16', {
  2714. 'block': ScatterDiv((6,), np.float16),
  2715. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2716. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2717. 'skip': ['backward']}),
  2718. ('ScatterDivI8', {
  2719. 'block': ScatterDiv((6,), np.int8),
  2720. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2721. Tensor(np.array([2, 3, 4], np.int8))),
  2722. 'skip': ['backward']}),
  2723. ('ScatterDivU8', {
  2724. 'block': ScatterDiv((6,), np.uint8),
  2725. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2726. Tensor(np.array([2, 3, 4], np.uint8))),
  2727. 'skip': ['backward']}),
  2728. ('ScatterSubUseLocking', {
  2729. 'block': ScatterSub((6,), use_locking=True),
  2730. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2731. Tensor(np.array([2.0], np.float32))),
  2732. 'skip': ['backward']}),
  2733. ('ScatterSubScalar', {
  2734. 'block': ScatterSub((6,)),
  2735. 'desc_inputs': (Tensor(np.array([2], np.int32)),
  2736. Tensor(np.array([2.0], np.float32))),
  2737. 'skip': ['backward']}),
  2738. ('ScatterSub2d', {
  2739. 'block': ScatterSub((3, 4)),
  2740. 'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
  2741. Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
  2742. [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
  2743. 'skip': ['backward']}),
  2744. ('ScatterSubF16', {
  2745. 'block': ScatterSub((6,), np.float16),
  2746. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2747. Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
  2748. 'skip': ['backward']}),
  2749. ('ScatterSubI32', {
  2750. 'block': ScatterSub((6,), np.int32),
  2751. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2752. Tensor(np.array([2, 3, 4], np.int32))),
  2753. 'skip': ['backward']}),
  2754. ('ScatterSubI8', {
  2755. 'block': ScatterSub((6,), np.int8),
  2756. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2757. Tensor(np.array([2, 3, 4], np.int8))),
  2758. 'skip': ['backward']}),
  2759. ('ScatterSubU8', {
  2760. 'block': ScatterSub((6,), np.uint8),
  2761. 'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
  2762. Tensor(np.array([1, 1, 0], np.uint8))),
  2763. 'skip': ['backward']}),
  2764. ('SmoothL1Loss', {
  2765. 'block': P.SmoothL1Loss(),
  2766. 'desc_inputs': [[256, 4], [256, 4]],
  2767. 'desc_bprop': [[256, 4]]}),
  2768. ('IOU', {
  2769. 'block': P.IOU(),
  2770. 'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
  2771. 'desc_bprop': [convert([128, 256], np.float16)]}),
  2772. ('PopulationCount', {
  2773. 'block': P.PopulationCount(),
  2774. 'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.int16))],
  2775. 'skip': ['backward']}),
  2776. ('BasicLSTMCellNet', {
  2777. 'block': BasicLSTMCellNet(),
  2778. 'desc_inputs': [Tensor(np.random.rand(1, 32).astype(np.float16)),
  2779. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2780. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2781. Tensor(np.random.rand(96, 256).astype(np.float16)),
  2782. Tensor(np.random.rand(256,).astype(np.float16))],
  2783. 'desc_bprop': [Tensor(np.random.rand(1, 64).astype(np.float16)),
  2784. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2785. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2786. Tensor(np.random.rand(1, 64).astype(np.float16)),
  2787. Tensor(np.random.rand(1, 64).astype(np.float16))]}),
  2788. ('DynamicGRUV2Net', {
  2789. 'block': DynamicGRUV2Net(),
  2790. 'desc_inputs': [Tensor(np.random.rand(2, 8, 64).astype(np.float16)),
  2791. Tensor(np.random.rand(64, 48).astype(np.float16)),
  2792. Tensor(np.random.rand(16, 48).astype(np.float16)),
  2793. Tensor(np.random.rand(48).astype(np.float16)),
  2794. Tensor(np.random.rand(48).astype(np.float16)),
  2795. Tensor(np.random.rand(8, 16).astype(np.float16))],
  2796. 'desc_bprop': [Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2797. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2798. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2799. Tensor(np.random.rand(2, 8, 16).astype(np.float16)),
  2800. Tensor(np.random.rand(2, 8, 16).astype(np.float16))]}),
  2801. ('HSVToRGB', {
  2802. 'block': P.HSVToRGB(),
  2803. 'desc_inputs': [Tensor(np.array([[[[0.5, 0.5, 0.5]]]], np.float32))],
  2804. 'skip': ['backward']}),
  2805. ]
  2806. test_case_quant_ops = [
  2807. ('Quant_1', {
  2808. 'block': inner.Quant(0.5, 0.0, False, "Round"),
  2809. 'desc_inputs': [Tensor(np.random.rand(1, 2, 4, 4), mstype.float32)],
  2810. 'skip': ['backward']}),
  2811. ('Quant_2', {
  2812. 'block': inner.Quant(80.0, 10.0, True, "Round"),
  2813. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2814. 'skip': ['backward']}),
  2815. ('Quant_3', {
  2816. 'block': inner.Quant(80.0, 0.0, False, "Floor"),
  2817. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2818. 'skip': ['backward']}),
  2819. ('Quant_4', {
  2820. 'block': inner.Quant(80.0, 0.0, False, "Ceil"),
  2821. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2822. 'skip': ['backward']}),
  2823. ('Quant_5', {
  2824. 'block': inner.Quant(80.0, 0.0, False, "Trunc"),
  2825. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2826. 'skip': ['backward']}),
  2827. ('Quant_6', {
  2828. 'block': inner.Quant(-80.0, 10.0, False, "Round"),
  2829. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2830. 'skip': ['backward']}),
  2831. ('Quant_7', {
  2832. 'block': inner.Quant(80.0, -10.0, False, "Round"),
  2833. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
  2834. 'skip': ['backward']}),
  2835. ('Quant_8', {
  2836. 'block': inner.Quant(80.0, 10.0, False, "Round"),
  2837. 'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
  2838. 'skip': ['backward']}),
  2839. ]
  2840. test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops,
  2841. test_case_other_ops, test_case_quant_ops, test_case_image_ops]
  2842. test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
  2843. # use -k to select certain testcast
  2844. # pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
  2845. test_exec_case = test_case
  2846. test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
  2847. @non_graph_engine
  2848. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  2849. def test_exec():
  2850. context.set_context(mode=context.GRAPH_MODE)
  2851. return test_exec_case
  2852. @mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
  2853. def test_backward_exec():
  2854. context.set_context(mode=context.GRAPH_MODE)
  2855. return test_backward_exec_case
  2856. @security_off_wrap
  2857. @non_graph_engine
  2858. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
  2859. def test_summary_ops():
  2860. if security.enable_security():
  2861. return []
  2862. test_cases_for_summary_ops = [
  2863. ('Summary', {
  2864. 'block': SummaryNet(),
  2865. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2866. Tensor(np.array([1.2]).astype(np.float32))],
  2867. 'skip': ['backward']}),
  2868. ('HistogramSummary', {
  2869. 'block': HistogramSummaryNet(),
  2870. 'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
  2871. Tensor(np.array([1.2]).astype(np.float32))],
  2872. 'skip': ['backward']}),
  2873. ]
  2874. context.set_context(mode=context.GRAPH_MODE)
  2875. return test_cases_for_summary_ops
  2876. def test_summary_ops_security_on():
  2877. if security.enable_security():
  2878. with pytest.raises(ValueError) as exc:
  2879. SummaryNet()
  2880. assert str(exc.value) == 'The Summary is not supported, please without `-s on` and recompile source.'
  2881. with pytest.raises(ValueError) as exc:
  2882. HistogramSummaryNet()
  2883. assert str(exc.value) == 'The Summary is not supported, please without `-s on` and recompile source.'
  2884. raise_set = [
  2885. ('Cast_Error', {
  2886. 'block': (P.Cast(), {'exception': TypeError}),
  2887. 'desc_const': [mstype.int32],
  2888. 'desc_inputs': ['wrong input'],
  2889. 'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
  2890. ('Maximum_Error', {
  2891. 'block': (P.Maximum(), {'exception': TypeError}),
  2892. 'desc_const': [(1, 2, 3)],
  2893. 'desc_inputs': [[2, 3, 3, 5]],
  2894. 'desc_bprop': [[2, 3, 3, 5]]}),
  2895. ('Shape_error', {
  2896. 'block': (P.Shape(), {'exception': TypeError}),
  2897. 'desc_inputs': [(64, 1)],
  2898. 'desc_bprop': [[64]]}),
  2899. ('Flatten_Error', {
  2900. 'block': (NetForFlatten0D(), {'exception': ValueError}),
  2901. 'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
  2902. 'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
  2903. ('ScatterNdUpdate', {
  2904. 'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
  2905. 'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
  2906. Tensor(np.ones((2, 2), np.float32)),
  2907. Tensor(np.ones((2,), np.float32))),
  2908. 'desc_bprop': [[2, 3]]}),
  2909. ('PReLU', {
  2910. 'block': (P.PReLU(), {'exception': ValueError}),
  2911. 'desc_inputs': [[2], [1]],
  2912. 'desc_bprop': [[1]]}),
  2913. ('SSIM', {
  2914. 'block': (nn.SSIM(), {'exception': ValueError}),
  2915. 'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
  2916. Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]})
  2917. ]
  2918. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  2919. def test_check_exception():
  2920. return raise_set