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_nn_ops_check.py 23 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. from mindspore import Tensor
  20. from mindspore import ops
  21. from mindspore.common import dtype as mstype
  22. from mindspore.common.api import _executor
  23. from mindspore.common.parameter import Parameter
  24. from mindspore.ops import composite as C
  25. from mindspore.ops import functional as F
  26. from mindspore.ops import operations as P
  27. from mindspore.ops.operations import _grad_ops as G
  28. from ..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. class Conv2DBackpropInputNet(nn.Cell):
  36. def __init__(self, net, x_shape):
  37. super(Conv2DBackpropInputNet, self).__init__()
  38. self.net = net
  39. self.x_shape = x_shape
  40. def construct(self, dout, w):
  41. return self.net(dout, w, self.x_shape)
  42. class TopKNet(nn.Cell):
  43. def __init__(self, net, k):
  44. super(TopKNet, self).__init__()
  45. self.net = net
  46. self.k = k
  47. def construct(self, x):
  48. return self.net(x, self.k)
  49. raise_set = [
  50. # input is scalar
  51. ('Flatten0', {
  52. 'block': (P.Flatten(), {'exception': TypeError, 'error_keywords': ['Flatten']}),
  53. 'desc_inputs': [5.0],
  54. 'skip': ['backward']}),
  55. # dim of input is zero
  56. ('Flatten1', {
  57. 'block': (P.Flatten(), {'exception': ValueError, 'error_keywords': ['Flatten']}),
  58. 'desc_inputs': [F.scalar_to_tensor(5.0)],
  59. 'skip': ['backward']}),
  60. # input is scalar
  61. ('Softmax0', {
  62. 'block': (P.Softmax(), {'exception': TypeError, 'error_keywords': ['Softmax']}),
  63. 'desc_inputs': [5.0],
  64. 'skip': ['backward']}),
  65. # axis is empty tuple
  66. ('Softmax1', {
  67. 'block': (P.Softmax(axis=()), {'exception': ValueError, 'error_keywords': ['Softmax']}),
  68. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  69. 'skip': ['backward']}),
  70. # axis value is not in range
  71. ('Softmax2', {
  72. 'block': (P.Softmax(axis=2), {'exception': ValueError, 'error_keywords': ['Softmax']}),
  73. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  74. 'skip': ['backward']}),
  75. # input is scalar
  76. ('LogSoftmax0', {
  77. 'block': (P.LogSoftmax(), {'exception': TypeError, 'error_keywords': ['LogSoftmax']}),
  78. 'desc_inputs': [5.0],
  79. 'skip': ['backward']}),
  80. # axis value is not in range
  81. ('LogSoftmax1', {
  82. 'block': (P.LogSoftmax(axis=2), {'exception': ValueError, 'error_keywords': ['LogSoftmax']}),
  83. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))],
  84. 'skip': ['backward']}),
  85. # input is scalar
  86. ('ReLU0', {
  87. 'block': (P.ReLU(), {'exception': TypeError, 'error_keywords': ['ReLU']}),
  88. 'desc_inputs': [5.0],
  89. 'skip': ['backward']}),
  90. # input is Tensor(Bool)
  91. ('ReLU1', {
  92. 'block': (P.ReLU(), {'exception': TypeError, 'error_keywords': ['ReLU']}),
  93. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))],
  94. 'skip': ['backward']}),
  95. # input is scalar
  96. ('ReLU60', {
  97. 'block': (P.ReLU6(), {'exception': TypeError, 'error_keywords': ['ReLU6']}),
  98. 'desc_inputs': [5.0],
  99. 'skip': ['backward']}),
  100. # input is Tensor(int32)
  101. ('ReLU61', {
  102. 'block': (P.ReLU6(), {'exception': TypeError, 'error_keywords': ['ReLU6']}),
  103. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  104. 'skip': ['backward']}),
  105. # input is scalar
  106. ('Elu0', {
  107. 'block': (P.Elu(), {'exception': TypeError, 'error_keywords': ['Elu']}),
  108. 'desc_inputs': [5.0],
  109. 'skip': ['backward']}),
  110. # input is Tensor(int32)
  111. ('Elu1', {
  112. 'block': (P.Elu(), {'exception': TypeError, 'error_keywords': ['Elu']}),
  113. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  114. 'skip': ['backward']}),
  115. # input is scalar
  116. ('Sigmoid0', {
  117. 'block': (P.Sigmoid(), {'exception': TypeError, 'error_keywords': ['Sigmoid']}),
  118. 'desc_inputs': [5.0],
  119. 'skip': ['backward']}),
  120. # input is Tensor(int32)
  121. ('Sigmoid1', {
  122. 'block': (P.Sigmoid(), {'exception': TypeError, 'error_keywords': ['Sigmoid']}),
  123. 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))],
  124. 'skip': ['backward']}),
  125. # input is scalar
  126. ('Tanh0', {
  127. 'block': (P.Tanh(), {'exception': TypeError, 'error_keywords': ['Tanh']}),
  128. 'desc_inputs': [5.0],
  129. 'skip': ['backward']}),
  130. # input is scalar
  131. ('BatchNorm0', {
  132. 'block': (P.BatchNorm(is_training=False), {'exception': TypeError, 'error_keywords': ['BatchNorm']}),
  133. 'desc_inputs': [5.0, 5.0, 5.0, 5.0, 5.0],
  134. 'skip': ['backward']}),
  135. # is_training=False and mean=None
  136. ('BatchNorm1', {
  137. 'block': (P.BatchNorm(is_training=False), {'exception': TypeError, 'error_keywords': ['BatchNorm']}),
  138. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([5, 3]).astype(np.float32)),
  139. Tensor(np.ones([5, 3]).astype(np.float32)), None, None],
  140. 'skip': ['backward']}),
  141. # is_training=True and mean=None
  142. ('BatchNorm2', {
  143. 'block': (P.BatchNorm(is_training=True), {'exception': TypeError, 'error_keywords': ['BatchNorm']}),
  144. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  145. Tensor(np.ones([3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float16)),
  146. Tensor(np.ones([3]).astype(np.float32))],
  147. 'skip': ['backward']}),
  148. # scale and bias rank > 1
  149. ('BatchNorm3', {
  150. 'block': (P.BatchNorm(is_training=True), {'exception': ValueError, 'error_keywords': ['BatchNorm']}),
  151. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([5, 3]).astype(np.float32)),
  152. Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  153. Tensor(np.ones([3]).astype(np.float32))],
  154. 'skip': ['backward']}),
  155. # scale and bias shape not match
  156. ('BatchNorm4', {
  157. 'block': (P.BatchNorm(is_training=True), {'exception': ValueError, 'error_keywords': ['BatchNorm']}),
  158. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  159. Tensor(np.ones([7]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  160. Tensor(np.ones([3]).astype(np.float32))],
  161. 'skip': ['backward']}),
  162. # is_training=False, mean and variance shape not match
  163. ('BatchNorm5', {
  164. 'block': (P.BatchNorm(is_training=False), {'exception': ValueError, 'error_keywords': ['BatchNorm']}),
  165. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  166. Tensor(np.ones([3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  167. Tensor(np.ones([5]).astype(np.float32))],
  168. 'skip': ['backward']}),
  169. # is_training=False, mean and scale shape not match
  170. ('BatchNorm6', {
  171. 'block': (P.BatchNorm(is_training=False), {'exception': ValueError, 'error_keywords': ['BatchNorm']}),
  172. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32)),
  173. Tensor(np.ones([3]).astype(np.float32)), Tensor(np.ones([5]).astype(np.float32)),
  174. Tensor(np.ones([5]).astype(np.float32))],
  175. 'skip': ['backward']}),
  176. # input is scalar
  177. ('Conv2D0', {
  178. 'block': (P.Conv2D(2, (5, 5)), {'exception': TypeError, 'error_keywords': ['Conv2D']}),
  179. 'desc_inputs': [5.0, 5.0],
  180. 'skip': ['backward']}),
  181. # input is Tensor(bool)
  182. ('Conv2D1', {
  183. 'block': (P.Conv2D(2, (5, 5)), {'exception': TypeError, 'error_keywords': ['Conv2D']}),
  184. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  185. 'skip': ['backward']}),
  186. # input x and w type mismatch
  187. ('Conv2D2', {
  188. 'block': (P.Conv2D(2, (5, 5)), {'exception': TypeError, 'error_keywords': ['Conv2D']}),
  189. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([5]).astype(np.float16))],
  190. 'skip': ['backward']}),
  191. # rank of x is not 4
  192. ('Conv2D3', {
  193. 'block': (P.Conv2D(2, (5, 5)), {'exception': ValueError, 'error_keywords': ['Conv2D']}),
  194. 'desc_inputs': [Tensor(np.ones([1, 1]).astype(np.float32)), Tensor(np.ones([1, 1, 9, 9]).astype(np.float32))],
  195. 'skip': ['backward']}),
  196. # rank of 2 is not 4
  197. ('Conv2D4', {
  198. 'block': (P.Conv2D(2, (5, 5)), {'exception': ValueError, 'error_keywords': ['Conv2D']}),
  199. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  200. Tensor(np.ones([1, 1, 9]).astype(np.float32))],
  201. 'skip': ['backward']}),
  202. # x_shape[1] / group != w_shape[1]
  203. ('Conv2D5', {
  204. 'block': (P.Conv2D(2, (5, 5)), {'exception': ValueError, 'error_keywords': ['Conv2D']}),
  205. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  206. Tensor(np.ones([1, 2, 9, 9]).astype(np.float32))],
  207. 'skip': ['backward']}),
  208. # out_channel != w_shape[0]
  209. ('Conv2D6', {
  210. 'block': (P.Conv2D(2, (5, 5)), {'exception': ValueError, 'error_keywords': ['Conv2D']}),
  211. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  212. Tensor(np.ones([1, 1, 9, 9]).astype(np.float32))],
  213. 'skip': ['backward']}),
  214. # kernel_size != w_shape[2:4]
  215. ('Conv2D7', {
  216. 'block': (P.Conv2D(2, (5, 5)), {'exception': ValueError, 'error_keywords': ['Conv2D']}),
  217. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  218. Tensor(np.ones([2, 1, 5, 6]).astype(np.float32))],
  219. 'skip': ['backward']}),
  220. # input is scalar
  221. ('DepthwiseConv2dNative0', {
  222. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  223. {'exception': TypeError, 'error_keywords': ['DepthwiseConv2dNative']}),
  224. 'desc_inputs': [5.0, 5.0],
  225. 'skip': ['backward']}),
  226. # input is Tensor(bool)
  227. ('DepthwiseConv2dNative1', {
  228. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  229. {'exception': TypeError, 'error_keywords': ['DepthwiseConv2dNative']}),
  230. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  231. 'skip': ['backward']}),
  232. # input x and w type mismatch
  233. ('DepthwiseConv2dNative2', {
  234. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  235. {'exception': TypeError, 'error_keywords': ['DepthwiseConv2dNative']}),
  236. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([5]).astype(np.float16))],
  237. 'skip': ['backward']}),
  238. # rank of x is not 4
  239. ('DepthwiseConv2dNative3', {
  240. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  241. {'exception': ValueError, 'error_keywords': ['DepthwiseConv2dNative']}),
  242. 'desc_inputs': [Tensor(np.ones([1, 1]).astype(np.float32)), Tensor(np.ones([1, 1, 9, 9]).astype(np.float32))],
  243. 'skip': ['backward']}),
  244. # rank of 2 is not 4
  245. ('DepthwiseConv2dNative4', {
  246. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  247. {'exception': ValueError, 'error_keywords': ['DepthwiseConv2dNative']}),
  248. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  249. Tensor(np.ones([1, 1, 9]).astype(np.float32))],
  250. 'skip': ['backward']}),
  251. # x_shape[1] != w_shape[1]
  252. ('DepthwiseConv2dNative5', {
  253. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  254. {'exception': ValueError, 'error_keywords': ['DepthwiseConv2dNative']}),
  255. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  256. Tensor(np.ones([1, 2, 9, 9]).astype(np.float32))],
  257. 'skip': ['backward']}),
  258. # kernel_size != w_shape[2:4]
  259. ('DepthwiseConv2dNative6', {
  260. 'block': (P.DepthwiseConv2dNative(2, (5, 5)),
  261. {'exception': ValueError, 'error_keywords': ['DepthwiseConv2dNative']}),
  262. 'desc_inputs': [Tensor(np.ones([1, 1, 9, 9]).astype(np.float32)),
  263. Tensor(np.ones([2, 1, 5, 6]).astype(np.float32))],
  264. 'skip': ['backward']}),
  265. # input is scalar
  266. ('MaxPoolWithArgmax0', {
  267. 'block': (P.MaxPoolWithArgmax(), {'exception': TypeError, 'error_keywords': ['MaxPoolWithArgmax']}),
  268. 'desc_inputs': [5.0],
  269. 'skip': ['backward']}),
  270. # input is Tensor(bool)
  271. ('MaxPoolWithArgmax1', {
  272. 'block': (P.MaxPoolWithArgmax(), {'exception': TypeError, 'error_keywords': ['MaxPoolWithArgmax']}),
  273. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_))],
  274. 'skip': ['backward']}),
  275. # rank of x is not 4
  276. ('MaxPoolWithArgmax2', {
  277. 'block': (P.MaxPoolWithArgmax(), {'exception': ValueError, 'error_keywords': ['MaxPoolWithArgmax']}),
  278. 'desc_inputs': [Tensor(np.ones([1, 1, 32]).astype(np.float32))],
  279. 'skip': ['backward']}),
  280. # kernel size is invalid(very large)
  281. ('MaxPoolWithArgmax3', {
  282. 'block': (P.MaxPoolWithArgmax(ksize=50), {'exception': ValueError, 'error_keywords': ['MaxPoolWithArgmax']}),
  283. 'desc_inputs': [Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))],
  284. 'skip': ['backward']}),
  285. # input is scalar
  286. ('MaxPool0', {
  287. 'block': (P.MaxPool(), {'exception': TypeError, 'error_keywords': ['MaxPool']}),
  288. 'desc_inputs': [5.0],
  289. 'skip': ['backward']}),
  290. # rank of x is not 4
  291. ('MaxPool1', {
  292. 'block': (P.MaxPool(), {'exception': ValueError, 'error_keywords': ['MaxPool']}),
  293. 'desc_inputs': [Tensor(np.ones([1, 1, 32]).astype(np.float32))],
  294. 'skip': ['backward']}),
  295. # rank of x is not 4
  296. ('MaxPool2', {
  297. 'block': (P.MaxPool(ksize=50, strides=1), {'exception': ValueError, 'error_keywords': ['MaxPool']}),
  298. 'desc_inputs': [Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))],
  299. 'skip': ['backward']}),
  300. # input is scalar
  301. ('AvgPool0', {
  302. 'block': (P.AvgPool(), {'exception': TypeError, 'error_keywords': ['AvgPool']}),
  303. 'desc_inputs': [5.0],
  304. 'skip': ['backward']}),
  305. # rank of x is not 4
  306. ('AvgPool1', {
  307. 'block': (P.AvgPool(), {'exception': ValueError, 'error_keywords': ['AvgPool']}),
  308. 'desc_inputs': [Tensor(np.ones([1, 1, 32]).astype(np.float32))],
  309. 'skip': ['backward']}),
  310. # rank of x is not 4
  311. ('AvgPool2', {
  312. 'block': (P.AvgPool(ksize=50, strides=1), {'exception': ValueError, 'error_keywords': ['AvgPool']}),
  313. 'desc_inputs': [Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))],
  314. 'skip': ['backward']}),
  315. # input is scalar
  316. ('Conv2DBackpropInput0', {
  317. 'block': (Conv2DBackpropInputNet(P.Conv2DBackpropInput(2, (5, 5)), (2, 3)),
  318. {'exception': TypeError, 'error_keywords': ['Conv2DBackpropInput']}),
  319. 'desc_inputs': [5.0, 5.0],
  320. 'skip': ['backward']}),
  321. # input is Tensor(bool)
  322. ('Conv2DBackpropInput1', {
  323. 'block': (Conv2DBackpropInputNet(P.Conv2DBackpropInput(2, (5, 5)), (2, 3)),
  324. {'exception': TypeError, 'error_keywords': ['Conv2DBackpropInput']}),
  325. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  326. 'skip': ['backward']}),
  327. # types of doutput and w mismatch
  328. ('Conv2DBackpropInput2', {
  329. 'block': (Conv2DBackpropInputNet(P.Conv2DBackpropInput(2, (5, 5)), (2, 3)),
  330. {'exception': TypeError, 'error_keywords': ['Conv2DBackpropInput']}),
  331. 'desc_inputs': [Tensor(np.ones([5]).astype(np.int32)), Tensor(np.ones([5]).astype(np.float32))],
  332. 'skip': ['backward']}),
  333. # types x_size is not tuple
  334. ('Conv2DBackpropInput3', {
  335. 'block': (Conv2DBackpropInputNet(P.Conv2DBackpropInput(2, (5, 5)), 2),
  336. {'exception': TypeError, 'error_keywords': ['Conv2DBackpropInput']}),
  337. 'desc_inputs': [Tensor(np.ones([5]).astype(np.int32)), Tensor(np.ones([5]).astype(np.float32))],
  338. 'skip': ['backward']}),
  339. # types x_size is not tuple(int,...)
  340. ('Conv2DBackpropInput4', {
  341. 'block': (Conv2DBackpropInputNet(P.Conv2DBackpropInput(2, (5, 5)), (2, 3.0)),
  342. {'exception': TypeError, 'error_keywords': ['Conv2DBackpropInput']}),
  343. 'desc_inputs': [Tensor(np.ones([5]).astype(np.int32)), Tensor(np.ones([5]).astype(np.float32))],
  344. 'skip': ['backward']}),
  345. # input is scalar
  346. ('BiasAdd0', {
  347. 'block': (P.BiasAdd(), {'exception': TypeError, 'error_keywords': ['BiasAdd']}),
  348. 'desc_inputs': [5.0, 5.0],
  349. 'skip': ['backward']}),
  350. # input is Tensor(bool)
  351. ('BiasAdd1', {
  352. 'block': (P.BiasAdd(), {'exception': TypeError, 'error_keywords': ['BiasAdd']}),
  353. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  354. 'skip': ['backward']}),
  355. # types of x and bias mismatch
  356. ('BiasAdd2', {
  357. 'block': (P.BiasAdd(), {'exception': TypeError, 'error_keywords': ['BiasAdd']}),
  358. 'desc_inputs': [Tensor(np.ones([5]).astype(np.int32)), Tensor(np.ones([5]).astype(np.float32))],
  359. 'skip': ['backward']}),
  360. # rank of x less than 2
  361. ('BiasAdd3', {
  362. 'block': (P.BiasAdd(), {'exception': ValueError, 'error_keywords': ['BiasAdd']}),
  363. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([5]).astype(np.float32))],
  364. 'skip': ['backward']}),
  365. # rank of bias is not equal to 1
  366. ('BiasAdd4', {
  367. 'block': (P.BiasAdd(), {'exception': ValueError, 'error_keywords': ['BiasAdd']}),
  368. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([5, 3]).astype(np.float32))],
  369. 'skip': ['backward']}),
  370. # b_shape[0] != x_shape[1]
  371. ('BiasAdd5', {
  372. 'block': (P.BiasAdd(), {'exception': ValueError, 'error_keywords': ['BiasAdd']}),
  373. 'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([5]).astype(np.float32))],
  374. 'skip': ['backward']}),
  375. # input x is scalar
  376. ('TopK0', {
  377. 'block': (TopKNet(P.TopK(), 5), {'exception': TypeError, 'error_keywords': ['TopK']}),
  378. 'desc_inputs': [5.0],
  379. 'skip': ['backward']}),
  380. # input x is Tensor(bool)
  381. ('TopK1', {
  382. 'block': (TopKNet(P.TopK(), 5), {'exception': TypeError, 'error_keywords': ['TopK']}),
  383. 'desc_inputs': [Tensor(np.ones([10]).astype(np.bool_))],
  384. 'skip': ['backward']}),
  385. # k is not integer
  386. ('TopK2', {
  387. 'block': (TopKNet(P.TopK(), 5.0), {'exception': TypeError, 'error_keywords': ['TopK']}),
  388. 'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
  389. 'skip': ['backward']}),
  390. # input is scalar
  391. ('SoftmaxCrossEntropyWithLogits0', {
  392. 'block': (P.SoftmaxCrossEntropyWithLogits(),
  393. {'exception': TypeError, 'error_keywords': ['SoftmaxCrossEntropyWithLogits']}),
  394. 'desc_inputs': [5.0, 5.0],
  395. 'skip': ['backward']}),
  396. # input is Tensor(bool)
  397. ('SoftmaxCrossEntropyWithLogits1', {
  398. 'block': (P.SoftmaxCrossEntropyWithLogits(),
  399. {'exception': TypeError, 'error_keywords': ['SoftmaxCrossEntropyWithLogits']}),
  400. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  401. 'skip': ['backward']}),
  402. # types of logits and labels mismatch
  403. ('SoftmaxCrossEntropyWithLogits2', {
  404. 'block': (P.SoftmaxCrossEntropyWithLogits(),
  405. {'exception': TypeError, 'error_keywords': ['SoftmaxCrossEntropyWithLogits']}),
  406. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float16)), Tensor(np.ones([5]).astype(np.float32))],
  407. 'skip': ['backward']}),
  408. # shapes of logits and labels mismatch
  409. ('SoftmaxCrossEntropyWithLogits3', {
  410. 'block': (P.SoftmaxCrossEntropyWithLogits(),
  411. {'exception': ValueError, 'error_keywords': ['SoftmaxCrossEntropyWithLogits']}),
  412. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([3]).astype(np.float32))],
  413. 'skip': ['backward']}),
  414. # input is scalar
  415. ('SparseSoftmaxCrossEntropyWithLogits0', {
  416. 'block': (P.SparseSoftmaxCrossEntropyWithLogits(),
  417. {'exception': TypeError, 'error_keywords': ['SparseSoftmaxCrossEntropyWithLogits']}),
  418. 'desc_inputs': [5.0, 5.0],
  419. 'skip': ['backward']}),
  420. # logits is Tensor(bool)
  421. ('SparseSoftmaxCrossEntropyWithLogits1', {
  422. 'block': (P.SparseSoftmaxCrossEntropyWithLogits(),
  423. {'exception': TypeError, 'error_keywords': ['SparseSoftmaxCrossEntropyWithLogits']}),
  424. 'desc_inputs': [Tensor(np.ones([5]).astype(np.bool_)), Tensor(np.ones([5]).astype(np.bool_))],
  425. 'skip': ['backward']}),
  426. # labels is Tensor(bool)
  427. ('SparseSoftmaxCrossEntropyWithLogits2', {
  428. 'block': (P.SparseSoftmaxCrossEntropyWithLogits(),
  429. {'exception': TypeError, 'error_keywords': ['SparseSoftmaxCrossEntropyWithLogits']}),
  430. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([5]).astype(np.bool_))],
  431. 'skip': ['backward']}),
  432. # logits_shape[0] != labels_shape[0]
  433. ('SparseSoftmaxCrossEntropyWithLogits3', {
  434. 'block': (P.SparseSoftmaxCrossEntropyWithLogits(),
  435. {'exception': ValueError, 'error_keywords': ['SparseSoftmaxCrossEntropyWithLogits']}),
  436. 'desc_inputs': [Tensor(np.ones([5]).astype(np.float32)), Tensor(np.ones([3]).astype(np.int32))],
  437. 'skip': ['backward']}),
  438. ]
  439. @mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
  440. def test_check_exception():
  441. return raise_set