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

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