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