You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_ops.py 120 kB

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