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

test_ops.py 100 kB

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