test_ops.py 85.3 KB
Newer Older
Z
zhunaipan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test ops """
import functools
J
jinyaohui 已提交
17

Z
zhunaipan 已提交
18
import numpy as np
J
jinyaohui 已提交
19 20 21 22

import mindspore.nn as nn
import mindspore.ops.composite as C
from mindspore import Tensor
23
from mindspore import ops, Parameter, context
J
jinyaohui 已提交
24
from mindspore.common import dtype as mstype
Z
zhunaipan 已提交
25 26 27
from mindspore.ops import functional as F
from mindspore.ops import operations as P
from mindspore.ops.operations import _grad_ops as G
J
jiangjinsheng 已提交
28
from mindspore.ops.operations import _inner_ops as inner
Z
zhunaipan 已提交
29 30
from ..ut_filter import non_graph_engine
from ....mindspore_test_framework.mindspore_test import mindspore_test
31
from ....mindspore_test_framework.pipeline.forward.compile_forward \
Z
zhunaipan 已提交
32 33
    import (pipeline_for_compile_forward_ge_graph_for_case_by_case_config,
            pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
34
from ....mindspore_test_framework.pipeline.gradient.compile_gradient \
Z
zhunaipan 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    import pipeline_for_compile_grad_ge_graph_for_case_by_case_config


class InputBackward(nn.Cell):
    def __init__(self, network):
        super(InputBackward, self).__init__()
        self.network = network
        self.network.set_train()
        self.grad = C.grad_all_with_sens

    def construct(self, x1, x2, x3, sens):
        return self.grad(self.network)(x1, x2, x3, sens)


class NetForTupleInput(nn.Cell):
    def __init__(self, op):
        super(NetForTupleInput, self).__init__()
        self.op = op

    def construct(self, x1, x2):
        return self.op((x1, x2))


class StridedSlicessdNet(nn.Cell):
    def __init__(self):
        super(StridedSlicessdNet, self).__init__()
        self.rank = P.Rank()

    def construct(self, x1):
        return P.StridedSlice(1, 1, 0, self.rank(x1), 0)(x1, (0, 0), (0, 0), (1, 1))


class NetForConcat(nn.Cell):
    def __init__(self):
        super(NetForConcat, self).__init__()
        self.concat = P.Concat()

    def construct(self, x1):
        return self.concat((x1, x1))


class NetForConcat1(nn.Cell):
    def __init__(self):
        super(NetForConcat1, self).__init__()
        self.concat = P.Concat()

    def construct(self, x1, x2):
        return self.concat((x1, x2))


85
class NetForPackInput(nn.Cell):
L
liuxiao 已提交
86
    def __init__(self, op):
87
        super(NetForPackInput, self).__init__()
L
liuxiao 已提交
88 89 90 91 92
        self.op = op
        self.mul = P.Mul()

    def construct(self, *args):
        t = ()
93 94
        for element in args:
            t = t + (self.mul(element, element),)
L
liuxiao 已提交
95 96 97
        return self.op(t)


98
class NetForUnpackInput(nn.Cell):
L
liuxiao 已提交
99
    def __init__(self, op):
100
        super(NetForUnpackInput, self).__init__()
L
liuxiao 已提交
101 102 103 104 105 106 107
        self.op = op
        self.mul = P.Mul()

    def construct(self, x1):
        return self.op((self.mul(x1, x1)))


Z
zhunaipan 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
class NetForFlatten(nn.Cell):
    def __init__(self):
        super(NetForFlatten, self).__init__()
        self.flatten = P.Flatten()

    def construct(self, x, y):
        return self.flatten(x) + y


class NetForFlatten0D(nn.Cell):
    def __init__(self):
        super(NetForFlatten0D, self).__init__()
        self.flatten = P.Flatten()

    def construct(self, x):
        return self.flatten(x)


Z
zhaozhenlong 已提交
126 127 128 129 130 131 132
class NetForFlattenComposed(nn.Cell):
    # make flatten op together with other ops for testing flatten grad
    def __init__(self):
        super(NetForFlattenComposed, self).__init__()
        self.flatten = P.Flatten()

    def construct(self, x, y):
L
lihongkang 已提交
133
        return self.flatten(x + x) + y
Z
zhaozhenlong 已提交
134 135


Z
zhunaipan 已提交
136 137 138 139 140
class ArgmaxNet(nn.Cell):
    def __init__(self):
        super(ArgmaxNet, self).__init__()
        self.argmax = P.Argmax(axis=1)

141 142
    def construct(self, input_):
        return self.argmax(input_)
Z
zhunaipan 已提交
143 144 145 146 147 148 149


class ArgminNet(nn.Cell):
    def __init__(self):
        super(ArgminNet, self).__init__()
        self.argmin = P.Argmin(axis=1)

150 151
    def construct(self, input_):
        return self.argmin(input_)
Z
zhunaipan 已提交
152 153 154 155 156 157 158 159


class CumSumNet(nn.Cell):
    def __init__(self):
        super(CumSumNet, self).__init__()
        self.cumsum = P.CumSum()
        self.axis = 1

160 161
    def construct(self, input_):
        return self.cumsum(input_, self.axis)
Z
zhunaipan 已提交
162 163 164


class SummaryNet(nn.Cell):
165
    def __init__(self):
Z
zhunaipan 已提交
166 167 168 169 170 171 172 173 174
        super(SummaryNet, self).__init__()
        self.s = P.ScalarSummary()
        self.add = P.TensorAdd()

    def construct(self, x, y):
        self.s("x1", x)
        return self.add(x, y)


O
ougongchang 已提交
175
class HistogramSummaryNet(nn.Cell):
176
    def __init__(self):
O
ougongchang 已提交
177 178 179 180 181 182 183 184 185 186 187
        super(HistogramSummaryNet, self).__init__()
        self.summary = P.HistogramSummary()
        self.add = P.TensorAdd()

    def construct(self, x, y):
        out = self.add(x, y)
        string_in = "out"
        self.summary(string_in, out)
        return out


Z
zhaozhenlong 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200
class ScatterUpdate(nn.Cell):
    """ScatterUpdate net definition"""

    def __init__(self, ref_shape, dtype=np.float32, use_locking=False):
        super(ScatterUpdate, self).__init__()
        self.scatter_update = P.ScatterUpdate(use_locking)
        self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref")

    def construct(self, indices, updates):
        out = self.scatter_update(self.ref, indices, updates)
        return out


201 202 203
class ScatterMax(nn.Cell):
    """ScatterMax net definition"""

204
    def __init__(self, dtype=np.float32, use_locking=False):
205
        super(ScatterMax, self).__init__()
206 207
        self.scatter_max = P.ScatterMax(use_locking)
        self.ref = Parameter(Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype)), name="ref")
208 209 210 211 212

    def construct(self, indices, updates):
        out = self.scatter_max(self.ref, indices, updates)
        return out

J
jinyaohui 已提交
213

214 215 216 217 218 219 220 221 222 223 224 225 226
class ScatterMin(nn.Cell):
    """ScatterMin net definition"""

    def __init__(self, dtype=np.float32, use_locking=False):
        super(ScatterMin, self).__init__()
        self.scatter_min = P.ScatterMin(use_locking)
        self.ref = Parameter(Tensor(np.array([[-1.0, 2.0, 3.0], [-4.0, 1.0, 6.0]], dtype)), name="ref")

    def construct(self, indices, updates):
        out = self.scatter_min(self.ref, indices, updates)
        return out


Z
zhaozhenlong 已提交
227 228 229
class ScatterAdd(nn.Cell):
    """ScatterAdd net definition"""

230
    def __init__(self, ref_shape, dtype=np.float32, use_locking=False):
Z
zhaozhenlong 已提交
231
        super(ScatterAdd, self).__init__()
232
        self.scatter_add = P.ScatterAdd(use_locking)
233
        self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref")
Z
zhaozhenlong 已提交
234 235 236 237 238 239

    def construct(self, indices, updates):
        out = self.scatter_add(self.ref, indices, updates)
        return out


240 241 242 243 244 245 246 247 248 249 250 251 252
class ScatterSub(nn.Cell):
    """ScatterSub net definition"""

    def __init__(self, ref_shape, dtype=np.float32, use_locking=False):
        super(ScatterSub, self).__init__()
        self.scatter_sub = P.ScatterSub(use_locking)
        self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref")

    def construct(self, indices, updates):
        out = self.scatter_sub(self.ref, indices, updates)
        return out


Z
zhaozhenlong 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
class ScatterMul(nn.Cell):
    """ScatterMul net definition"""

    def __init__(self, ref_shape, dtype=np.float32, use_locking=False):
        super(ScatterMul, self).__init__()
        self.scatter_mul = P.ScatterMul(use_locking)
        self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref")

    def construct(self, indices, updates):
        out = self.scatter_mul(self.ref, indices, updates)
        return out


class ScatterDiv(nn.Cell):
    """ScatterDiv net definition"""

    def __init__(self, ref_shape, dtype=np.float32, use_locking=False):
        super(ScatterDiv, self).__init__()
        self.scatter_div = P.ScatterDiv(use_locking)
        self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)*10), name="ref")

    def construct(self, indices, updates):
        out = self.scatter_div(self.ref, indices, updates)
        return out


279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
class ApplyFtrlNet(nn.Cell):
    def __init__(self):
        super(ApplyFtrlNet, self).__init__()
        self.apply_ftrl = P.ApplyFtrl()
        self.lr = 0.001
        self.l1 = 0.0
        self.l2 = 0.0
        self.lr_power = -0.5
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
        self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")

    def construct(self, grad):
        out = self.apply_ftrl(self.var, self.accum, self.linear, grad, self.lr, self.l1, self.l2, self.lr_power)
        return out

295 296 297 298 299 300 301 302 303 304 305 306 307 308

class SparseApplyFtrlNet(nn.Cell):
    def __init__(self):
        super(SparseApplyFtrlNet, self).__init__()
        self.sparse_apply_ftrl = P.SparseApplyFtrl(lr=0.001, l1=0.0, l2=0.0, lr_power=-0.5)
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
        self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")

    def construct(self, grad, indices):
        out = self.sparse_apply_ftrl(self.var, self.accum, self.linear, grad, indices)
        return out


309 310 311 312 313 314 315 316 317 318 319 320 321
class SparseApplyFtrlV2Net(nn.Cell):
    def __init__(self):
        super(SparseApplyFtrlV2Net, self).__init__()
        self.sparse_apply_ftrl_v2 = P.SparseApplyFtrlV2(lr=0.001, l1=0.0, l2=0.0, l2_shrinkage=0.0, lr_power=-0.5)
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
        self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")

    def construct(self, grad, indices):
        out = self.sparse_apply_ftrl_v2(self.var, self.accum, self.linear, grad, indices)
        return out


322 323 324 325
class SparseApplyProximalAdagradNet(nn.Cell):
    def __init__(self):
        super(SparseApplyProximalAdagradNet, self).__init__()
        self.sparse_apply_proximal_adagrad = P.SparseApplyProximalAdagrad()
L
liuxiao 已提交
326 327
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
328 329 330 331
        self.lr = 0.01
        self.l1 = 0.0
        self.l2 = 0.0

L
liuxiao 已提交
332 333
    def construct(self, grad, indices):
        out = self.sparse_apply_proximal_adagrad(self.var, self.accum, self.lr, self.l1, self.l2, grad, indices)
334 335 336 337 338 339 340
        return out


class ApplyProximalAdagradNet(nn.Cell):
    def __init__(self):
        super(ApplyProximalAdagradNet, self).__init__()
        self.apply_proximal_adagrad = P.ApplyProximalAdagrad()
L
liuxiao 已提交
341 342
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
343 344 345 346
        self.lr = 0.01
        self.l1 = 0.0
        self.l2 = 0.0

L
liuxiao 已提交
347 348
    def construct(self, grad):
        out = self.apply_proximal_adagrad(self.var, self.accum, self.lr, self.l1, self.l2, grad)
349 350 351
        return out


352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
class ApplyAdaMaxNet(nn.Cell):
    def __init__(self):
        super(ApplyAdaMaxNet, self).__init__()
        self.apply_ada_max = P.ApplyAdaMax()
        self.beta1_power = 0.9
        self.lr = 0.001
        self.beta1 = 0.9
        self.beta2 = 0.99
        self.epsilon = 1e-10
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.m = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="m")
        self.v = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="v")

    def construct(self, grad):
        out = self.apply_ada_max(self.var, self.m, self.v, self.beta1_power, self.lr,
                                 self.beta1, self.beta2, self.epsilon, grad)
        return out


class ApplyAdadeltaNet(nn.Cell):
    def __init__(self):
        super(ApplyAdadeltaNet, self).__init__()
        self.apply_adadelta = P.ApplyAdadelta()
        self.lr = 0.001
        self.rho = 0.0
        self.epsilon = 1e-6
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
        self.accum_update = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum_update")

    def construct(self, grad):
        out = self.apply_adadelta(self.var, self.accum, self.accum_update, self.lr, self.rho, self.epsilon, grad)
        return out


class ApplyAdagradNet(nn.Cell):
    def __init__(self):
        super(ApplyAdagradNet, self).__init__()
        self.apply_adagrad = P.ApplyAdagrad()
        self.lr = 0.001
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")

    def construct(self, grad):
        out = self.apply_adagrad(self.var, self.accum, self.lr, grad)
        return out


class ApplyAdagradV2Net(nn.Cell):
    def __init__(self):
        super(ApplyAdagradV2Net, self).__init__()
        self.apply_adagrad_v2 = P.ApplyAdagradV2(epsilon=1e-6)
        self.lr = 0.001
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")

    def construct(self, grad):
        out = self.apply_adagrad_v2(self.var, self.accum, self.lr, grad)
        return out


L
liuxiao 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
class ApplyAddSignNet(nn.Cell):
    def __init__(self):
        super(ApplyAddSignNet, self).__init__()
        self.apply_add_sign = P.ApplyAddSign()
        self.lr = 0.001
        self.alpha = 1.0
        self.sign_decay = 0.99
        self.beta = 0.99
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.m = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="m")

    def construct(self, grad):
        out = self.apply_add_sign(self.var, self.m, self.lr, self.alpha, self.sign_decay, self.beta, grad)
        return out


class ApplyPowerSignNet(nn.Cell):
    def __init__(self):
        super(ApplyPowerSignNet, self).__init__()
        self.apply_power_sign = P.ApplyPowerSign()
        self.lr = 0.001
        self.logbase = np.e
        self.sign_decay = 0.99
        self.beta = 0.99
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.m = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="m")

    def construct(self, grad):
        out = self.apply_power_sign(self.var, self.m, self.lr, self.logbase, self.sign_decay, self.beta, grad)
        return out


class ApplyGradientDescentNet(nn.Cell):
    def __init__(self):
        super(ApplyGradientDescentNet, self).__init__()
        self.apply_gradient_descent = P.ApplyGradientDescent()
        self.alpha = 0.001
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")

    def construct(self, delta):
        out = self.apply_gradient_descent(self.var, self.alpha, delta)
        return out


class ApplyProximalGradientDescentNet(nn.Cell):
    def __init__(self):
        super(ApplyProximalGradientDescentNet, self).__init__()
        self.apply_proximal_gradient_descent = P.ApplyProximalGradientDescent()
        self.alpha = 0.001
        self.l1 = 0.0
        self.l2 = 0.0
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")

    def construct(self, delta):
        out = self.apply_proximal_gradient_descent(self.var, self.alpha, self.l1, self.l2, delta)
        return out


471 472 473 474 475 476 477 478 479 480 481
class SparseApplyAdagradNet(nn.Cell):
    def __init__(self):
        super(SparseApplyAdagradNet, self).__init__()
        self.sparse_apply_adagrad = P.SparseApplyAdagrad(lr=0.01)
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")

    def construct(self, grad, indices):
        out = self.sparse_apply_adagrad(self.var, self.accum, grad, indices)
        return out

B
buxue 已提交
482

483 484 485 486 487 488 489 490 491 492 493 494
class SparseApplyAdagradV2Net(nn.Cell):
    def __init__(self):
        super(SparseApplyAdagradV2Net, self).__init__()
        self.sparse_apply_adagrad_v2 = P.SparseApplyAdagradV2(lr=0.01, epsilon=0.001)
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")

    def construct(self, grad, indices):
        out = self.sparse_apply_adagrad_v2(self.var, self.accum, grad, indices)
        return out


Z
zhaojichen 已提交
495 496 497 498 499 500
class ApplyRMSNet(nn.Cell):
    def __init__(self):
        super(ApplyRMSNet, self).__init__()
        self.apply_rms = P.ApplyRMSProp()
        self.lr = 0.001
        self.rho = 0.0
501
        self.momentum = 0.0
Z
zhaojichen 已提交
502 503 504 505 506 507 508 509
        self.epsilon = 1e-10
        self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
        self.ms = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="ms")
        self.moment = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="moment")

    def construct(self, grad):
        out = self.apply_rms(self.var, self.ms, self.moment, self.lr, grad, self.rho, self.momentum, self.epsilon)
        return out
510

L
lihongkang 已提交
511

512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
class InplaceAddNet(nn.Cell):
    def __init__(self):
        super(InplaceAddNet, self).__init__()
        self.inplace_add = P.InplaceAdd(indices=(0, 1))

    def construct(self, x, v):
        out = self.inplace_add(x, v)
        return out


class InplaceSubNet(nn.Cell):
    def __init__(self):
        super(InplaceSubNet, self).__init__()
        self.inplace_sub = P.InplaceSub(indices=(0, 1))

    def construct(self, x, v):
        out = self.inplace_sub(x, v)
        return out


P
pkuliuliu 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544
class NormalNet(nn.Cell):
    def __init__(self, shape=None, mean=0.0, stddev=1.0, seed=0):
        super(NormalNet, self).__init__()
        self.normal = P.Normal(seed=seed)
        self.shape = shape
        self.mean = Tensor(mean, mstype.float32)
        self.stddev = Tensor(stddev, mstype.float32)

    def construct(self):
        out = self.normal(self.shape, self.mean, self.stddev)
        return out


B
buxue 已提交
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
class StridedSliceNet(nn.Cell):
    def __init__(self):
        super(StridedSliceNet, self).__init__()
        self.begins = (1, 2, 3, 2, 1)
        self.ends = (5, 6, 7, 8, 9)
        self.strides = (1, 2, 3, 2, 1)
        self.strided_slice_0 = P.StridedSlice(begin_mask=3, end_mask=5, ellipsis_mask=4,
                                              shrink_axis_mask=2, new_axis_mask=8)
        self.strided_slice_1 = P.StridedSlice(begin_mask=5, end_mask=2, ellipsis_mask=2,
                                              shrink_axis_mask=6, new_axis_mask=10)
        self.strided_slice_2 = P.StridedSlice(begin_mask=3, end_mask=3, ellipsis_mask=4,
                                              shrink_axis_mask=5, new_axis_mask=13)
        self.strided_slice_3 = P.StridedSlice(begin_mask=0, end_mask=0, ellipsis_mask=4,
                                              shrink_axis_mask=12, new_axis_mask=15)
        self.const_0 = Tensor(np.ones([6, 8, 9, 1, 8], np.float32))
        self.const_1 = Tensor(np.ones([5, 7, 8, 1, 8], np.float32))
        self.const_2 = Tensor(np.ones([1, 3, 7, 8, 9, 1, 8], np.float32))
        self.const_3 = Tensor(np.ones([1, 1, 6, 7, 8, 9, 1, 8], np.float32))

    def construct(self, x):
        out_0 = self.strided_slice_0(x, self.begins, self.ends, self.strides) + self.const_0
        out_1 = self.strided_slice_1(x, self.begins, self.ends, self.strides) + self.const_1
        out_2 = self.strided_slice_2(x, self.begins, self.ends, self.strides) + self.const_2
        out_3 = self.strided_slice_3(x, self.begins, self.ends, self.strides) + self.const_3
        return out_0, out_1, out_2, out_3


def test_strided_slice_const():
    class StridedSLiceConstNet(nn.Cell):
        """StridedSLiceConstNet net definition"""

        def __init__(self):
            super(StridedSLiceConstNet, self).__init__()
            self.begins = (0, 2, -5, 2, 1)
            self.ends = (0, 6, 9, 8, 9)
            self.strides = (1, 2, 1, 2, 1)
            self.strided_slice = P.StridedSlice(begin_mask=2,
                                                end_mask=6,
                                                ellipsis_mask=4,
                                                shrink_axis_mask=6,
                                                new_axis_mask=18)

        def construct(self, x):
            out = self.strided_slice(x, self.begins, self.ends, self.strides)
            return out

    net = StridedSLiceConstNet()
    context.set_context(mode=context.GRAPH_MODE, save_graphs=True)
    x = Tensor(np.ones([6, 7, 8, 9, 10]), mstype.float32)
    ret = net(x)
    assert ret.shape == (0, 1, 7, 8, 9, 3, 1)
    assert (ret.asnumpy() == np.array([], np.float32).reshape([0, 1, 7, 8, 9, 3, 1])).all()


J
jiangjinsheng 已提交
599 600 601 602 603 604 605 606 607
class ParallelConcatNet(nn.Cell):
    def __init__(self):
        super(ParallelConcatNet, self).__init__()
        self.parallel_concat = P.ParallelConcat()

    def construct(self, x1, x2):
        return self.parallel_concat((x1, x2))


Z
zhunaipan 已提交
608
test_case_math_ops = [
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    ('BitwiseAnd', {
        'block': P.BitwiseAnd(),
        'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
                        Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
        'skip': ['backward']}),
    ('BitwiseAnd_1', {
        'block': P.BitwiseAnd(),
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
                        Tensor(np.array([1, 1, 1]), mstype.int16)],
        'skip': ['backward']}),
    ('BitwiseOr', {
        'block': P.BitwiseOr(),
        'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
                        Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
        'skip': ['backward']}),
    ('BitwiseOr_1', {
        'block': P.BitwiseOr(),
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
                        Tensor(np.array([1, 1, 1]), mstype.int16)],
        'skip': ['backward']}),
    ('BitwiseXor', {
        'block': P.BitwiseXor(),
        'desc_inputs': [Tensor(np.array([0, 0, 1, -1, 1, 1, 1]), mstype.int16),
                        Tensor(np.array([0, 1, 1, -1, -1, 2, 3]), mstype.int16)],
        'skip': ['backward']}),
    ('BitwiseXor_1', {
        'block': P.BitwiseXor(),
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [-1, -2, -3]]), mstype.int16),
                        Tensor(np.array([1, 1, 1]), mstype.int16)],
        'skip': ['backward']}),
Z
zhunaipan 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
    ('Neg', {
        'block': P.Neg(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('Sub', {
        'block': P.Sub(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('TensorAdd', {
        'block': P.TensorAdd(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Mul0', {
        'block': P.Mul(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Mul1', {
        'block': P.Mul(),
        'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Mul2', {
        'block': P.Mul(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Mul3', {
        'block': P.Mul(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Mul4', {
        'block': P.Mul(),
        'desc_inputs': [[2, 3, 3, 5], [3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Add0', {
        'block': P.TensorAdd(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Add1', {
        'block': P.TensorAdd(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Add2', {
        'block': P.TensorAdd(),
        'desc_inputs': [[2, 3, 3, 5], [3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Add3', {
        'block': P.TensorAdd(),
        'desc_inputs': [[2, 3, 1, 1], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Add4', {
        'block': P.TensorAdd(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 1, 1]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
    ('Minimum', {
        'block': P.Minimum(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
702
    ('Pow_0', {
Z
zhunaipan 已提交
703 704 705 706
        'block': P.Pow(),
        'desc_const': [2.0],
        'desc_inputs': [[2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
707 708 709 710
    ('Pow_1', {
        'block': P.Pow(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
Z
zhunaipan 已提交
711 712 713 714
    ('Exp', {
        'block': P.Exp(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
Z
zhouneng 已提交
715 716 717 718
    ('Expm1', {
        'block': P.Expm1(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
L
liuxiao 已提交
719 720 721 722
    ('Erf', {
        'block': P.Erf(),
        'desc_inputs': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))],
        'desc_bprop': [Tensor(np.array([-2, -1, 0, 1, 2]).astype(np.float16))]}),
Z
zhunaipan 已提交
723 724 725
    ('Floor', {
        'block': P.Floor(),
        'desc_inputs': [[2, 512, 56, 56]],
726 727 728 729 730
        'desc_bprop': [[2, 512, 56, 56]],
        'skip': ['backward']}),
    ('Ceil', {
        'block': P.Ceil(),
        'desc_inputs': [[2, 512, 56, 56]],
Z
zhunaipan 已提交
731 732
        'desc_bprop': [[2, 512, 56, 56]],
        'skip': ['backward']}),
733 734 735 736 737 738 739 740 741 742
    ('InplaceAdd', {
        'block': InplaceAddNet(),
        'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
                        Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
        'skip': ['backward']}),
    ('InplaceSub', {
        'block': InplaceSubNet(),
        'desc_inputs': [Tensor(np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)),
                        Tensor(np.array([[0.5, 1], [1, 1.5]]).astype(np.float32))],
        'skip': ['backward']}),
Z
zhunaipan 已提交
743 744
    ('ACos', {
        'block': P.ACos(),
Z
zhouneng 已提交
745 746 747 748 749 750
        'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
        'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
    ('ACosGrad', {
        'block': G.ACosGrad(),
        'desc_inputs': [[2, 3], [2, 3]],
        'skip': ['backward']}),
Z
zhangz0911gm 已提交
751 752
    ('Acosh', {
        'block': P.Acosh(),
Z
zhouneng 已提交
753 754 755 756 757 758
        'desc_inputs': [Tensor(np.array([2., 3.]).astype(np.float32))],
        'desc_bprop': [Tensor(np.array([2., 3.]).astype(np.float32))]}),
    ('AcoshGrad', {
        'block': G.AcoshGrad(),
        'desc_inputs': [[2, 3], [2, 3]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
759 760 761 762
    ('Sin', {
        'block': P.Sin(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
763 764 765 766 767 768 769 770
    ('Asin', {
        'block': P.Asin(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
    ('Asinh', {
        'block': P.Asinh(),
        'desc_inputs': [[3, 4, 5]],
        'desc_bprop': [[3, 4, 5]]}),
Z
zhunaipan 已提交
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
    ('Reciprocal', {
        'block': P.Reciprocal(),
        'desc_inputs': [[2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Minimum_0', {
        'block': P.Minimum(),
        'desc_inputs': [[2, 3, 3, 5], [3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Maximum', {
        'block': P.Maximum(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Maximum_0', {
        'block': P.Maximum(),
        'desc_inputs': [[3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('MaximumGrad', {
        'block': G.MaximumGrad(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
        'skip': ['backward']}),
    ('MinimumGrad', {
        'block': G.MinimumGrad(),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5], [2, 3, 3, 5]],
        'skip': ['backward']}),
    ('StridedSlice', {
        'block': P.StridedSlice(),
        'desc_const': [(0, 1, 2, 1),
798 799
                       (2, 3, 3, 4),
                       (1, 1, 1, 1)],
Z
zhunaipan 已提交
800 801 802 803 804
        'desc_inputs': [[2, 3, 3, 5]],
        'desc_bprop': [[2, 2, 1, 3]]}),
    ('Slice_1', {
        'block': P.Slice(),
        'desc_const': [(0, 1, 2, 1),
805
                       (1, 1, 1, 2)],
Z
zhunaipan 已提交
806 807 808 809 810
        'desc_inputs': [[2, 3, 3, 5]],
        'desc_bprop': [[1, 1, 1, 2]]}),
    ('StridedSliceGrad', {
        'block': G.StridedSliceGrad(),
        'desc_const': [(64, 1, 1024),
811 812 813
                       (0, 1, 0),
                       (64, 2, 1024),
                       (1, 1, 1)],
Z
zhunaipan 已提交
814 815 816 817 818
        'desc_inputs': [[64, 128, 1024]],
        'skip': ['backward']}),
    ('RandomChoiceWithMask', {
        'block': P.RandomChoiceWithMask(256),
        'desc_inputs': [Tensor(np.random.rand(24000, 4).astype(np.bool_))],
819
        'desc_bprop': [[256, 4], [256, 4]],
Z
zhunaipan 已提交
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
        'skip': ['backward']}),
    ('LessEqual', {
        'block': P.LessEqual(),
        'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
                        Tensor(np.random.rand(4).astype(np.float16))],
        'skip': ['backward']}),
    ('Less', {
        'block': P.Less(),
        'desc_inputs': [[2, 1, 4, 5], [2, 1, 4, 5]],
        'desc_bprop': [Tensor(np.zeros((2, 1, 4, 5), np.bool_))],
        'skip': ['backward']}),
    ('RealDiv_0', {
        'block': P.RealDiv(),
        'desc_const': [Tensor(2048.0), Tensor(0.0)],
        'desc_inputs': [],
        'skip': ['backward']}),
    ('RealDiv', {
        'block': P.RealDiv(),
        'desc_inputs': [[4], Tensor(np.ones(4).astype(np.float32))],
        'desc_bprop': [[4]]}),
    ('RealDiv_1', {
        'block': P.RealDiv(),
        'desc_inputs': [[512, 1024], [512, 1024]],
        'desc_bprop': [[512, 1024]]}),
    ('FloorDiv', {
        'block': P.FloorDiv(),
        'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)),
                        Tensor(np.random.rand(4).astype(np.float16))],
        'skip': ['backward']}),
Z
zhangz0911gm 已提交
849 850
    ('FloorMod', {
        'block': P.FloorMod(),
B
buxue 已提交
851 852
        'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
        'desc_bprop': [[2, 3, 4, 5]]}),
Z
zhunaipan 已提交
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
    ('identity', {
        'block': ops.functional.identity,
        'desc_inputs': [[2, 2]],
        'skip': ['backward']}),
    ('MatMul_1', {
        'block': P.MatMul(transpose_a=False, transpose_b=False),
        'desc_inputs': [[1024, 160], [160, 1024]],
        'desc_bprop': [[1024, 1024]]}),
    ('MatMul_2', {
        'block': P.MatMul(transpose_a=True, transpose_b=True),
        'desc_inputs': [[160, 1024], [1024, 160]],
        'desc_bprop': [[1024, 1024]]}),
    ('Sub', {
        'block': P.Sub(),
        'desc_inputs': [[3], [3]],
        'desc_bprop': [[3]]}),
    ('TruncatedNormal', {
        'block': P.TruncatedNormal(),
871
        'desc_const': [(1, 2, 3)],
Z
zhunaipan 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
        'desc_inputs': [],
        'skip': ['backward'],
        'add_fake_input': True}),
    ('Select', {
        'block': P.Select(),
        'desc_inputs': [Tensor(np.array([[True, False, False], [False, True, True]])),
                        [2, 3], [2, 3]],
        'desc_bprop': [[2, 3]]}),
    ('Rank', {
        'block': P.Rank(),
        'desc_inputs': [[2, 3]],
        'skip': ['backward']}),
    ('InvertPermutation', {
        'block': P.InvertPermutation(),
        'desc_const': [(0, 3, 1, 2)],
        'desc_inputs': [],
        'skip': ['backward']}),
    ('Square', {
        'block': P.Square(),
        'desc_inputs': [[4]],
        'desc_bprop': [[4]]}),
    ('Rsqrt', {
        'block': P.Rsqrt(),
        'desc_inputs': [[4]],
        'desc_bprop': [[4]]}),
    ('Sqrt', {
        'block': P.Sqrt(),
        'desc_inputs': [[4]],
        'desc_bprop': [[4]]}),
    ('RealDiv', {
        'block': P.RealDiv(),
        'desc_inputs': [[4, 5], [2, 3, 4, 5]],
        'desc_bprop': [[2, 3, 4, 5]]}),
    ('Div', {
        'block': P.Div(),
        'desc_inputs': [[4, 5], [2, 3, 4, 5]],
        'desc_bprop': [[2, 3, 4, 5]]}),
    ('Equal', {
        'block': P.Equal(),
        'desc_inputs': [[3, 4, 5], [4, 5]],
        'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
    ('NotEqual', {
        'block': P.NotEqual(),
        'desc_inputs': [[4, 1], [2, 3, 4, 5]],
        'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
C
candanzg 已提交
917 918
    ('NotEqual_0', {
        'block': P.NotEqual(),
919
        'desc_inputs': [1, [2, 3, 4, 5]],
C
candanzg 已提交
920 921
        'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))],
        'skip': ['backward']}),
922 923 924 925
    ('ApproximateEqual', {
        'block': P.ApproximateEqual(),
        'desc_inputs': [[3, 4, 5], [3, 4, 5]],
        'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
Z
zhunaipan 已提交
926 927 928 929 930 931 932 933 934 935 936 937 938
    ('Greater', {
        'block': P.Greater(),
        'desc_inputs': [[2, 3, 4, 1], [4, 5]],
        'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
    ('GreaterEqual', {
        'block': P.GreaterEqual(),
        'desc_inputs': [[2, 3, 4, 1], [4, 5]],
        'desc_bprop': [Tensor(np.ones((2, 3, 4, 5), np.bool_))]}),
    ('LogicalNot', {
        'block': P.LogicalNot(),
        'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_))],
        'desc_bprop': [Tensor(np.ones((3, 4, 5), np.bool_))]}),
    ('LogicalAnd', {
939 940 941
        'block': P.LogicalAnd(),
        'desc_inputs': [Tensor(np.zeros((2, 3, 4), np.bool_)), Tensor(np.ones((1), np.bool_))],
        'desc_bprop': [Tensor(np.zeros((2, 3, 4), np.bool_))]}),
Z
zhunaipan 已提交
942
    ('LogicalOr', {
943 944 945
        'block': P.LogicalOr(),
        'desc_inputs': [Tensor(np.zeros((3, 4, 5), np.bool_)), Tensor(np.ones((3, 1, 1), np.bool_))],
        'desc_bprop': [Tensor(np.zeros((3, 4, 5), np.bool_))]}),
Z
zhunaipan 已提交
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
    ('NpuAllocFloatStatus', {
        'block': P.NPUAllocFloatStatus(),
        'desc_inputs': [],
        'add_fack_input': True,
        'fack_input_type': np.float32,
        'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
        'skip': ['backward']}),
    ('NpuGetFloatStatus', {
        'block': P.NPUGetFloatStatus(),
        'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
        'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
        'skip': ['backward']}),
    ('NpuClearFloatStatus', {
        'block': P.NPUClearFloatStatus(),
        'desc_inputs': [Tensor(np.zeros([8]).astype(np.float32))],
        'desc_bprop': [Tensor(np.zeros([8]).astype(np.float32))],
        'skip': ['backward']}),
    ('CheckValid', {
        'block': P.CheckValid(),
        'desc_inputs': [[20000, 4], [3]],
        'desc_bprop': [[20000]],
        'skip': ['backward']}),
    ('NMSWithMask', {
        'block': P.NMSWithMask(0.5),
        'desc_inputs': [[128, 5]],
        'desc_bprop': [[128, 5], [128], [128]],
        'skip': ['backward']}),
    ('Abs', {
        'block': P.Abs(),
        'desc_inputs': [[4]],
        'desc_bprop': [[4]]}),
    ('CumSum', {
Z
zhouneng 已提交
978 979
        'block': CumSumNet(),
        'desc_inputs': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))],
980 981
        'desc_bprop': [Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7],
                                        [1, 3, 7, 9]]).astype(np.float32))]}),
Z
zhunaipan 已提交
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
    ('ReduceSum_3', {
        'block': P.ReduceSum(),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[2]]}),
    ('ReduceSum_4', {
        'block': P.ReduceSum(keep_dims=True),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[1, 2]]}),
    ('ReduceSum_5', {
        'block': P.ReduceSum(keep_dims=True),
        'desc_inputs': [[2, 3, 4]],
        'desc_bprop': [[1, 1, 1]]}),
    ('ReduceSum_6', {
        'block': P.ReduceSum(),
        'desc_inputs': [[2, 3, 4]],
        'desc_bprop': [[1]]}),
    ('Sum_0', {
        'block': P.ReduceSum(),
        'desc_const': [(1,)],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[3]]}),
    ('Sum_1', {
        'block': P.ReduceSum(keep_dims=True),
        'desc_const': [(1,)],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[3, 1]]}),
    ('Sum_2', {
        'block': P.ReduceSum(),
        'desc_const': [(0, 1)],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[1]]}),
    ('Sum_3', {
        'block': P.ReduceSum(),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[2]]}),
    ('Sum_4', {
        'block': P.ReduceSum(keep_dims=True),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[1, 2]]}),
    ('Sum_5', {
        'block': P.ReduceSum(keep_dims=True),
        'desc_const': [()],
        'desc_inputs': [[2, 3, 4]],
        'desc_bprop': [[1, 1, 1]]}),
    ('Sum_6', {
        'block': P.ReduceSum(),
        'desc_const': [()],
        'desc_inputs': [[2, 3, 4]],
        'desc_bprop': [[1]]}),
    ('Sign', {
        'block': P.Sign(),
        'desc_inputs': [[3]],
        'desc_bprop': [[3]]}),
    ('Round', {
        'block': P.Round(),
        'desc_inputs': [[3]],
Z
zhaozhenlong 已提交
1042 1043 1044 1045 1046
        'desc_bprop': [[3]]}),
    ('Atan2', {
        'block': P.Atan2(),
        'desc_inputs': [Tensor(np.array([0, 1]).astype(np.float32)),
                        Tensor(np.array([1, 1]).astype(np.float32))],
Z
zhaojichen 已提交
1047 1048 1049 1050 1051 1052
        'desc_bprop': [[2]]}),
    ('SquareSumAll', {
        'block': P.SquareSumAll(),
        'desc_inputs': [Tensor(np.array([0, 1, 4, 5]).astype(np.float32)),
                        Tensor(np.array([1, 1, 3, 7]).astype(np.float32))],
        'skip': ['backward']}),
Z
zhouneng 已提交
1053 1054 1055 1056
    ('Cos', {
        'block': P.Cos(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
L
lihongkang 已提交
1057 1058 1059 1060 1061
    ('ReduceAll', {
        'block': P.ReduceAll(),
        'desc_const': [1],
        'desc_inputs': [Tensor(np.array([[True, False], [True, True]]))],
        'desc_bprop': []}),
J
jiangjinsheng 已提交
1062 1063 1064 1065 1066 1067 1068 1069
    ('BesselI0e', {
        'block': P.BesselI0e(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
    ('BesselI1e', {
        'block': P.BesselI1e(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
Z
zhouneng 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
    ('Atan', {
        'block': P.Atan(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
    ('AtanGrad', {
        'block': G.AtanGrad(),
        'desc_inputs': [[2, 3], [2, 3]],
        'skip': ['backward']}),
    ('Atanh', {
        'block': P.Atanh(),
        'desc_inputs': [[2, 3]],
        'desc_bprop': [[2, 3]]}),
L
lihongkang 已提交
1082 1083 1084 1085 1086 1087 1088 1089
    ('Cosh', {
        'block': P.Cosh(),
        'desc_inputs': [[3, 4, 5]],
        'desc_bprop': [[3, 4, 5]]}),
    ('Sinh', {
        'block': P.Sinh(),
        'desc_inputs': [[3, 4, 5]],
        'desc_bprop': [[3, 4, 5]]}),
Z
zhaojichen 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098
    ('Inv', {
        'block': P.Inv(),
        'desc_inputs': [[21, 9, 12, 5]],
        'desc_bprop': [[21, 9, 12, 5]]}),
    ('Invert', {
        'block': P.Invert(),
        'desc_inputs': [Tensor(np.array([[24, 4, 13, 9], [1, 5, 10, 8]]).astype(np.int16))],
        'desc_bprop': [],
        'skip': ['backward']}),
1099 1100 1101 1102 1103
    ('HistogramFixedWidth', {
        'block': P.HistogramFixedWidth(5),
        'desc_inputs': [Tensor([-1.0, 0.0, 1.5, 2.0, 5.0, 15], mstype.float16), Tensor([0.0, 5.0], mstype.float16)],
        'desc_bprop': [],
        'skip': ['backward']}),
P
pkuliuliu 已提交
1104 1105 1106 1107
    ('Normal', {
        'block': NormalNet((3, 2, 4), 0.0, 1.0, 0),
        'desc_inputs': [],
        'skip': ['backward']}),
J
jiangjinsheng 已提交
1108 1109 1110 1111
    ('Mod', {
        'block': P.Mod(),
        'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]],
        'desc_bprop': [[2, 3, 4, 5]]}),
Z
zhunaipan 已提交
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
]

test_case_nn_ops = [
    ('BiasAdd', {
        'block': P.BiasAdd(),
        'desc_inputs': [[1, 3, 3, 3], [3]],
        'desc_bprop': [[1, 3, 3, 3]]}),
    ('BiasAddGrad', {
        'block': G.BiasAddGrad(),
        'desc_inputs': [[1, 3, 3, 3]],
        'skip': ['backward']}),
    ('Gelu', {
        'block': P.Gelu(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('GeluGrad', {
        'block': G.GeluGrad(),
        'desc_inputs': [[2, 2], [2, 2], [2, 2]],
        'desc_bprop': [[2, 2]],
        'skip': ['backward']}),
    ('Tanh', {
        'block': P.Tanh(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('TanhGrad', {
        'block': G.TanhGrad(),
        'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]],
        'skip': ['backward']}),
    ('ReLU', {
        'block': P.ReLU(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('ReLU6', {
        'block': P.ReLU6(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
1149 1150 1151
    ('ReLUV2', {
        'block': P.ReLUV2(),
        'desc_inputs': [[1, 3, 4, 4]],
P
panyifeng 已提交
1152
        'desc_bprop': [[1, 3, 4, 4], ([1, 1, 4, 4, 2], {'dtype': np.uint8})]}),
Z
zhunaipan 已提交
1153 1154 1155 1156
    ('ReLUGrad', {
        'block': G.ReluGrad(),
        'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
        'skip': ['backward']}),
1157 1158 1159 1160 1161 1162 1163 1164
    ('Softplus', {
        'block': P.Softplus(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('SoftplusGrad', {
        'block': G.SoftplusGrad(),
        'desc_inputs': [[1, 3, 4, 4], [1, 3, 4, 4]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
    ('Elu', {
        'block': P.Elu(),
        'desc_inputs': [[2, 3, 4]],
        'desc_bprop': [[2, 3, 4]]}),
    ('EluGrad', {
        'block': G.EluGrad(),
        'desc_inputs': [[2, 3, 4], [2, 3, 4]],
        'desc_bprop': [[2, 3, 4]],
        'skip': ['backward']}),
    ('Sigmoid', {
        'block': P.Sigmoid(),
        'desc_inputs': [[1, 3, 4, 4]],
        'desc_bprop': [[1, 3, 4, 4]]}),
    ('MaxPool', {
        'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
        'desc_inputs': [[100, 3, 28, 28]],
        'desc_bprop': [[100, 3, 14, 14]]}),
    ('MaxPoolGrad', {
        'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
        'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]],
        'desc_bprop': [[3, 4, 6, 6]],
        'skip': ['backward']}),
    ('AvgPool', {
        'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"),
        'desc_inputs': [[100, 3, 28, 28]],
        'desc_bprop': [[100, 3, 14, 14]]}),
    ('AvgPoolGrad', {
        'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"),
        'desc_const': [(3, 4, 6, 6)],
        'const_first': True,
        'desc_inputs': [[3, 4, 6, 6]],
        'desc_bprop': [[3, 4, 6, 6]],
        'skip': ['backward']}),
    ('MaxPoolWithArgmax', {
B
buxue 已提交
1199
        'block': P.MaxPoolWithArgmax(ksize=2, strides=2),
Z
zhunaipan 已提交
1200
        'desc_inputs': [[128, 32, 32, 64]],
P
panyifeng 已提交
1201
        'desc_bprop': [[128, 32, 16, 32], ([128, 32, 4, 33], {'dtype': np.uint16})]}),
Z
zhunaipan 已提交
1202 1203 1204 1205 1206 1207 1208 1209
    ('SoftmaxCrossEntropyWithLogits', {
        'block': P.SoftmaxCrossEntropyWithLogits(),
        'desc_inputs': [[1, 10], [1, 10]],
        'desc_bprop': [[1], [1, 10]],
        'skip': ['backward_exec']}),
    ('Flatten', {
        'block': P.Flatten(),
        'desc_inputs': [[128, 32, 32, 64]],
Z
zhaozhenlong 已提交
1210
        'desc_bprop': [[128, 65536]]}),
Z
zhunaipan 已提交
1211 1212 1213
    ('LogSoftmax', {
        'block': P.LogSoftmax(),
        'desc_inputs': [[64, 2]],
P
panyifeng 已提交
1214
        'desc_bprop': [[64, 2]]}),
Z
zhunaipan 已提交
1215 1216 1217 1218 1219
    ('LogSoftmaxGrad', {
        'block': G.LogSoftmaxGrad(),
        'desc_inputs': [[16, 1234], [16, 1234]],
        'desc_bprop': [[64, 2]],
        'skip': ['backward']}),
1220 1221 1222 1223 1224 1225 1226 1227 1228
    ('L2Normalize', {
        'block': P.L2Normalize(),
        'desc_inputs': [[2, 2]],
        'desc_bprop': [[2, 2]]}),
    ('L2NormalizeGrad', {
        'block': G.L2NormalizeGrad(),
        'desc_inputs': [[2, 2], [2, 2], [2, 2]],
        'desc_bprop': [[2, 2]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1229 1230 1231
    ('LayerNorm', {
        'block': P.LayerNorm(),
        'desc_inputs': [[2, 16], [16], [16]],
P
panyifeng 已提交
1232
        'desc_bprop': [[2, 16], [2, 1], [2, 1]]}),
Z
zhunaipan 已提交
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
    ('LayerNormGrad', {
        'block': G.LayerNormGrad(),
        'desc_inputs': [[2, 16], [2, 16], [2, 16], [2, 16], [16]],
        'desc_bprop': [[2, 16], [16], [16]],
        'skip': ['backward']}),
    ('FusedBatchNorm', {
        'block': P.FusedBatchNorm(),
        'desc_inputs': [[128, 64, 32, 64], [64], [64], [64], [64]],
        'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
        'skip': []}),
    ('FusedBatchNormGrad', {
        'block': G.FusedBatchNormGrad(),
        'desc_inputs': [[128, 64, 32, 64], [128, 64, 32, 64], [64], [64], [64]],
        'desc_bprop': [[128, 64, 32, 64], [64], [64], [64], [64]],
        'skip': ['backward']}),
    ('BatchNorm', {
        'block': P.BatchNorm(),
        'desc_inputs': [[128, 64, 32, 32], [64], [64], [64], [64]],
        'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
        'skip': []}),
    ('BatchNormGrad', {
        'block': G.BatchNormGrad(),
高东海's avatar
高东海 已提交
1255
        'desc_inputs': [[128, 64, 32, 32], [128, 64, 32, 32], [64], [64], [64]],
Z
zhunaipan 已提交
1256 1257
        'desc_bprop': [[128, 64, 32, 32], [64], [64], [64], [64]],
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
1258 1259
    ('BasicLSTMCell', {
        'block': P.BasicLSTMCell(keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'),
J
jinyaohui 已提交
1260
        'desc_inputs': [[128, 128], [128, 128], [128, 128], [512, 256, 1, 1], [512, 1, 1, 1]],
Z
zhaozhenlong 已提交
1261 1262
        'desc_bprop': [[128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128], [128, 128]],
        'skip': []}),
Z
zhunaipan 已提交
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
    ('TopK', {
        'block': P.TopK(),
        'desc_const': [5],
        'desc_inputs': [[20, 20, 10]],
        'desc_bprop': [[20, 20, 5]],
        'skip': ['backward']}),
    ('GatherV2_0', {
        'block': P.GatherV2(),
        'desc_const': [0],
        'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
        'desc_bprop': [[2, 1, 2]]}),
    ('GatherV2_1', {
        'block': P.GatherV2(),
        'desc_const': [2],
        'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
        'desc_bprop': [[3, 1, 2]]}),
    ('GatherV2_2', {
        'block': P.GatherV2(),
        'desc_const': [0],
        'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
        'desc_bprop': [[3, 2, 1, 3]]}),
    ('GatherV2_3', {
        'block': P.GatherV2(),
        'desc_const': [2],
        'desc_inputs': [[3, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
        'desc_bprop': [[3, 1, 3, 2]]}),
    ('GatherV2_4', {
        'block': P.GatherV2(),
        'desc_const': [1],
        'desc_inputs': [[32, 5, 1024], Tensor(np.array([3]).astype(np.int32))],
        'desc_bprop': [[32, 1, 1024]]}),
    ('GatherV2_5', {
        'block': P.GatherV2(),
        'desc_const': [-1],
        'desc_inputs': [[3, 1, 3], Tensor(np.array([0, 1]).astype(np.int32))],
        'desc_bprop': [[3, 1, 2]]}),
    ('GatherV2_6', {
        'block': P.GatherV2(),
        'desc_const': [0],
        'desc_inputs': [[1152], Tensor(np.array(10).astype(np.int32))],
        'desc_bprop': [Tensor(np.array(10).astype(np.float32))]}),
Z
zhaozhenlong 已提交
1304 1305 1306 1307 1308
    ('SparseGatherV2_0', {
        'block': P.SparseGatherV2(),
        'desc_const': [0],
        'desc_inputs': [[3, 1, 2], Tensor(np.array([0, 1]).astype(np.int32))],
        'desc_bprop': [[2, 1, 2]]}),
L
liuxiao 已提交
1309
    ('Range', {
J
jiangjinsheng 已提交
1310
        'block': inner.Range(1.0, 5.0),
L
liuxiao 已提交
1311 1312
        'desc_inputs': [Tensor(np.ones([10]).astype(np.float32))],
        'desc_bprop': [[10]]}),
Z
zhunaipan 已提交
1313 1314 1315
    ('UnsortedSegmentSum', {
        'block': P.UnsortedSegmentSum(),
        'desc_const': [1280],
1316 1317
        'desc_inputs': [[1280, 1024], Tensor(np.ones(1280).astype(np.int32))],
        'desc_bprop': [[8192, 1024]],
Z
zhunaipan 已提交
1318 1319 1320 1321 1322 1323 1324
        'skip': ['backward']}),
    ('UnsortedSegmentSum_1', {
        'block': P.UnsortedSegmentSum(),
        'desc_const': [4],
        'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
        'desc_bprop': [[4, 1, 3]],
        'skip': ['backward']}),
L
liuxiao 已提交
1325 1326 1327 1328 1329
    ('UnsortedSegmentMin', {
        'block': P.UnsortedSegmentMin(),
        'desc_const': [4],
        'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([1, 2, 3]).astype(np.int32))],
        'desc_bprop': [[4, 2, 1, 3]]}),
1330 1331 1332 1333 1334
    ('UnsortedSegmentProd', {
        'block': P.UnsortedSegmentProd(),
        'desc_const': [4],
        'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([0, 1, 0]).astype(np.int32))],
        'desc_bprop': [[4, 2, 1, 3]]}),
Z
zhunaipan 已提交
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
    ('DropoutGenMask', {
        'block': P.DropoutGenMask(),
        'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
        'desc_inputs': [],
        'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
        'skip': ['backward']}),
    ('DropoutDoMask', {
        'block': P.DropoutDoMask(),
        'desc_const': [Tensor(0.5)],
        'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
        'desc_bprop': [[64, 12, 128, 128]]}),
    ('Dropout', {
        'block': nn.Dropout(0.5),
        'desc_inputs': [[64, 12, 128, 128]],
        'desc_bprop': [[64, 12, 128, 128]]}),
    ('ReduceMean0', {
        'block': P.ReduceMean(),
        'desc_const': [(2,)],
        'desc_inputs': [[3, 2, 2]],
        'desc_bprop': [[3, 2]]}),
    ('ReduceMean1', {
        'block': P.ReduceMean(),
        'desc_const': [2],
        'desc_inputs': [[3, 2, 2]],
        'desc_bprop': [[3, 2]]}),
    ('All', {
        'block': P.ReduceAll(),
        'desc_const': [(1,)],
        'desc_inputs': [Tensor(np.ones([3, 2]).astype(np.bool_))],
        'desc_bprop': [[3]],
        'skip': ['backward']}),
    ('DescConst', {
        'block': Tensor(np.array([2], np.float32)),
        'desc_inputs': [],
        'desc_bprop': [[1]],
        'skip': ['backward'],
        'add_fake_input': True}),
    ('Fill', {
        'block': P.Fill(),
        'desc_const': [mstype.float32, (2, 3), 1.0],
        'desc_inputs': [],
        'desc_bprop': [[2, 3]],
        'skip': ['backward'],
        'add_fake_input': True}),
    ('OnesLike', {
        'block': P.OnesLike(),
        'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
        'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
    }),
    ('ZerosLike', {
        'block': P.ZerosLike(),
        'desc_inputs': [Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))],
        'desc_bprop': [Tensor(np.array([[1, 1], [1, 1]]).astype(np.int32))]
    }),
    ('Softmax', {
        'block': P.Softmax(),
        'desc_inputs': [[5, 5]],
        'desc_bprop': [[5, 5]]}),
P
panbingao 已提交
1393 1394 1395 1396
    ('Softsign', {
        'block': P.Softsign(),
        'desc_inputs': [[5, 5]],
        'desc_bprop': [[5, 5]]}),
Z
zhunaipan 已提交
1397 1398
    ('DepthwiseConv2dNative_1', {
        'block': P.DepthwiseConv2dNative(3, (3, 3), pad_mode="pad", pad=1, stride=2),
L
liuxiao 已提交
1399 1400
        'desc_inputs': [[10, 32, 32, 32], [1, 32, 3, 3]],
        'desc_bprop': [[10, 32, 16, 16]]}),
Z
zhunaipan 已提交
1401 1402 1403
    ('DepthwiseConv2dNative_2', {
        'block': P.DepthwiseConv2dNative(1, (3, 3), pad_mode="same", pad=0, stride=1),
        'desc_inputs': [[2592, 2048, 4, 4], [1, 2048, 3, 3]],
L
liuxiao 已提交
1404
        'desc_bprop': [[2592, 2048, 4, 4]]}),
Z
zhunaipan 已提交
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
    ('SigmoidCrossEntropyWithLogits', {
        'block': P.SigmoidCrossEntropyWithLogits(),
        'desc_inputs': [[128, 10], [128, 10]],
        'desc_bprop': [[128, 10]]}),
    ('Pad', {
        'block': P.Pad(((1, 2), (2, 3))),
        'desc_inputs': [[7, 7]],
        'desc_bprop': [[10, 12]]}),
    ('BinaryCrossEntropy', {
        'block': P.BinaryCrossEntropy(),
        'desc_inputs': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
        'desc_bprop': []}),
    ('SparseApplyAdagrad', {
1418 1419
        'block': SparseApplyAdagradNet(),
        'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
1420
        'desc_bprop': [[3, 3], [3, 3]],
Z
zhunaipan 已提交
1421
        'skip': ['backward']}),
1422 1423 1424 1425
    ('SparseApplyAdagradV2', {
        'block': SparseApplyAdagradV2Net(),
        'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
        'skip': ['backward']}),
1426 1427 1428 1429
    ('SparseApplyFtrl', {
        'block': SparseApplyFtrlNet(),
        'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
        'skip': ['backward']}),
1430 1431 1432 1433
    ('SparseApplyFtrlV2', {
        'block': SparseApplyFtrlV2Net(),
        'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
        'skip': ['backward']}),
1434 1435
    ('ApplyProximalAdagrad', {
        'block': ApplyProximalAdagradNet(),
L
liuxiao 已提交
1436
        'desc_inputs': [[3, 3]],
1437 1438 1439
        'skip': ['backward']}),
    ('SparseApplyProximalAdagrad', {
        'block': SparseApplyProximalAdagradNet(),
L
liuxiao 已提交
1440
        'desc_inputs': [[3, 3], Tensor(np.ones((3,), np.int32))],
1441
        'skip': ['backward']}),
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
    ('ApplyAdaMax', {
        'block': ApplyAdaMaxNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyAdadelta', {
        'block': ApplyAdadeltaNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyAdagrad', {
        'block': ApplyAdagradNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyAdagradV2', {
        'block': ApplyAdagradV2Net(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
L
liuxiao 已提交
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
    ('ApplyAddSign', {
        'block': ApplyAddSignNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyPowerSign', {
        'block': ApplyPowerSignNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyGradientDescent', {
        'block': ApplyGradientDescentNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
    ('ApplyProximalGradientDescent', {
        'block': ApplyProximalGradientDescentNet(),
        'desc_inputs': [[3, 3]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
    ('Flatten_1', {
        'block': NetForFlatten(),
        'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
        'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
        'skip': ['backward']}),
    ('Flatten_2', {
        'block': NetForFlatten(),
        'desc_inputs': [Tensor(np.ones([8]).astype(np.int32)), Tensor(np.ones([8, 3]).astype(np.int32))],
        'desc_bprop': [Tensor(np.ones([8, 3]).astype(np.int32))],
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
1484 1485 1486 1487 1488
    ('Flatten_3', {
        'block': NetForFlattenComposed(),
        'desc_inputs': [Tensor(np.ones([2, 3, 4]).astype(np.int32)), Tensor(np.ones([2, 12]).astype(np.int32))],
        'desc_bprop': [Tensor(np.ones([2, 12]).astype(np.int32))],
        'skip': []}),
Z
zhunaipan 已提交
1489 1490
    ('ArgmaxNet', {
        'block': ArgmaxNet(),
1491 1492
        'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
        'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
Z
zhunaipan 已提交
1493 1494 1495
        'skip': ['backward']}),
    ('ArgminNet', {
        'block': ArgminNet(),
1496 1497
        'desc_inputs': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
        'desc_bprop': [Tensor(np.array([[128, 32, 32, 64], [128, 32, 32, 64]]).astype(np.float16))],
Z
zhunaipan 已提交
1498
        'skip': ['backward']}),
B
buxue 已提交
1499 1500 1501 1502
    ('StridedSliceNet', {
        'block': StridedSliceNet(),
        'desc_inputs': [[6, 7, 8, 9, 10]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1503 1504 1505 1506
    ('OneHot', {
        'block': P.OneHot(),
        'desc_const': [3, Tensor(1.0, mstype.float32), Tensor(0.0, mstype.float32)],
        'desc_inputs': [Tensor(np.array([64]).astype(np.int32))],
P
panyifeng 已提交
1507
        'desc_bprop': [[1, 3]]}),
Z
zhunaipan 已提交
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
    ('ReduceProd_0', {
        'block': P.ReduceProd(),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[2]]}),
    ('ReduceProd_1', {
        'block': P.ReduceProd(keep_dims=True),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[1, 2]]}),
    ('CumProd', {
        'block': P.CumProd(),
        'desc_const': [0],
        'desc_inputs': [[3, 2]],
        'desc_bprop': [[3, 2]]}),
    ('ApplyFtrl', {
1524 1525
        'block': ApplyFtrlNet(),
        'desc_inputs': [[3, 3]],
Z
zhunaipan 已提交
1526 1527
        'desc_bprop': [3, 3],
        'skip': ['backward']}),
Z
zhaoting 已提交
1528
    ('ApplyRMSProp', {
Z
zhaojichen 已提交
1529 1530
        'block': ApplyRMSNet(),
        'desc_inputs': [[3, 3]],
Z
zhaoting 已提交
1531 1532 1533 1534 1535
        'desc_bprop': [3, 3],
        'skip': ['backward']}),
    ('ApplyCenteredRMSProp', {
        'block': P.ApplyCenteredRMSProp(),
        'desc_const': [0.9, 0.0, 1e-10, 0.001],
Z
zhouneng 已提交
1536 1537 1538
        'desc_inputs': [Tensor(1., mstype.float32), Tensor(2., mstype.float32), Tensor(1., mstype.float32),
                        Tensor(2., mstype.float32), Tensor(1., mstype.float32)],
        'desc_bprop': [1],
Z
zhaoting 已提交
1539
        'skip': ['backward']}),
L
liuxiao 已提交
1540 1541 1542 1543 1544 1545 1546
    ('CTCLoss', {
        'block': P.CTCLoss(),
        'desc_inputs': [Tensor(np.ones([6, 4, 6]).astype(np.float32)),
                        Tensor(np.array([[0, 1], [1, 0], [2, 3], [3, 2]]).astype(np.int64)),
                        Tensor(np.array([1, 2, 3, 4]).astype(np.int32)),
                        Tensor(np.array([6, 6, 6, 6]).astype(np.int32))],
        'desc_bprop': [[4], [6, 4, 6]]}),
L
liuxiao 已提交
1547 1548
    ('L2Loss_1', {
        'block': P.L2Loss(),
L
liuxiao 已提交
1549
        'desc_inputs': [Tensor(np.array([1, 2, 3, 4]), mstype.float32)],
L
liuxiao 已提交
1550 1551 1552 1553 1554
        'desc_bprop': []}),
    ('L2Loss_2', {
        'block': P.L2Loss(),
        'desc_inputs': [Tensor(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]), mstype.float16)],
        'desc_bprop': []}),
1555 1556 1557 1558 1559 1560 1561 1562 1563
    ('ResizeBilinear', {
        'block': P.ResizeBilinear((5, 5)),
        'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
        'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
    ('ResizeBilinearGrad', {
        'block': G.ResizeBilinearGrad(),
        'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
        'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
        'skip': ['backward']}),
1564 1565 1566
    ('ROIAlign', {
        'block': P.ROIAlign(7, 7, 0.03125, 2),
        'desc_inputs': [[2, 256, 192, 320], [1024, 5]],
J
jinyaohui 已提交
1567
        'desc_bprop': [[7, 7]]}),
1568 1569 1570 1571 1572
    ('ROIAlignGrad', {
        'block': G.ROIAlignGrad((1, 1, 1, 1), 2, 2, 0.5, 2),
        'desc_inputs': [[1, 1, 2, 2], [1, 5]],
        'desc_bprop': [[1, 1, 2, 2]],
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
1573 1574 1575 1576 1577 1578 1579
    ('LARSUpdate', {
        'block': P.LARSUpdate(1e-05, 0.001, False),
        'desc_const': [0.0, 0.001],
        'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
        'desc_bprop': [3, 3],
        'skip': ['backward']}),
    ('SGD', {
J
jinyaohui 已提交
1580
        'block': P.SGD(0.0, 0.0, False),
Z
zhaozhenlong 已提交
1581 1582 1583
        'desc_inputs': [[3, 3], [3, 3], Tensor(0.001, mstype.float32), [3, 3], Tensor(0.1, mstype.float32), [3, 3]],
        'desc_bprop': [3, 3],
        'skip': ['backward']}),
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
    ('BinaryCrossEntropy', {
        'block': P.BinaryCrossEntropy(),
        'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
                        Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16),
                        Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
        'desc_bprop': []}),
    ('BinaryCrossEntropyGrad', {
        'block': G.BinaryCrossEntropyGrad(),
        'desc_inputs': [Tensor([[0.3, 0.8], [0.4, 0.3]], mstype.float16),
                        Tensor([[0.4, 1.2], [-0.4, -0.9]], mstype.float16), Tensor(0.85, mstype.float16),
                        Tensor([[-1.4, -0.7], [0.9, 0.7]], mstype.float16)],
        'desc_bprop': [],
        'skip': ['backward']}),
1597 1598 1599 1600 1601
    ('DataFormatDimMap', {
        'block': P.DataFormatDimMap(),
        'desc_inputs': [Tensor([0, 1, 2, 3], mstype.int32)],
        'desc_bprop': [],
        'skip': ['backward']}),
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
    ('MaxPoolGradGrad', {
        'block': G.MaxPoolGradGrad(),
        'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
                        Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
                        Tensor(np.random.rand(1, 1, 2, 2), mstype.float16)],
        'desc_bprop': [],
        'skip': ['backward']}),
    ('MaxPoolGradGradWithArgmax', {
        'block': G.MaxPoolGradGradWithArgmax(),
        'desc_inputs': [Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
                        Tensor(np.random.rand(1, 1, 2, 2), mstype.float16),
                        Tensor(np.zeros((1, 1, 2, 2)), mstype.uint16)],
        'desc_bprop': [],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
]

test_case_array_ops = [
    ('SpaceToDepth', {
        'block': P.SpaceToDepth(2),
        'desc_inputs': [[1, 3, 2, 2]],
        'desc_bprop': [[1, 12, 1, 1]]}),
    ('DepthToSpace', {
        'block': P.DepthToSpace(2),
        'desc_inputs': [[1, 12, 1, 1]],
        'desc_bprop': [[1, 3, 2, 2]]}),
    ('Split', {
        'block': P.Split(1, 2),
        'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))],
        'skip': ['backward']}),
    ('Argmax', {
        'block': P.Argmax(),
        'desc_inputs': [[128, 32, 32, 64]],
        'desc_bprop': [0],
        'skip': ['backward']}),
    ('Argmin', {
        'block': P.Argmin(),
        'desc_inputs': [[128, 32, 32, 64]],
        'desc_bprop': [1],
        'skip': ['backward']}),
    ('ArgMaxWithValue', {
        'block': P.ArgMaxWithValue(),
        'desc_inputs': [[128, 32, 32, 64]],
        'desc_bprop': [[1], [1]],
        'skip': ['backward']}),
    ('ArgMinWithValue', {
        'block': P.ArgMinWithValue(),
        'desc_inputs': [[128, 32, 32, 64]],
        'desc_bprop': [[1], [1]],
        'skip': ['backward']}),
    ('Transpose_dim3', {
        'block': P.Transpose(),
        'desc_const': [(0, 2, 1)],
        'desc_inputs': [[1, 2, 3]],
        'desc_bprop': [[1, 3, 2]]}),
    ('Transpose_dim4', {
        'block': P.Transpose(),
        'desc_const': [(0, 1, 2, 3)],
        'desc_inputs': [[1, 2, 3, 4]],
        'desc_bprop': [[1, 2, 4, 3]]}),
    ('AddN', {
        'block': NetForTupleInput(P.AddN()),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
Z
zhangz0911gm 已提交
1666 1667 1668 1669 1670
    ('AccumulateNV2', {
        'block': NetForTupleInput(P.AccumulateNV2()),
        'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]],
        'skip': ['backward']}),
Z
zhunaipan 已提交
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
    ('Shape', {
        'block': P.Shape(),
        'desc_inputs': [[3, 3, 2, 2]],
        'skip': ['backward']}),
    ('Reshape', {
        'block': P.Reshape(),
        'desc_const': [(64,)],
        'desc_inputs': [[64, 1]],
        'desc_bprop': [[64]]}),
    ('Cast', {
        'block': P.Cast(),
        'desc_const': [mstype.int32],
        'desc_inputs': [[2, 3, 4, 5]],
P
panyifeng 已提交
1684
        'desc_bprop': [Tensor(np.ones((2, 3, 4, 5)).astype(np.int32))]}),
Z
zhunaipan 已提交
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
    ('ExpandDims', {
        'block': P.ExpandDims(),
        'desc_const': [0],
        'desc_inputs': [[2, 2]],
        'desc_bprop': [[1, 2, 2]]}),
    ('ExpandDims_1', {
        'block': P.ExpandDims(),
        'desc_const': [-1],
        'desc_inputs': [[2, 2]],
        'desc_bprop': [[2, 2, 1]]}),
    ('Squeeze', {
        'block': P.Squeeze(2),
        'desc_inputs': [[3, 2, 1]],
        'desc_bprop': [[3, 2]]}),
    ('Squeeze_0', {
        'block': P.Squeeze(),
        'desc_inputs': [[3, 1, 2, 1]],
        'desc_bprop': [[3, 2]]}),
    ('Squeeze_1', {
        'block': P.Squeeze(),
        'desc_inputs': [[1, 1, 1, 1]],
        'desc_bprop': [1.0],
        'skip': ['backward']}),
    ('Squeeze_2', {
        'block': P.Squeeze((2, 3)),
        'desc_inputs': [[3, 2, 1, 1]],
        'desc_bprop': [[3, 2]]}),
    ('Size', {
        'block': P.Size(),
        'desc_inputs': [[2, 3, 5]],
        'skip': ['backward']}),
    ('Tile_0', {
        'block': P.Tile(),
        'desc_const': [(1, 2)],
        'desc_inputs': [[64, 1]],
        'desc_bprop': [[64, 2]]}),
    ('Tile_1', {
        'block': P.Tile(),
        'desc_const': [(1, 1)],
        'desc_inputs': [[64, 1]],
        'desc_bprop': [[64, 1]]}),
    ('Tile_2', {
        'block': P.Tile(),
        'desc_const': [(2, 1, 1, 2)],
        'desc_inputs': [[2, 2, 2]],
        'desc_bprop': [[2, 2, 2, 4]]}),
    ('ConcatV2_0', {
        'block': P.Concat(),
        'desc_inputs': [
            (Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)),
             Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)))],
P
panyifeng 已提交
1736
        'desc_bprop': [([4, 2], {'dtype': np.int32})]}),
Z
zhunaipan 已提交
1737 1738 1739 1740
    ('ConcatV2_1', {
        'block': P.Concat(axis=2),
        'desc_inputs': [(Tensor(np.array([[[0, 1, 2]], [[2, 1, 2]]]).astype(np.int32)),
                         Tensor(np.array([[[0, 1]], [[2, 1]]]).astype(np.int32)))],
P
panyifeng 已提交
1741
        'desc_bprop': [([2, 1, 5], {'dtype': np.int32})]}),
Z
zhunaipan 已提交
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
    ('ConcatV2_2', {
        'block': NetForConcat(),
        'desc_inputs': [[2, 2]],
        'desc_bprop': [[4, 2]]}),
    ('ConcatV2_3', {
        'block': NetForConcat1(),
        'desc_inputs': [[2, 2], [2, 2]],
        'desc_bprop': [[4, 2]]}),
    ('ConcatV2_4', {
        'block': P.Concat(axis=0),
        'desc_inputs': [
            (Tensor(np.ones((3, 2, 3), np.float32)),
             Tensor(np.ones((5, 2, 3), np.float32)),
             Tensor(np.ones((6, 2, 3), np.float32)))],
        'desc_bprop': [[14, 2, 3]]}),
    ('ConcatV2_5', {
        'block': P.Concat(axis=-1),
        'desc_inputs': [(Tensor(np.array([1], np.float32)),
                         Tensor(np.array([1], np.float32)),
                         Tensor(np.array([1], np.float32)))],
J
jiangjinsheng 已提交
1762
        'desc_bprop': [[3, ]]}),
1763 1764
    ('Pack_0', {
        'block': NetForPackInput(P.Pack()),
1765 1766
        'desc_inputs': [[2, 2], [2, 2], [2, 2]],
        'desc_bprop': [[3, 2, 2]],
L
liuxiao 已提交
1767
    }),
1768 1769
    ('Pack_1', {
        'block': NetForPackInput(P.Pack(axis=-2)),
1770 1771
        'desc_inputs': [[3, 2, 3], [3, 2, 3], [3, 2, 3]],
        'desc_bprop': [[3, 2, 3, 3]],
L
liuxiao 已提交
1772
    }),
1773 1774
    ('Pack_2', {
        'block': NetForPackInput(P.Pack()),
1775 1776
        'desc_inputs': [[128, 128], [128, 128]],
        'desc_bprop': [[2, 128, 128]],
L
liuxiao 已提交
1777
    }),
1778 1779 1780 1781
    ('Pack_3', {
        'block': NetForPackInput(P.Pack()),
        'desc_inputs': [[2, 2]],
        'desc_bprop': [[1, 2, 2]]}),
1782 1783
    ('Unpack_0', {
        'block': NetForUnpackInput(P.Unpack(axis=0)),
1784 1785
        'desc_inputs': [[2, 4]],
        'desc_bprop': [[4], [4]],
L
liuxiao 已提交
1786
    }),
1787 1788
    ('Unpack_1', {
        'block': NetForUnpackInput(P.Unpack(axis=-1)),
1789 1790
        'desc_inputs': [Tensor(np.array([[1, 1, 1]], np.float32))],
        'desc_bprop': [[1], [1], [1]],
L
liuxiao 已提交
1791
    }),
1792
    ('Diag_1', {
Z
zhaozhenlong 已提交
1793 1794 1795 1796
        'block': P.Diag(),
        'desc_inputs': [[4]],
        'desc_bprop': [[4, 4]],
    }),
1797 1798 1799 1800 1801 1802
    ('Diag_2', {
        'block': P.Diag(),
        'desc_inputs': [[4, 4]],
        'desc_bprop': [[4, 4, 4, 4]],
    }),
    ('DiagPart_1', {
Z
zhaozhenlong 已提交
1803 1804 1805 1806
        'block': P.DiagPart(),
        'desc_inputs': [[4, 4]],
        'desc_bprop': [[4]],
    }),
1807 1808 1809 1810 1811
    ('DiagPart_2', {
        'block': P.DiagPart(),
        'desc_inputs': [[4, 4, 4, 4]],
        'desc_bprop': [[4, 4]],
    }),
1812 1813 1814 1815 1816 1817 1818 1819
    ('SpaceToBatch_1', {
        'block': P.SpaceToBatch(2, [[0, 0], [0, 0]]),
        'desc_inputs': [[1, 3, 2, 2]],
        'desc_bprop': [[4, 3, 1, 1]],
    }),
    ('SpaceToBatch_2', {
        'block': P.SpaceToBatch(2, [[1, 1], [0, 4]]),
        'desc_inputs': [[1, 3, 2, 2]],
P
panyifeng 已提交
1820
        'desc_bprop': [[4, 3, 2, 3]],
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
    }),
    ('BatchToSpace_1', {
        'block': P.BatchToSpace(2, [[0, 0], [0, 0]]),
        'desc_inputs': [[4, 3, 1, 1]],
        'desc_bprop': [[1, 3, 2, 2]],
    }),
    ('BatchToSpace_2', {
        'block': P.BatchToSpace(2, [[0, 0], [0, 1]]),
        'desc_inputs': [[4, 3, 1, 1]],
        'desc_bprop': [[1, 3, 2, 1]],
    }),
L
lihongkang 已提交
1832 1833 1834 1835 1836 1837
    ('UnsortedSegmentMin_1', {
        'block': P.UnsortedSegmentMin(),
        'desc_const': [2],
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [4, 2, 1]]).astype(np.float32)),
                        Tensor(np.array([0, 1, 1]).astype(np.int32))],
        'desc_bprop': [Tensor(np.array([[1, 2, 3], [4, 2, 1]]).astype(np.float32))]}),
Z
zhaozhenlong 已提交
1838
    ('BroadcastTo', {
J
jiangjinsheng 已提交
1839
        'block': P.BroadcastTo((2, 3)),
Z
zhaozhenlong 已提交
1840 1841
        'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.float32))],
        'desc_bprop': [Tensor(np.array([[1, 2, 3], [1, 2, 3]]).astype(np.float32))]}),
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
    ('InTopK', {
        'block': P.InTopK(2),
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [2, 3, 6], [4, 2, 1]]).astype(np.float32)),
                        Tensor(np.array([2, 1, 2]).astype(np.int32))],
        'skip': ['backward'],
    }),
    ('InplaceUpdate', {
        'block': P.InplaceUpdate((0, 2)),
        'desc_inputs': [Tensor(np.arange(24).reshape(3, 4, 2).astype(np.float32)),
                        Tensor(np.arange(16).reshape(2, 4, 2).astype(np.float32))],
        'skip': ['backward'],
    }),
1854 1855 1856 1857 1858
    ('ReverseSequence', {
        'block': P.ReverseSequence(1, 0),
        'desc_inputs': [Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32)),
                        Tensor(np.array([1, 2, 3]).astype(np.int32))],
        'desc_bprop': [[3, 3]]}),
J
jiangjinsheng 已提交
1859 1860 1861 1862 1863 1864 1865 1866
    ('LinSpace', {
        'block': inner.LinSpace(),
        'desc_inputs': [Tensor([5, 5.5], mstype.float32),
                        Tensor(1, mstype.float32),
                        Tensor(10, mstype.float32),
                        Tensor(5, mstype.int32)],
        'skip': ['backward'],
    }),
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
    ('MatrixDiag', {
        'block': inner.MatrixDiag(),
        'desc_inputs': [Tensor(np.array([1, -1]), mstype.float32),
                        Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
        'skip': ['backward'],
    }),
    ('MatrixDiagPart', {
        'block': inner.MatrixDiagPart(),
        'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
                        Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
        'skip': ['backward'],
    }),
    ('MatrixSetDiag', {
        'block': inner.MatrixSetDiag(),
        'desc_inputs': [Tensor(np.arange(12).reshape(3, 2, 2), mstype.float32),
                        Tensor(np.arange(6).reshape(3, 2), mstype.float32),
                        Tensor(np.arange(-12, 0).reshape(3, 2, 2), mstype.float32)],
        'skip': ['backward'],
    }),
L
leilei_snow 已提交
1886 1887 1888 1889 1890 1891
    ('TransShape', {
        'block': P.TransShape(),
        'desc_const': [(1, 12, 24, 24)],
        'desc_inputs': [[1, 3, 24, 24]],
        'desc_bprop': [[1, 12, 24, 24]],
    }),
J
jiangjinsheng 已提交
1892 1893 1894 1895 1896 1897
    ('ParallelConcat', {
        'block': ParallelConcatNet(),
        'desc_inputs': [Tensor([[1, 2]], mstype.float32),
                        Tensor([[5, 6]], mstype.float32)],
        'skip': ['backward'],
    }),
Z
zhunaipan 已提交
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
]

test_case_other_ops = [
    ('ScalarLog', {
        'block': F.scalar_log,
        'desc_const': [0.0],
        'desc_inputs': [],
        'desc_bprop': [1],
        'skip': ['backward']}),
    ('BoundingBoxEncode', {
        'block': P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)),
        'desc_inputs': [[256, 4], [256, 4]],
        'desc_bprop': [[256, 4]],
        'skip': ['backward']}),
    ('BoundingBoxDecode', {
        '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)),
        'desc_inputs': [[256, 4], [256, 4]],
        'desc_bprop': [[256, 4]],
        'skip': ['backward']}),
    ('GatherNd', {
        'block': P.GatherNd(),
        'desc_inputs': (Tensor(np.ones((1, 3, 6, 6), np.float32)),
                        Tensor(np.ones((2, 4), np.int32))),
        'desc_bprop': [[2]]}),
    ('ScatterNd', {
        'block': P.ScatterNd(),
        'desc_const': [(3, 3)],
        'desc_inputs': (Tensor(np.ones((2, 2), np.int32)),
                        Tensor(np.ones((2,), np.int32))),
P
panyifeng 已提交
1927
        'desc_bprop': [([3, 3], {'dtype': np.int32})]}),
1928 1929
    ('TensorScatterUpdate', {
        'block': P.TensorScatterUpdate(),
B
buxue 已提交
1930
        'desc_inputs': (Tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5)), mstype.float32),
1931 1932 1933
                        Tensor(np.array([[0, 1], [1, 2]], np.int32)),
                        Tensor(np.ones([2, 5], np.float32) * 99)),
        'desc_bprop': [([3, 4, 5], {'dtype': np.float32})]}),
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
    ('ScatterMaxUseLocking', {
        'block': ScatterMax(use_locking=True),
        'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
                        Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
        'skip': ['backward']}),
    ('ScatterMax1d', {
        'block': ScatterMax(),
        'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
                        Tensor(np.array([[5.0, 5.0, 5.0], [4.0, 4.0, 4.0]], np.float32))),
        'skip': ['backward']}),
    ('ScatterMaxF32', {
1945 1946 1947 1948
        'block': ScatterMax(),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.float32) * 99)),
        'skip': ['backward']}),
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
    ('ScatterMaxF16', {
        'block': ScatterMax(np.float16),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.float16) * 99)),
        'skip': ['backward']}),
    ('ScatterMaxI32', {
        'block': ScatterMax(np.int32),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.int32) * 99)),
        'skip': ['backward']}),
    ('ScatterMinUseLocking', {
        'block': ScatterMin(use_locking=True),
        'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
                        Tensor(np.ones([2, 3], np.float32))),
        'skip': ['backward']}),
    ('ScatterMin1d', {
        'block': ScatterMin(),
        'desc_inputs': (Tensor(np.array([1, 0], np.int32)),
                        Tensor(np.ones([2, 3], np.float32))),
        'skip': ['backward']}),
    ('ScatterMinF32', {
        'block': ScatterMin(),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.float32))),
        'skip': ['backward']}),
    ('ScatterMinF16', {
        'block': ScatterMin(np.float16),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.float16))),
        'skip': ['backward']}),
    ('ScatterMinI32', {
        'block': ScatterMin(np.int32),
        'desc_inputs': (Tensor(np.array([[0, 0], [1, 1]], np.int32)),
                        Tensor(np.ones([2, 2, 3], np.int32))),
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
1984 1985 1986 1987 1988
    ('ScatterUpdate', {
        'block': ScatterUpdate((6,)),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
        'skip': ['backward']}),
1989 1990 1991 1992 1993
    ('ScatterAddUseLocking', {
        'block': ScatterAdd((6,), use_locking=True),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
1994 1995 1996 1997 1998
    ('ScatterAdd', {
        'block': ScatterAdd((6,)),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float32))),
        'skip': ['backward']}),
1999 2000 2001 2002 2003
    ('ScatterAddScalar', {
        'block': ScatterAdd((6,)),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
2004 2005 2006 2007 2008 2009
    ('ScatterAdd2d', {
        'block': ScatterAdd((3, 4)),
        'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
                        Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
                                         [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
        'skip': ['backward']}),
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
    ('ScatterAddF16', {
        'block': ScatterAdd((6,), np.float16),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
        'skip': ['backward']}),
    ('ScatterAddI8', {
        'block': ScatterAdd((6,), np.int8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int8))),
        'skip': ['backward']}),
    ('ScatterAddI32', {
        'block': ScatterAdd((6,), np.int32),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int32))),
        'skip': ['backward']}),
    ('ScatterAddU8', {
        'block': ScatterAdd((6,), np.uint8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.uint8))),
        'skip': ['backward']}),
Z
zhaozhenlong 已提交
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
    ('ScatterMulUseLocking', {
        'block': ScatterMul((6,), use_locking=True),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterMulScalar', {
        'block': ScatterMul((6,)),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterMul2d', {
        'block': ScatterMul((3, 4)),
        'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
                        Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
                                         [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
        'skip': ['backward']}),
    ('ScatterMulF16', {
        'block': ScatterMul((6,), np.float16),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
        'skip': ['backward']}),
    ('ScatterMulI8', {
        'block': ScatterMul((6,), np.int8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int8))),
        'skip': ['backward']}),
    ('ScatterMulI32', {
        'block': ScatterMul((6,), np.int32),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int32))),
        'skip': ['backward']}),
    ('ScatterMulU8', {
        'block': ScatterMul((6,), np.uint8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.uint8))),
        'skip': ['backward']}),
    ('ScatterDivUseLocking', {
        'block': ScatterDiv((6,), use_locking=True),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterDivScalar', {
        'block': ScatterDiv((6,)),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterDiv2d', {
        'block': ScatterDiv((3, 4)),
        'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
                        Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
                                         [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
        'skip': ['backward']}),
    ('ScatterDivF16', {
        'block': ScatterDiv((6,), np.float16),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
        'skip': ['backward']}),
    ('ScatterDivI8', {
        'block': ScatterDiv((6,), np.int8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int8))),
        'skip': ['backward']}),
    ('ScatterDivU8', {
        'block': ScatterDiv((6,), np.uint8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.uint8))),
        'skip': ['backward']}),
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
    ('ScatterSubUseLocking', {
        'block': ScatterSub((6,), use_locking=True),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterSubScalar', {
        'block': ScatterSub((6,)),
        'desc_inputs': (Tensor(np.array([2], np.int32)),
                        Tensor(np.array([2.0], np.float32))),
        'skip': ['backward']}),
    ('ScatterSub2d', {
        'block': ScatterSub((3, 4)),
        'desc_inputs': (Tensor(np.array([[0, 1], [1, 2]], np.int32)),
                        Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2]],
                                         [[3, 3, 3, 3], [4, 4, 4, 4]]], np.float32))),
        'skip': ['backward']}),
    ('ScatterSubF16', {
        'block': ScatterSub((6,), np.float16),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2.0, 3.0, 4.0], np.float16))),
        'skip': ['backward']}),
    ('ScatterSubI32', {
        'block': ScatterSub((6,), np.int32),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int32))),
        'skip': ['backward']}),
    ('ScatterSubI8', {
        'block': ScatterSub((6,), np.int8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([2, 3, 4], np.int8))),
        'skip': ['backward']}),
    ('ScatterSubU8', {
        'block': ScatterSub((6,), np.uint8),
        'desc_inputs': (Tensor(np.array([2, 0, 5], np.int32)),
                        Tensor(np.array([1, 1, 0], np.uint8))),
        'skip': ['backward']}),
Z
zhunaipan 已提交
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145
    ('SmoothL1Loss', {
        'block': P.SmoothL1Loss(),
        'desc_inputs': [[256, 4], [256, 4]],
        'desc_bprop': [[256, 4]]}),
    ('IOU', {
        'block': P.IOU(),
        'desc_inputs': [Tensor(np.ones((256, 4), np.float16)), Tensor(np.ones((128, 4), np.float16))],
        'desc_bprop': [[128, 256]]}),
    ('Summary', {
        'block': SummaryNet(),
        'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
                        Tensor(np.array([1.2]).astype(np.float32))],
        'skip': ['backward']}),
2146
    ('ConfusionMulGrad_1', {
2147
        'block': P.ConfusionMulGrad(axis=[0], keep_dims=False),
2148 2149 2150 2151
        'desc_inputs': [[3, 2], [3, 2], [3, 2]],
        'desc_bprop': [[3, 2], [2]],
        'skip': ['backward']}),
    ('ConfusionMulGrad_2', {
2152
        'block': P.ConfusionMulGrad(axis=[0], keep_dims=True),
2153 2154 2155 2156
        'desc_inputs': [[3, 2], [3, 2], [3, 2]],
        'desc_bprop': [[3, 2], [1, 2]],
        'skip': ['backward']}),
    ('ConfusionMulGrad_3', {
2157
        'block': P.ConfusionMulGrad(axis=(), keep_dims=True),
2158 2159 2160
        'desc_inputs': [[2, 3, 4], [2, 3, 4], [2, 3, 4]],
        'desc_bprop': [[2, 3, 4], [1, 1, 1]],
        'skip': ['backward']}),
O
ougongchang 已提交
2161 2162 2163 2164 2165
    ('HistogramSummary', {
        'block': HistogramSummaryNet(),
        'desc_inputs': [Tensor(np.array([1.1]).astype(np.float32)),
                        Tensor(np.array([1.2]).astype(np.float32))],
        'skip': ['backward']}),
J
jiangjinsheng 已提交
2166 2167 2168 2169
    ('PopulationCount', {
        'block': P.PopulationCount(),
        'desc_inputs': [Tensor(np.array([1, 2, 3]).astype(np.int16))],
        'skip': ['backward']}),
Z
zhunaipan 已提交
2170 2171
]

Z
zhaozhenlong 已提交
2172 2173
test_case_quant_ops = [
    ('AscendQuant_1', {
2174
        'block': inner.AscendQuant(0.5, 0.0, False, "Round"),
B
buxue 已提交
2175
        'desc_inputs': [Tensor(np.random.rand(1, 2, 4, 4), mstype.float32)],
Z
zhaozhenlong 已提交
2176 2177
        'skip': ['backward']}),
    ('AscendQuant_2', {
2178
        'block': inner.AscendQuant(80.0, 10.0, True, "Round"),
Z
zhaozhenlong 已提交
2179 2180 2181
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_3', {
2182
        'block': inner.AscendQuant(80.0, 0.0, False, "Floor"),
Z
zhaozhenlong 已提交
2183 2184 2185
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_4', {
2186
        'block': inner.AscendQuant(80.0, 0.0, False, "Ceil"),
Z
zhaozhenlong 已提交
2187 2188 2189
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_5', {
2190
        'block': inner.AscendQuant(80.0, 0.0, False, "Trunc"),
Z
zhaozhenlong 已提交
2191 2192 2193
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_6', {
2194
        'block': inner.AscendQuant(-80.0, 10.0, False, "Round"),
Z
zhaozhenlong 已提交
2195 2196 2197
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_7', {
2198
        'block': inner.AscendQuant(80.0, -10.0, False, "Round"),
Z
zhaozhenlong 已提交
2199 2200 2201
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float32)],
        'skip': ['backward']}),
    ('AscendQuant_8', {
2202
        'block': inner.AscendQuant(80.0, 10.0, False, "Round"),
Z
zhaozhenlong 已提交
2203 2204 2205 2206 2207
        'desc_inputs': [Tensor([100.0, 200.0], mstype.float16)],
        'skip': ['backward']}),
]

test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops, test_case_other_ops, test_case_quant_ops]
Z
zhunaipan 已提交
2208 2209 2210 2211 2212 2213 2214
test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
# use -k to select certain testcast
# pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm


test_exec_case = test_case

J
jinyaohui 已提交
2215
test_backward_exec_case = filter(lambda x: 'skip' not in x[1] or 'backward' not in x[1]['skip'], test_case)
Z
zhunaipan 已提交
2216 2217 2218 2219 2220


@non_graph_engine
@mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
def test_exec():
2221
    context.set_context(mode=context.GRAPH_MODE)
Z
zhunaipan 已提交
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249
    return test_exec_case


@mindspore_test(pipeline_for_compile_grad_ge_graph_for_case_by_case_config)
def test_backward_exec():
    context.set_context(mode=context.GRAPH_MODE)
    return test_backward_exec_case


raise_set = [
    ('Cast_Error', {
        'block': (P.Cast(), {'exception': TypeError}),
        'desc_const': [mstype.int32],
        'desc_inputs': ['wrong input'],
        'desc_bprop': [Tensor(np.ones((2, 3, 3, 5)).astype(np.int32))]}),
    ('Maximum_Error', {
        'block': (P.Maximum(), {'exception': TypeError}),
        'desc_const': [(1, 2, 3)],
        'desc_inputs': [[2, 3, 3, 5]],
        'desc_bprop': [[2, 3, 3, 5]]}),
    ('Shape_error', {
        'block': (P.Shape(), {'exception': TypeError}),
        'desc_inputs': [(64, 1)],
        'desc_bprop': [[64]]}),
    ('Flatten_Error', {
        'block': (NetForFlatten0D(), {'exception': ValueError}),
        'desc_inputs': [Tensor(np.array(0).astype(np.int32))],
        'desc_bprop': [Tensor(np.array(0).astype(np.int32))]}),
2250 2251 2252
    ('ScatterNdUpdate', {
        'block': (P.ScatterNdUpdate(), {'exception': TypeError}),
        'desc_inputs': (Tensor(np.ones((2, 3), np.float32)),
B
buxue 已提交
2253
                        Tensor(np.ones((2, 2), np.float32)),
2254 2255
                        Tensor(np.ones((2,), np.float32))),
        'desc_bprop': [[2, 3]]}),
2256 2257
    ('PReLU', {
        'block': (P.PReLU(), {'exception': ValueError}),
2258 2259
        'desc_inputs': [[2], [1]],
        'desc_bprop': [[1]]}),
Z
zhaozhenlong 已提交
2260 2261 2262 2263
    ('SSIM', {
        'block': (nn.SSIM(), {'exception': ValueError}),
        'desc_inputs': [Tensor(np.ones((1, 3, 8, 8)), mstype.float32),
                        Tensor(np.ones((1, 3, 8, 8)), mstype.float32)]}),
B
buxue 已提交
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275
    ('StridedSlice_0', {
        'block': (P.StridedSlice(), {'exception': ValueError}),
        'desc_const': [(1, 2.2, 3), (3, 4, 5), (1, 1, 1)],
        'desc_inputs': [[4, 5, 6, 7]]}),
    ('StridedSlice_1', {
        'block': (P.StridedSlice(), {'exception': ValueError}),
        'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1)],
        'desc_inputs': [[4, 5, 6, 7]]}),
    ('StridedSlice_2', {
        'block': (P.StridedSlice(), {'exception': ValueError}),
        'desc_const': [(1, 2, 3), (3, 4, 5), (1, 1, 0)],
        'desc_inputs': [[4, 5, 6, 7]]}),
2276

Z
zhunaipan 已提交
2277 2278 2279 2280 2281 2282
]


@mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception)
def test_check_exception():
    return raise_set