test_activation_op_xpu.py 39.6 KB
Newer Older
1
#   Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14
#
# 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.

15
import sys
16
import unittest
17

R
RedContritio 已提交
18
sys.path.append('../../python/paddle/fluid/tests/unittests')
19

20 21
import os

R
RedContritio 已提交
22
import numpy as np
23
from eager_op_test import OpTest
R
RedContritio 已提交
24
from get_test_cover_info import (
25
    XPUOpTestWrapper,
26 27 28
    create_test_class,
    get_xpu_op_support_types,
)
R
RedContritio 已提交
29
from op_test_xpu import XPUOpTest
30

31
import paddle
32
import paddle.nn.functional as F
33

34
paddle.enable_static()
35

36 37

class TestActivationOPBase(XPUOpTest):
38
    def setUp(self):
39
        self.place = paddle.XPUPlace(0)
40
        self.init_dtype()
41
        self.set_shape()
42
        self.set_case()
43

44 45 46
    def set_shape(self):
        self.shape = [11, 17]

47 48
    def set_case(self):
        self.op_type = 'exp'
49
        x = np.random.uniform(-1, 1, self.shape).astype(self.dtype)
50
        out = np.exp(x)
51 52 53 54 55 56 57 58
        self.attrs = {'use_xpu': True}
        self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
        self.outputs = {'Out': out}

    def init_dtype(self):
        self.dtype = np.float32

    def test_check_output(self):
59
        self.check_output_with_place(self.place)
60

61 62
    def test_check_grad(self):
        self.check_grad_with_place(self.place, ['X'], 'Out')
63 64


65 66 67 68
class XPUTestExpOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'exp'
        self.use_dynamic_create_class = False
69

70 71 72 73
    class XPUTestExp(TestActivationOPBase):
        def set_case(self):
            self.op_type = 'exp'
            self.dtype = self.in_type
74

75 76 77 78 79
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            out = np.exp(x)
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
80

81 82 83 84
    class XPUTestExp_ZeroDIm(TestActivationOPBase):
        def set_shape(self):
            self.shape = []

85

86 87 88
support_types = get_xpu_op_support_types('exp')
for stype in support_types:
    create_test_class(globals(), XPUTestExpOP, stype)
89 90


91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
class XPUTestSiluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'silu'
        self.use_dynamic_create_class = False

    class XPUTestSilu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "silu"
            self.dtype = self.in_type
            self.init_shape()

            np.random.seed(1024)
            x = np.random.uniform(-1, 1, self.shape).astype(self.dtype)
            out = x / (np.exp(-x) + 1)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}

110 111 112 113 114
        def test_check_output(self):
            self.set_env()
            self.check_output_with_place(self.place)
            self.delete_env()

115
        def test_check_grad(self):
116
            self.set_env()
117
            self.check_grad_with_place(self.place, ['X'], 'Out')
118
            self.delete_env()
119 120 121 122

        def init_shape(self):
            self.shape = [11, 17]

123 124 125 126 127 128
        def set_env(self):
            pass

        def delete_env(self):
            pass

129 130 131 132
    class TestSilu_ZeroDim(XPUTestSilu):
        def init_shape(self):
            self.shape = []

133 134 135 136 137 138 139 140 141
    class TestSilu_LUT(XPUTestSilu):
        def set_env(self):
            # set "XPU_PADDLE_ACT_LUT" env to enable lut
            os.environ['XPU_PADDLE_ACT_LUT'] = "1"

        def delete_env(self):
            if os.getenv('XPU_PADDLE_ACT_LUT'):
                del os.environ['XPU_PADDLE_ACT_LUT']

142 143 144 145 146 147 148 149 150 151

class TestSiluAPI(unittest.TestCase):
    # test paddle.nn.Silu, paddle.nn.functional.silu
    def setUp(self):
        self.x_np = np.random.uniform(-1, 1, [11, 17]).astype('float32')
        self.place = paddle.XPUPlace(0)

    def test_static_api(self):
        paddle.enable_static()
        with paddle.static.program_guard(paddle.static.Program()):
152
            x = paddle.static.data('X', [11, 17])
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
            out1 = F.silu(x)
            m = paddle.nn.Silu()
            out2 = m(x)
            exe = paddle.static.Executor(self.place)
            res = exe.run(feed={'X': self.x_np}, fetch_list=[out1, out2])
        out_ref = self.x_np / (1 + np.exp(-self.x_np))
        for r in res:
            np.testing.assert_allclose(out_ref, r, rtol=1e-05)

    def test_dygraph_api(self):
        paddle.disable_static(self.place)
        x = paddle.to_tensor(self.x_np)
        out1 = F.silu(x)
        m = paddle.nn.Silu()
        out2 = m(x)
        out_ref = self.x_np / (1 + np.exp(-self.x_np))
        for r in [out1, out2]:
            np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05)
        paddle.enable_static()

    def test_errors(self):
        with paddle.static.program_guard(paddle.static.Program()):
            # The input type must be Variable.
            self.assertRaises(TypeError, F.silu, 1)
            # The input dtype must be float16, float32, float64.
178
            x_int32 = paddle.static.data(
179 180 181 182
                name='x_int32', shape=[11, 17], dtype='int32'
            )
            self.assertRaises(TypeError, F.silu, x_int32)
            # support the input dtype is float16
183
            x_fp16 = paddle.static.data(
184 185 186 187 188 189 190 191 192 193
                name='x_fp16', shape=[11, 17], dtype='float16'
            )
            F.silu(x_fp16)


support_types = get_xpu_op_support_types('silu')
for stype in support_types:
    create_test_class(globals(), XPUTestSiluOP, stype)


194 195 196 197
class XPUTestSigmoidOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'sigmoid'
        self.use_dynamic_create_class = False
198

199 200 201 202
    class XPUTestSigmoid(TestActivationOPBase):
        def set_case(self):
            self.op_type = "sigmoid"
            self.dtype = self.in_type
203 204
            self.init_config()
            out = 1 / (1 + np.exp(-self.x))
T
TTerror 已提交
205

206
            self.attrs = {'use_xpu': True}
207
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(self.x)}
208
            self.outputs = {'Out': out}
209

210 211 212
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)

213 214 215 216
    class XPUTestSigmoid_ZeroDIm(XPUTestSigmoid):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, []).astype(self.dtype)

217 218 219 220 221 222 223 224 225 226 227 228 229 230
    class XPUTestSigmoid2(XPUTestSigmoid):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [100]).astype(self.dtype)

    class XPUTestSigmoid3(XPUTestSigmoid):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [10, 12, 15]).astype(self.dtype)

    class XPUTestSigmoid4(XPUTestSigmoid):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [19, 19]).astype(self.dtype)

    class XPUTestSigmoid5(XPUTestSigmoid):
        def init_config(self):
231 232 233
            self.x = np.random.uniform(-2, 2, [10, 20, 30, 40]).astype(
                self.dtype
            )
234

235

236 237 238
support_types = get_xpu_op_support_types('sigmoid')
for stype in support_types:
    create_test_class(globals(), XPUTestSigmoidOP, stype)
239 240


241 242 243 244
class XPUTestTanhOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'tanh'
        self.use_dynamic_create_class = False
245

246 247 248 249
    class XPUTestTanh(TestActivationOPBase):
        def set_case(self):
            self.op_type = "tanh"
            self.dtype = self.in_type
250

251 252 253 254 255
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            out = np.tanh(x)
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
256 257


258 259 260
support_types = get_xpu_op_support_types('tanh')
for stype in support_types:
    create_test_class(globals(), XPUTestTanhOP, stype)
261

T
TTerror 已提交
262

263 264 265 266
class XPUTestSqrtOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'sqrt'
        self.use_dynamic_create_class = False
267

268 269 270 271
    class XPUTestSqrt(TestActivationOPBase):
        def set_case(self):
            self.op_type = "sqrt"
            self.dtype = self.in_type
272

273 274
            x = np.random.uniform(0.1, 1, [11, 17]).astype(self.dtype)
            out = np.sqrt(x)
275

276 277 278
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
279

280

281 282 283
support_types = get_xpu_op_support_types('sqrt')
for stype in support_types:
    create_test_class(globals(), XPUTestSqrtOP, stype)
284 285


286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
class XPUTestFloorOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'floor'
        self.use_dynamic_create_class = False

    class XPUTestSqrt(TestActivationOPBase):
        def set_case(self):
            self.op_type = "floor"
            self.dtype = self.in_type

            x = np.random.uniform(0.1, 1, [11, 17]).astype(self.dtype)
            out = np.floor(x)

            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}

        def test_check_grad(self):
            self.check_output_with_place(self.place)


support_types = get_xpu_op_support_types('floor')
for stype in support_types:
    create_test_class(globals(), XPUTestFloorOP, stype)


312 313 314 315
class XPUTestAbsOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'abs'
        self.use_dynamic_create_class = False
316

317 318 319 320
    class XPUTestAbs(TestActivationOPBase):
        def set_case(self):
            self.op_type = "abs"
            self.dtype = self.in_type
321

322 323 324 325 326 327 328
            x = np.random.uniform(-1, 1, [4, 25]).astype(self.dtype)
            # Because we set delta = 0.005 in calculating numeric gradient,
            # if x is too small, such as 0.002, x_neg will be -0.003
            # x_pos will be 0.007, so the numeric gradient is inaccurate.
            # we should avoid this
            x[np.abs(x) < 0.005] = 0.02
            out = np.abs(x)
T
TTerror 已提交
329

330 331 332
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
333 334


335 336 337
support_types = get_xpu_op_support_types('abs')
for stype in support_types:
    create_test_class(globals(), XPUTestAbsOP, stype)
338

T
TTerror 已提交
339

340 341 342 343
class XPUTestReluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'relu'
        self.use_dynamic_create_class = False
344

345 346 347 348
    class XPUTestRelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "relu"
            self.dtype = self.in_type
349

350 351 352 353
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            # The same reason with TestAbs
            x[np.abs(x) < 0.005] = 0.02
            out = np.maximum(x, 0)
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
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': x}
            self.outputs = {'Out': out}


support_types = get_xpu_op_support_types('relu')
for stype in support_types:
    create_test_class(globals(), XPUTestReluOP, stype)


class XPUTestGeluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'gelu'
        self.use_dynamic_create_class = False

    class XPUTestGelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "gelu"
            self.dtype = self.in_type

            approximate = False
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            out = gelu(x, approximate)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {"approximate": approximate, 'use_xpu': True}
382

383 384 385 386

support_types = get_xpu_op_support_types('gelu')
for stype in support_types:
    create_test_class(globals(), XPUTestGeluOP, stype)
387 388


389
def gelu(x, approximate):
390
    from scipy.special import erf
391

392
    if approximate:
393 394 395 396 397 398 399 400
        y_ref = (
            0.5
            * x
            * (
                1.0
                + np.tanh(np.sqrt(2 / np.pi) * (x + 0.044715 * np.power(x, 3)))
            )
        )
401 402 403 404 405
    else:
        y_ref = 0.5 * x * (1 + erf(x / np.sqrt(2)))
    return y_ref.astype(x.dtype)


406
class XPUTestHardSwishOP(XPUOpTestWrapper):
407 408 409
    def __init__(self):
        self.op_name = 'hard_swish'
        self.use_dynamic_create_class = False
P
procr 已提交
410

411 412 413 414
    class XPUTestHardSwish(TestActivationOPBase):
        def set_case(self):
            self.op_type = "hard_swish"
            self.dtype = self.in_type
P
procr 已提交
415

416 417 418 419 420 421 422 423 424 425 426 427 428 429
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            offset = 3.0
            threshold = 6.0
            scale = 6.0
            out = hard_swish(x, offset, threshold, scale)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('hard_swish')
for stype in support_types:
    create_test_class(globals(), XPUTestHardSwishOP, stype)
P
procr 已提交
430 431 432 433 434 435 436


def hard_swish(x, offset, threshold, scale):
    y_ref = np.minimum(threshold, np.maximum(0, x + offset)) * x / scale
    return y_ref.astype(x.dtype)


437 438 439 440
class XPUTestLogOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'log'
        self.use_dynamic_create_class = False
441

442 443 444 445
    class XPUTestLog(TestActivationOPBase):
        def set_case(self):
            self.op_type = "log"
            self.dtype = self.in_type
446
            x = np.random.uniform(0.1, 1, self.shape).astype(self.dtype)
447
            out = np.log(x)
448

449 450 451
            self.attrs = {'use_xpu': True}
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
452

453 454 455 456
    class TestLogCase_ZeroDim(XPUTestLog):
        def set_shape(self):
            self.shape = []

457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
    class TestLogCase1(XPUTestLog):
        def set_shape(self):
            self.shape = [1, 11, 17]

    class TestLogCase2(XPUTestLog):
        def set_shape(self):
            self.shape = [2, 2, 2]

    class TestLogCase3(XPUTestLog):
        def set_shape(self):
            self.shape = [2]

    class TestLogCase4(XPUTestLog):
        def set_shape(self):
            self.shape = [1, 2, 3, 4]

473

474 475 476
support_types = get_xpu_op_support_types('log')
for stype in support_types:
    create_test_class(globals(), XPUTestLogOP, stype)
477 478


479 480 481 482
class XPUTestSquareOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'square'
        self.use_dynamic_create_class = False
T
TTerror 已提交
483

484 485 486 487
    class XPUTestSquare(TestActivationOPBase):
        def set_case(self):
            self.op_type = "square"
            self.dtype = self.in_type
488 489
            self.init_config()
            out = np.square(self.x)
490

491
            self.attrs = {'use_xpu': True}
492
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(self.x)}
493
            self.outputs = {'Out': out}
494

495 496 497
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)

498 499 500 501
    class XPUTestSquare_ZeroDim(XPUTestSquare):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, []).astype(self.dtype)

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
    class XPUTestSquare2(XPUTestSquare):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [100]).astype(self.dtype)

    class XPUTestSquare3(XPUTestSquare):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [1, 15, 19]).astype(self.dtype)

    class XPUTestSquare4(XPUTestSquare):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [100, 10]).astype(self.dtype)

    class XPUTestSquare5(XPUTestSquare):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [1, 2, 5, 17]).astype(self.dtype)

518

519 520 521
support_types = get_xpu_op_support_types('square')
for stype in support_types:
    create_test_class(globals(), XPUTestSquareOP, stype)
522

T
TTerror 已提交
523

524 525 526 527
class XPUTestPowOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'pow'
        self.use_dynamic_create_class = False
T
TTerror 已提交
528

529
    class XPUTestPowBase(TestActivationOPBase):
530 531 532 533
        def set_case(self):
            self.op_type = "pow"
            self.dtype = self.in_type

534 535
            self.init_config()
            out = np.power(self.x, self.factor)
536

537 538
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(self.x)}
            self.attrs = {'factor': self.factor, 'use_xpu': True}
539 540
            self.outputs = {'Out': out}

541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
        def init_config(self):
            self.x = np.random.uniform(-1, 2, [12]).astype(self.dtype)
            self.factor = 3.0

    class XPUTestPow1(XPUTestPowBase):
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [1024, 8]).astype(self.dtype)
            self.factor = 1

    class XPUTestPow2(XPUTestPowBase):
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [1024, 8]).astype(self.dtype)
            self.factor = 2

    class XPUTestPow3(XPUTestPowBase):
        def init_config(self):
557 558 559
            self.x = np.random.uniform(-2, 2, [4, 512, 15, 15]).astype(
                self.dtype
            )
560 561 562 563
            self.factor = 3

    class XPUTestPow4(XPUTestPowBase):
        def init_config(self):
564 565 566
            self.x = np.random.uniform(-2, 2, [4, 256, 22, 22]).astype(
                self.dtype
            )
567 568 569 570
            self.factor = 4

    class XPUTestPow5(XPUTestPowBase):
        def init_config(self):
571 572 573
            self.x = np.random.uniform(0, 1, [4, 256, 22, 22]).astype(
                self.dtype
            )
574 575 576 577 578 579 580
            self.factor = 1.2

    class XPUTestPow6(XPUTestPowBase):
        def init_config(self):
            self.x = np.random.uniform(0, 1, [1024, 8]).astype(self.dtype)
            self.factor = 3.2

581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599

support_types = get_xpu_op_support_types('pow')
for stype in support_types:
    create_test_class(globals(), XPUTestPowOP, stype)


class XPUTestLeakyReluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'leaky_relu'
        self.use_dynamic_create_class = False

    class XPUTestLeakyRelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "leaky_relu"
            self.dtype = self.in_type

            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            alpha = np.random.uniform(
                0,
600 601
                1,
            )
602 603 604 605 606 607 608 609 610 611
            out = leaky_relu(x, alpha)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'alpha': alpha}


support_types = get_xpu_op_support_types('leaky_relu')
for stype in support_types:
    create_test_class(globals(), XPUTestLeakyReluOP, stype)
T
TTerror 已提交
612 613 614


def leaky_relu(x, alpha):
615
    if alpha < 1:
T
TTerror 已提交
616 617 618 619 620 621
        y_ref = np.maximum(x, alpha * x)
    else:
        y_ref = np.minimum(x, alpha * x)
    return y_ref.astype(x.dtype)


622 623 624 625
class XPUTestReciprocalOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'reciprocal'
        self.use_dynamic_create_class = False
626

627 628 629 630
    class XPUTestRecipocal(TestActivationOPBase):
        def set_case(self):
            self.op_type = "reciprocal"
            self.dtype = self.in_type
631

632 633 634
            np.random.seed(1024)
            x = np.random.uniform(1, 2, [1111, 1117]).astype(self.dtype)
            out = np.reciprocal(x)
635

636 637 638
            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}
639 640


641 642 643
support_types = get_xpu_op_support_types('reciprocal')
for stype in support_types:
    create_test_class(globals(), XPUTestReciprocalOP, stype)
644 645


646 647 648 649
class XPUTestSoftPlusOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'softplus'
        self.use_dynamic_create_class = False
650

651 652 653 654
    class XPUTestSoftPlusBase(TestActivationOPBase):
        def set_case(self):
            self.op_type = "softplus"
            self.dtype = self.in_type
655

656 657 658 659 660 661 662 663
            self.init_config()
            beta = np.random.uniform(0, 1)
            threshold = np.random.uniform(0, 1)
            out = ref_softplus(self.x, beta, threshold)

            self.inputs = {'X': self.x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'beta': beta, 'threshold': threshold}
664

665 666
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
667

668 669 670 671
    class XPUTestSoftPlus_ZeroDim(XPUTestSoftPlusBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, []).astype(self.dtype)

672 673 674
    class XPUTestSoftPlus2(XPUTestSoftPlusBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [1024, 8]).astype(self.dtype)
675

676 677
    class XPUTestSoftPlus3(XPUTestSoftPlusBase):
        def init_config(self):
678 679 680
            self.x = np.random.uniform(-2, 2, [4, 512, 15, 15]).astype(
                self.dtype
            )
681

682 683
    class XPUTestSoftPlus4(XPUTestSoftPlusBase):
        def init_config(self):
684 685 686
            self.x = np.random.uniform(-2, 2, [4, 256, 22, 22]).astype(
                self.dtype
            )
687 688


689 690 691
support_types = get_xpu_op_support_types('softplus')
for stype in support_types:
    create_test_class(globals(), XPUTestSoftPlusOP, stype)
692 693 694 695


def ref_softplus(x, beta=1, threshold=20):
    x_beta = beta * x
696 697 698 699
    out = np.select(
        [x_beta <= threshold, x_beta > threshold],
        [np.log(1 + np.exp(x_beta)) / beta, x],
    )
700 701 702
    return out


L
Lijunhui 已提交
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 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
# XPU_KP unittests, these ops can be found from xpu_op_kpfirst_list.h
class XPUTestBReluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'brelu'
        self.use_dynamic_create_class = False

    class XPUTestBRelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "brelu"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-5, 10, [10, 12]).astype(self.dtype)
            t_min = 1.0
            t_max = 4.0
            # The same with TestAbs
            x[np.abs(x - t_min) < 0.005] = t_min + 0.02
            x[np.abs(x - t_max) < 0.005] = t_max + 0.02
            t = np.copy(x)
            t[t < t_min] = t_min
            t[t > t_max] = t_max

            self.inputs = {'X': x}
            self.outputs = {'Out': t}
            self.attrs = {'use_xpu': True, 't_min': t_min, 't_max': t_max}


support_types = get_xpu_op_support_types('brelu')
for stype in support_types:
    create_test_class(globals(), XPUTestBReluOP, stype)


class XPUTestCeilOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'ceil'
        self.use_dynamic_create_class = False

    class XPUTestCeil(TestActivationOPBase):
        def set_case(self):
            self.op_type = "ceil"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-1, 1, [10, 12]).astype(self.dtype)
            out = np.ceil(x)

            self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('ceil')
for stype in support_types:
    create_test_class(globals(), XPUTestCeilOP, stype)


class XPUTestCeluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'celu'
        self.use_dynamic_create_class = False

    class XPUTestCelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "celu"
            self.dtype = self.in_type

            alpha = 1.5
            x = np.random.uniform(-3, 3, [10, 12]).astype(self.dtype)
            out = ref_celu(x, alpha)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'alpha': alpha}


support_types = get_xpu_op_support_types('celu')
for stype in support_types:
    create_test_class(globals(), XPUTestCeluOP, stype)


def ref_celu(x, alpha):
    out_ref = np.maximum(0, x) + np.minimum(0, alpha * (np.exp(x / alpha) - 1))
    return out_ref.astype(x.dtype)


class XPUTestEluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'elu'
        self.use_dynamic_create_class = False

    class XPUTestElu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "elu"
            self.dtype = self.in_type

798
            alpha = 1.0
L
Lijunhui 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
            x = np.random.uniform(-3, 3, [10, 12]).astype(self.dtype)
            out = ref_elu(x, alpha)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'alpha': alpha}


support_types = get_xpu_op_support_types('elu')
for stype in support_types:
    create_test_class(globals(), XPUTestEluOP, stype)


def ref_elu(x, alpha):
    out_ref = np.where(x > 0, x, alpha * (np.exp(x) - 1))
    return out_ref.astype(x.dtype)


class XPUTestFloorOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'floor'
        self.use_dynamic_create_class = False

    class XPUTestFloor(TestActivationOPBase):
        def set_case(self):
            self.op_type = "floor"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-1, 1, [10, 12]).astype(self.dtype)
            out = np.floor(x)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('floor')
for stype in support_types:
    create_test_class(globals(), XPUTestFloorOP, stype)


class XPUTestHardShrinkOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'hard_shrink'
        self.use_dynamic_create_class = False

    class XPUTestHardShrink(TestActivationOPBase):
        def set_case(self):
            self.op_type = "hard_shrink"
            self.dtype = self.in_type

            threshold = 0.5
            # self.set_attrs()
            np.random.seed(1024)
            x = np.random.uniform(-1, 1, [10, 12]).astype(self.dtype) * 10
            out = ref_hardshrink(x, threshold)

            self.attrs = {'use_xpu': True}
            self.inputs = {'X': x}
            self.outputs = {'Out': out}


support_types = get_xpu_op_support_types('hard_shrink')
for stype in support_types:
    create_test_class(globals(), XPUTestHardShrinkOP, stype)


def ref_hardshrink(x, threshold):
    out = np.copy(x)
    out[(out >= -threshold) & (out <= threshold)] = 0
    return out


class XPUTestHardSigmoidOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'hard_sigmoid'
        self.use_dynamic_create_class = False

    class XPUTestHardSigmoid(TestActivationOPBase):
        def set_case(self):
            self.op_type = "hard_sigmoid"
            self.dtype = self.in_type
            self.slope = 0.166666666666667
            self.offset = 0.5

            x = np.random.uniform(-5, 5, [10, 12]).astype(self.dtype)
            lower_threshold = -self.offset / self.slope
887
            upper_threshold = (1.0 - self.offset) / self.slope
L
Lijunhui 已提交
888 889 890 891 892 893 894 895 896 897 898

            # Same reason as TestAbs
            delta = 0.005
            x[np.abs(x - lower_threshold) < delta] = lower_threshold - 0.02
            x[np.abs(x - upper_threshold) < delta] = upper_threshold - 0.02

            out = ref_hardsigmoid(x, self.slope, self.offset)

            self.attrs = {
                'use_xpu': True,
                'slope': self.slope,
899
                'offset': self.offset,
L
Lijunhui 已提交
900 901 902 903 904 905 906 907 908 909 910
            }
            self.inputs = {'X': x}
            self.outputs = {'Out': out}


support_types = get_xpu_op_support_types('hard_sigmoid')
for stype in support_types:
    create_test_class(globals(), XPUTestHardSigmoidOP, stype)


def ref_hardsigmoid(x, slope=0.166666666666667, offset=0.5):
911
    return np.maximum(np.minimum(x * slope + offset, 1.0), 0.0).astype(x.dtype)
L
Lijunhui 已提交
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 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 978 979 980 981 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


class XPUTestLog1pOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'log1p'
        self.use_dynamic_create_class = False

    class XPUTestLog1p(TestActivationOPBase):
        def set_case(self):
            self.op_type = "log1p"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(0.1, 1, [11, 17]).astype(self.dtype)
            out = np.log1p(x)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('log1p')
for stype in support_types:
    create_test_class(globals(), XPUTestLog1pOP, stype)


class XPUTestLogsigmoidOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'logsigmoid'
        self.use_dynamic_create_class = False

    class XPUTestLogsigmoid(TestActivationOPBase):
        def set_case(self):
            self.op_type = "logsigmoid"
            self.dtype = self.in_type

            np.random.seed(2048)
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            out = np.log(1 / (1 + np.exp(-x)))

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('logsigmoid')
for stype in support_types:
    create_test_class(globals(), XPUTestLogsigmoidOP, stype)


class XPUTestRelu6OP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'relu6'
        self.use_dynamic_create_class = False

    class XPUTestRelu6(TestActivationOPBase):
        def set_case(self):
            self.op_type = "relu6"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-1, 10, [10, 12]).astype(self.dtype)
            x[np.abs(x) < 0.005] = 0.02
            out = ref_relu6(x)

            self.attrs = {'use_xpu': True}
            self.inputs = {'X': x}
            self.outputs = {'Out': out}


support_types = get_xpu_op_support_types('relu6')
for stype in support_types:
    create_test_class(globals(), XPUTestRelu6OP, stype)


def ref_relu6(x, threshold=6.0):
    out = np.copy(x)
    out[np.abs(x - threshold) < 0.005] = threshold + 0.02
    out = np.minimum(np.maximum(x, 0), threshold)
    return out


class XPUTestSiluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'silu'
        self.use_dynamic_create_class = False

    class XPUTestSilu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "silu"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)
            out = x / (np.exp(-x) + 1)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('silu')
for stype in support_types:
    create_test_class(globals(), XPUTestSiluOP, stype)


class XPUTestSoftReluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'soft_relu'
        self.use_dynamic_create_class = False

    class XPUTestSoftRelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "soft_relu"
            self.dtype = self.in_type

            np.random.seed(4096)
            x = np.random.uniform(-3, 3, [4, 4]).astype(self.dtype)
            threshold = 2.0
            # The same reason with TestAbs
            x[np.abs(x - threshold) < 0.005] = threshold + 0.02
            x[np.abs(x + threshold) < 0.005] = -threshold - 0.02
            t = np.copy(x)
            t[t < -threshold] = -threshold
            t[t > threshold] = threshold
1037
            out = np.log(np.exp(t) + 1)
L
Lijunhui 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'threshold': threshold}


support_types = get_xpu_op_support_types('soft_relu')
for stype in support_types:
    create_test_class(globals(), XPUTestSoftReluOP, stype)


class XPUTestSoftSignOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'softsign'
        self.use_dynamic_create_class = False

    class XPUTestSoftSign(TestActivationOPBase):
        def set_case(self):
            self.op_type = "softsign"
            self.dtype = self.in_type

            np.random.seed(1024)
            x = np.random.uniform(-1, 1, [10, 12]).astype(self.dtype)
            out = ref_softsign(x)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('softsign')
for stype in support_types:
    create_test_class(globals(), XPUTestSoftSignOP, stype)


def ref_softsign(x):
    out = np.divide(x, 1 + np.abs(x))
    return out


1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
class XPUTestSoftshrinkOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'softshrink'
        self.use_dynamic_create_class = False

    class XPUTestSoftshrink(TestActivationOPBase):
        def set_case(self):
            self.op_type = "softshrink"
            self.dtype = self.in_type

            threshold = 0.5
            np.random.seed(1023)
            x = np.random.uniform(0.25, 10, [10, 12]).astype(self.dtype)
            out = ref_softshrink(x, threshold)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('softshrink')
for stype in support_types:
    create_test_class(globals(), XPUTestSoftshrinkOP, stype)


def ref_softshrink(x, threshold=0.5):
    out = np.copy(x)
    out = (out < -threshold) * (out + threshold) + (out > threshold) * (
1106 1107
        out - threshold
    )
1108 1109 1110
    return out


L
Lijunhui 已提交
1111 1112 1113 1114 1115
class XPUTestSwishOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'swish'
        self.use_dynamic_create_class = False

1116
    class XPUTestSwishBase(TestActivationOPBase):
L
Lijunhui 已提交
1117 1118 1119 1120
        def set_case(self):
            self.op_type = "swish"
            self.dtype = self.in_type

1121 1122
            self.init_config()
            out = ref_swish(self.x)
L
Lijunhui 已提交
1123

1124
            self.inputs = {'X': self.x}
L
Lijunhui 已提交
1125 1126 1127
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}

1128 1129 1130
        def init_config(self):
            self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)

1131 1132 1133 1134
    class XPUTestSwish_ZeroDim(XPUTestSwishBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, []).astype(self.dtype)

1135 1136 1137 1138 1139 1140
    class XPUTestSwish2(XPUTestSwishBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [1024, 8]).astype(self.dtype)

    class XPUTestSwish3(XPUTestSwishBase):
        def init_config(self):
1141 1142 1143
            self.x = np.random.uniform(-2, 2, [4, 512, 15, 15]).astype(
                self.dtype
            )
1144 1145 1146

    class XPUTestSwish4(XPUTestSwishBase):
        def init_config(self):
1147 1148 1149
            self.x = np.random.uniform(-2, 2, [4, 256, 22, 22]).astype(
                self.dtype
            )
1150

L
Lijunhui 已提交
1151 1152 1153 1154 1155 1156 1157 1158

support_types = get_xpu_op_support_types('swish')
for stype in support_types:
    create_test_class(globals(), XPUTestSwishOP, stype)


def ref_swish(x):
    from scipy.special import expit
1159

L
Lijunhui 已提交
1160 1161 1162 1163
    out = x * expit(x)
    return out


1164 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
class XPUTestThresholdedReluOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'thresholded_relu'
        self.use_dynamic_create_class = False

    class XPUTestThresholdedRelu(TestActivationOPBase):
        def set_case(self):
            self.op_type = "thresholded_relu"
            self.dtype = self.in_type

            threshold = 1.0
            np.random.seed(1024)
            x = np.random.uniform(-20, 20, [10, 12]).astype(self.dtype)
            x[np.abs(x) < 0.005] = 0.02
            out = ref_thresholded_relu(x, threshold)

            self.inputs = {'X': x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}


support_types = get_xpu_op_support_types('thresholded_relu')
for stype in support_types:
    create_test_class(globals(), XPUTestThresholdedReluOP, stype)


def ref_thresholded_relu(x, threshold=1.0):
    out = (x > threshold) * x
    return out


1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
class XPUTestMishOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'mish'
        self.use_dynamic_create_class = False

    class XPUTestMishBase(TestActivationOPBase):
        def set_case(self):
            self.op_type = "mish"
            self.dtype = self.in_type

            self.init_config()
            threshold = np.random.uniform(0, 1)
            out = ref_mish(self.x, threshold)

            self.inputs = {'X': self.x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True, 'threshold': threshold}

        def init_config(self):
            self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype)

1216 1217 1218 1219
    class XPUTestMish_ZeroDim(XPUTestMishBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, []).astype(self.dtype)

1220 1221 1222 1223 1224 1225
    class XPUTestMish2(XPUTestMishBase):
        def init_config(self):
            self.x = np.random.uniform(-2, 2, [1024, 8]).astype(self.dtype)

    class XPUTestMish3(XPUTestMishBase):
        def init_config(self):
1226 1227 1228
            self.x = np.random.uniform(-2, 2, [4, 512, 15, 15]).astype(
                self.dtype
            )
1229 1230 1231

    class XPUTestMish4(XPUTestMishBase):
        def init_config(self):
1232 1233 1234
            self.x = np.random.uniform(-2, 2, [4, 256, 22, 22]).astype(
                self.dtype
            )
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247


support_types = get_xpu_op_support_types('mish')
for stype in support_types:
    create_test_class(globals(), XPUTestMishOP, stype)


def ref_mish(x, threshold=20):
    sp = np.select([x <= threshold, x > threshold], [np.log(1 + np.exp(x)), x])
    out = x * np.tanh(sp)
    return out


1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 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 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
class XPUTestSinOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'sin'
        self.use_dynamic_create_class = False

    class XPUTestSinBase(TestActivationOPBase):
        def set_case(self):
            self.op_type = "sin"
            self.dtype = self.in_type

            self.init_config()
            out = np.sin(self.x)

            self.inputs = {'X': self.x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}

        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [11, 17]).astype(
                self.dtype
            )

    class XPUTestSin_ZeroDim(XPUTestSinBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, []).astype(self.dtype)

    class XPUTestSin2(XPUTestSinBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [1024, 8]).astype(
                self.dtype
            )

    class XPUTestSin3(XPUTestSinBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [4, 512, 15, 15]).astype(
                self.dtype
            )

    class XPUTestSin4(XPUTestSinBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [4, 256, 22, 22]).astype(
                self.dtype
            )


support_types = get_xpu_op_support_types('sin')
for stype in support_types:
    create_test_class(globals(), XPUTestSinOP, stype)


class XPUTestCosOP(XPUOpTestWrapper):
    def __init__(self):
        self.op_name = 'cos'
        self.use_dynamic_create_class = False

    class XPUTestCosBase(TestActivationOPBase):
        def set_case(self):
            self.op_type = "cos"
            self.dtype = self.in_type

            self.init_config()
            out = np.cos(self.x)

            self.inputs = {'X': self.x}
            self.outputs = {'Out': out}
            self.attrs = {'use_xpu': True}

        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [11, 17]).astype(
                self.dtype
            )

    class XPUTestCos_ZeroDim(XPUTestCosBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, []).astype(self.dtype)

    class XPUTestCos2(XPUTestCosBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [1024, 8]).astype(
                self.dtype
            )

    class XPUTestCos3(XPUTestCosBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [4, 512, 15, 15]).astype(
                self.dtype
            )

    class XPUTestCos4(XPUTestCosBase):
        def init_config(self):
            self.x = np.random.uniform(-np.pi, np.pi, [4, 256, 22, 22]).astype(
                self.dtype
            )


support_types = get_xpu_op_support_types('cos')
for stype in support_types:
    create_test_class(globals(), XPUTestCosOP, stype)

1347 1348
if __name__ == "__main__":
    unittest.main()