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