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

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