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