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

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