test_custom_optional.py 26.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

import os
import unittest

import numpy as np
from utils import extra_cc_args, extra_nvcc_args, paddle_includes

import paddle
22
from paddle import static
23 24 25 26 27
from paddle.utils.cpp_extension import get_build_directory, load
from paddle.utils.cpp_extension.extension_utils import run_cmd

# Because Windows don't use docker, the shared lib already exists in the
# cache dir, it will not be compiled again unless the shared lib is removed.
28
file = f'{get_build_directory()}\\custom_optional\\custom_optional.pyd'
29
if os.name == 'nt' and os.path.isfile(file):
30
    cmd = f'del {file}'
31 32 33 34 35 36 37 38 39 40 41 42 43
    run_cmd(cmd, True)

# Compile and load custom op Just-In-Time.
custom_optional = load(
    name='custom_optional',
    sources=['custom_optional.cc'],
    extra_include_paths=paddle_includes,  # add for Coverage CI
    extra_cxx_cflags=extra_cc_args,  # test for cflags
    extra_cuda_cflags=extra_nvcc_args,  # test for cflags
    verbose=True,
)


44
def optional_dynamic_add(custom_func, device, dtype, np_x, np_y):
45 46 47 48 49 50 51
    paddle.set_device(device)
    x = paddle.to_tensor(np_x, dtype=dtype, stop_gradient=False)

    if np_y is not None:
        y = paddle.to_tensor(np_y, dtype=dtype, stop_gradient=False)
    else:
        y = x
52
    if custom_func:
53 54 55 56 57 58 59 60
        out = custom_optional.custom_add(x, y if np_y is not None else None)
    else:
        out = paddle.add(x, y)

    out.backward()
    return x.numpy(), out.numpy(), x.grad.numpy()


61
def optional_static_add(custom_func, device, dtype, np_x, np_y):
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    paddle.enable_static()
    paddle.set_device(device)
    with static.scope_guard(static.Scope()):
        with static.program_guard(static.Program()):
            x = static.data(name="x", shape=[None, np_x.shape[1]], dtype=dtype)
            x.stop_gradient = False
            if np_y is not None:
                y = static.data(
                    name="y", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y.stop_gradient = False
                feed_dict = {
                    "x": np_x.astype(dtype),
                    "y": np_y.astype(dtype),
                }
            else:
                y = x
                feed_dict = {
                    "x": np_x.astype(dtype),
                }
82
            if custom_func:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                out = custom_optional.custom_add(
                    x, y if np_y is not None else None
                )
            else:
                out = paddle.add(x, y)

            mean_out = paddle.mean(out)
            static.append_backward(mean_out)

            exe = static.Executor()
            exe.run(static.default_startup_program())

            x_v, out_v, x_grad_v = exe.run(
                static.default_main_program(),
                feed=feed_dict,
                fetch_list=[
                    x.name,
                    out.name,
                    x.name + "@GRAD",
                ],
            )
    paddle.disable_static()
    return x_v, out_v, x_grad_v


108 109 110 111 112 113 114 115 116 117 118
'''
if (y) {
  outX = 2 * x + y;
  outY = x + y;
} else {
  outX = 2 * x;
  outY = None;
}
'''


119
def optional_inplace_dynamic_add(custom_func, device, dtype, np_x, np_y):
120 121 122 123 124
    paddle.set_device(device)
    x = paddle.to_tensor(np_x, dtype=dtype, stop_gradient=False)

    if np_y is not None:
        y = paddle.to_tensor(np_y, dtype=dtype, stop_gradient=True)
125
        if custom_func:
126 127 128 129 130 131 132 133 134 135
            outx, outy = custom_optional.custom_optional_inplace_add(x, y)
        else:
            # We need to accumulate y's grad here.
            y.stop_gradient = False
            outx = 2 * x + y
            # Inplace leaf Tensor's stop_gradient should be True
            y.stop_gradient = True
            outy = y.add_(x)
    else:
        y = None
136
        if custom_func:
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
            outx, outy = custom_optional.custom_optional_inplace_add(x, y)
        else:
            outx = 2 * x
            outy = None
        assert (
            outy is None
        ), "The output `outy` of optional_inplace_dynamic_add should be None"

    out = outx + outy if outy is not None else outx
    out.backward()
    return (
        x.numpy(),
        outx.numpy(),
        y.numpy() if y is not None else None,
        outy.numpy() if outy is not None else None,
        out.numpy(),
        x.grad.numpy(),
        y.grad.numpy() if y is not None and y.grad is not None else None,
    )


158
def optional_inplace_static_add(custom_func, device, dtype, np_x, np_y):
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    paddle.enable_static()
    paddle.set_device(device)
    with static.scope_guard(static.Scope()):
        with static.program_guard(static.Program()):
            x = static.data(name="x", shape=[None, np_x.shape[1]], dtype=dtype)
            x.stop_gradient = False
            if np_y is not None:
                y = static.data(
                    name="y", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y.stop_gradient = False
                feed_dict = {
                    "x": np_x.astype(dtype),
                    "y": np_y.astype(dtype),
                }
174
                if custom_func:
175 176 177 178 179 180 181 182 183 184
                    outx, outy = custom_optional.custom_optional_inplace_add(
                        x, y
                    )
                else:
                    outx = 2 * x + y
                    outy = x + y
            else:
                feed_dict = {
                    "x": np_x.astype(dtype),
                }
185
                if custom_func:
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                    outx, outy = custom_optional.custom_optional_inplace_add(
                        x, None
                    )
                else:
                    outx = 2 * x
                    outy = None
            out = outx + outy if outy is not None else outx
            mean_out = paddle.mean(out)
            static.append_backward(mean_out)

            exe = static.Executor()
            exe.run(static.default_startup_program())

            if np_y is not None:
                x_v, out_v, x_grad_v, y_grad_v = exe.run(
                    static.default_main_program(),
                    feed=feed_dict,
                    fetch_list=[
                        x.name,
                        out.name,
                        x.name + "@GRAD",
                        y.name + "@GRAD",
                    ],
                )
                paddle.disable_static()
                return [x_v, out_v, x_grad_v, y_grad_v]
            else:
                x_v, out_v, x_grad_v = exe.run(
                    static.default_main_program(),
                    feed=feed_dict,
                    fetch_list=[
                        x.name,
                        out.name,
                        x.name + "@GRAD",
                    ],
                )
                paddle.disable_static()
                return [x_v, out_v, x_grad_v]


226
def optional_vector_dynamic_add(custom_func, device, dtype, np_x, np_inputs):
227 228 229 230 231 232 233 234
    paddle.set_device(device)
    x = paddle.to_tensor(np_x, dtype=dtype, stop_gradient=False)

    if np_inputs is not None:
        inputs = [
            paddle.to_tensor(np_input, dtype=dtype, stop_gradient=False)
            for np_input in np_inputs
        ]
235
        if custom_func:
236 237 238 239 240 241
            out = custom_optional.custom_add_vec(x, inputs)
        else:
            out = paddle.add(x, inputs[0])
            for input in inputs[1:]:
                out = paddle.add(out, input)
    else:
242
        if custom_func:
243 244 245 246 247 248 249 250
            out = custom_optional.custom_add_vec(x, None)
        else:
            out = paddle.add(x, x)

    out.backward()
    return x.numpy(), out.numpy(), x.grad.numpy()


251
def optional_vector_static_add(custom_func, device, dtype, np_x, np_inputs):
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
    paddle.enable_static()
    paddle.set_device(device)
    with static.scope_guard(static.Scope()):
        with static.program_guard(static.Program()):
            x = static.data(name="x", shape=[None, np_x.shape[1]], dtype=dtype)
            x.stop_gradient = False
            feed_dict = {"x": np_x.astype(dtype)}
            if np_inputs is not None:
                y1 = static.data(
                    name="y1", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y1.stop_gradient = False
                y2 = static.data(
                    name="y2", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y2.stop_gradient = False
                feed_dict.update(
                    {
                        "y1": np_inputs[0].astype(dtype),
                        "y2": np_inputs[1].astype(dtype),
                    }
                )
274
                if custom_func:
275 276 277 278 279
                    out = custom_optional.custom_add_vec(x, [y1, y2])
                else:
                    out = paddle.add(x, y1)
                    out = paddle.add(out, y2)
            else:
280
                if custom_func:
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
                    out = custom_optional.custom_add_vec(x, None)
                else:
                    out = paddle.add(x, x)

            mean_out = paddle.mean(out)
            static.append_backward(mean_out)

            exe = static.Executor()
            exe.run(static.default_startup_program())

            x_v, out_v, x_grad_v = exe.run(
                static.default_main_program(),
                feed=feed_dict,
                fetch_list=[
                    x.name,
                    out.name,
                    x.name + "@GRAD",
                ],
            )
    paddle.disable_static()
    return x_v, out_v, x_grad_v


304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 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 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
'''
if (y) {
  outX = 2 * x + y[1...n];
  outY[i] = x + y[i];
} else {
  outX = 2 * x;
  outY = None;
}
'''


def optional_inplace_vector_dynamic_add(
    custom_func, device, dtype, np_x, np_inputs
):
    paddle.set_device(device)
    x = paddle.to_tensor(np_x, dtype=dtype, stop_gradient=False)

    if np_inputs is not None:
        inputs = [
            paddle.to_tensor(np_input, dtype=dtype, stop_gradient=True)
            for np_input in np_inputs
        ]
        if custom_func:
            outx, outy = custom_optional.custom_optional_inplace_add_vec(
                x, inputs
            )
        else:
            outx = 2 * x
            outy = []
            for input in inputs:
                # We need to accumulate y's grad here.
                input.stop_gradient = False
                outx = outx + input
                # Inplace leaf Tensor's stop_gradient should be True
                input.stop_gradient = True
                outy.append(input.add_(x))
    else:
        if custom_func:
            outx, outy = custom_optional.custom_optional_inplace_add_vec(
                x, None
            )
        else:
            outx = 2 * x
            outy = None
        assert (
            outy is None
        ), "The output `outy` of optional_inplace_dynamic_add should be None"

    if outy is not None:
        out = outx
        for tensor in outy:
            out = out + tensor
    else:
        out = outx
    out.backward()
    return (
        x.numpy(),
        outx.numpy(),
        [y.numpy() for y in inputs] if np_inputs is not None else None,
        [t.numpy() for t in outy] if outy is not None else None,
        out.numpy(),
        x.grad.numpy(),
        [y.grad.numpy() for y in inputs]
        if np_inputs is not None and inputs[0].grad is not None
        else None,
    )


def optional_inplace_vector_static_add(
    custom_func, device, dtype, np_x, np_inputs
):
    paddle.enable_static()
    paddle.set_device(device)
    with static.scope_guard(static.Scope()):
        with static.program_guard(static.Program()):
            x = static.data(name="x", shape=[None, np_x.shape[1]], dtype=dtype)
            x.stop_gradient = False
            feed_dict = {
                "x": np_x.astype(dtype),
            }
            if np_inputs is not None:
                y1 = static.data(
                    name="y1", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y1.stop_gradient = False
                y2 = static.data(
                    name="y2", shape=[None, np_x.shape[1]], dtype=dtype
                )
                y2.stop_gradient = False
                feed_dict.update(
                    {
                        "y1": np_inputs[0].astype(dtype),
                        "y2": np_inputs[1].astype(dtype),
                    }
                )
                if custom_func:
                    (
                        outx,
                        outy,
                    ) = custom_optional.custom_optional_inplace_add_vec(
                        x, [y1, y2]
                    )
                else:
                    outx = paddle.add(paddle.add(paddle.add(x, x), y1), y2)
                    # outx = 2 * x + y1 + y2
                    outy = [x + y1, x + y2]
            else:
                if custom_func:
                    (
                        outx,
                        outy,
                    ) = custom_optional.custom_optional_inplace_add_vec(x, None)
                else:
                    outx = 2 * x
                    outy = None
            if np_inputs is not None:
                out = outx + outy[0] + outy[1]
            else:
                out = outx
            mean_out = paddle.mean(out)
            static.append_backward(mean_out)

            exe = static.Executor()
            exe.run(static.default_startup_program())

            if np_inputs is not None:
                x_v, out_v, x_grad_v, y1_grad_v, y2_grad_v = exe.run(
                    static.default_main_program(),
                    feed=feed_dict,
                    fetch_list=[
                        x.name,
                        out.name,
                        x.name + "@GRAD",
                        y1.name + "@GRAD",
                        y2.name + "@GRAD",
                    ],
                )
                paddle.disable_static()
                return [x_v, out_v, x_grad_v, y1_grad_v, y2_grad_v]
            else:
                x_v, out_v, x_grad_v = exe.run(
                    static.default_main_program(),
                    feed=feed_dict,
                    fetch_list=[
                        x.name,
                        out.name,
                        x.name + "@GRAD",
                    ],
                )
                paddle.disable_static()
                return [x_v, out_v, x_grad_v]


457 458 459 460 461 462
class TestCustomOptionalJit(unittest.TestCase):
    def setUp(self):
        self.dtypes = ['float32', 'float64']
        self.devices = ['cpu']
        self.np_x = np.random.random((3, 2)).astype("float32")
        self.np_y = np.random.random((3, 2)).astype("float32")
463 464 465 466
        self.np_inputs = [
            np.random.random((3, 2)).astype("float32"),
            np.random.random((3, 2)).astype("float32"),
        ]
467 468

    def check_output(self, out, pd_out, name):
469 470 471 472
        if out is None and pd_out is None:
            return
        assert out is not None, "out value of " + name + " is None"
        assert pd_out is not None, "pd_out value of " + name + " is None"
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
        if isinstance(out, list) and isinstance(pd_out, list):
            for idx in range(len(out)):
                np.testing.assert_array_equal(
                    out[idx],
                    pd_out[idx],
                    err_msg='custom op {}: {},\n paddle api {}: {}'.format(
                        name, out[idx], name, pd_out[idx]
                    ),
                )
        else:
            np.testing.assert_array_equal(
                out,
                pd_out,
                err_msg='custom op {}: {},\n paddle api {}: {}'.format(
                    name, out, name, pd_out
                ),
            )
490 491

    def check_output_allclose(self, out, pd_out, name):
492 493 494 495
        if out is None and pd_out is None:
            return
        assert out is not None, "out value of " + name + " is None"
        assert pd_out is not None, "pd_out value of " + name + " is None"
496 497 498 499 500 501 502 503 504 505
        np.testing.assert_allclose(
            out,
            pd_out,
            rtol=5e-5,
            atol=1e-2,
            err_msg='custom op {}: {},\n paddle api {}: {}'.format(
                name, out, name, pd_out
            ),
        )

506
    def test_optional_static_add(self):
507 508
        for device in self.devices:
            for dtype in self.dtypes:
509 510 511 512 513 514 515 516
                for np_y in [None, self.np_y]:
                    (pd_x, pd_out, pd_x_grad,) = optional_static_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
517 518 519 520 521
                    (
                        custom_x,
                        custom_out,
                        custom_x_grad,
                    ) = optional_static_add(
522 523 524 525 526 527 528
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )

529 530 531
                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")
532

533
    def test_optional_dynamic_add(self):
534 535
        for device in self.devices:
            for dtype in self.dtypes:
536 537 538 539 540 541 542 543
                for np_y in [None, self.np_y]:
                    (pd_x, pd_out, pd_x_grad,) = optional_dynamic_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
544 545 546 547 548
                    (
                        custom_x,
                        custom_out,
                        custom_x_grad,
                    ) = optional_dynamic_add(
549 550 551 552 553 554
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
555

556 557 558
                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")
559

560 561 562 563 564 565 566 567 568 569 570
    def test_optional_inplace_static_add(self):
        for device in self.devices:
            for dtype in self.dtypes:
                for np_y in [None, self.np_y]:
                    pd_tuple = optional_inplace_static_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
571
                    custom_tuple = optional_inplace_static_add(
572 573 574 575 576 577 578
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )

579 580 581 582 583 584 585
                    self.check_output(custom_tuple[0], pd_tuple[0], "x")
                    self.check_output(custom_tuple[1], pd_tuple[1], "out")
                    self.check_output(custom_tuple[2], pd_tuple[2], "x_grad")
                    if len(custom_tuple) > 3:
                        self.check_output(
                            custom_tuple[3], pd_tuple[3], "y_grad"
                        )
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606

    def test_optional_inplace_dynamic_add(self):
        for device in self.devices:
            for dtype in self.dtypes:
                for np_y in [None, self.np_y]:
                    (
                        pd_x,
                        pd_outx,
                        pd_y,
                        pd_outy,
                        pd_out,
                        pd_x_grad,
                        pd_y_grad,
                    ) = optional_inplace_dynamic_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
                    (
607 608 609 610 611 612 613
                        custom_x,
                        custom_outx,
                        custom_y,
                        custom_outy,
                        custom_out,
                        custom_x_grad,
                        custom_y_grad,
614 615 616 617 618 619 620 621 622
                    ) = optional_inplace_dynamic_add(
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )

                    self.check_output(pd_y, pd_outy, "inplace_pd_y")
623
                    self.check_output(custom_y, custom_outy, "inplace_custom_y")
624

625 626 627 628 629 630 631
                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_outx, pd_outx, "outx")
                    self.check_output(custom_y, pd_y, "y")
                    self.check_output(custom_outy, pd_outy, "outy")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")
                    self.check_output(custom_y_grad, pd_y_grad, "y_grad")
632

633
    def test_optional_vector_static_add(self):
634 635
        for device in self.devices:
            for dtype in self.dtypes:
636
                for np_y in [None, self.np_inputs]:
637 638 639 640 641
                    (
                        custom_x,
                        custom_out,
                        custom_x_grad,
                    ) = optional_vector_static_add(
642 643 644 645 646 647 648 649 650 651 652 653 654
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
                    (pd_x, pd_out, pd_x_grad,) = optional_vector_static_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
655

656 657 658
                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")
659

660
    def test_optional_vector_dynamic_add(self):
661 662
        for device in self.devices:
            for dtype in self.dtypes:
663
                for np_y in [None, self.np_inputs]:
664 665 666 667 668
                    (
                        custom_x,
                        custom_out,
                        custom_x_grad,
                    ) = optional_vector_dynamic_add(
669 670 671 672 673 674 675 676 677 678 679 680 681
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
                    (pd_x, pd_out, pd_x_grad,) = optional_vector_dynamic_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
682

683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 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
                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")

    def test_optional_inplace_vector_static_add(self):
        for device in self.devices:
            for dtype in self.dtypes:
                for np_y in [None, self.np_inputs]:
                    pd_tuple = optional_inplace_vector_static_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
                    custom_tuple = optional_inplace_vector_static_add(
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )

                    self.check_output(custom_tuple[0], pd_tuple[0], "x")
                    self.check_output(custom_tuple[1], pd_tuple[1], "out")
                    self.check_output(custom_tuple[2], pd_tuple[2], "x_grad")
                    if len(custom_tuple) > 3:
                        self.check_output(
                            custom_tuple[3], pd_tuple[3], "y1_grad"
                        )
                        self.check_output(
                            custom_tuple[4], pd_tuple[4], "y2_grad"
                        )

    def test_optional_inplace_vector_dynamic_add(self):
        for device in self.devices:
            for dtype in self.dtypes:
                for np_y in [None, self.np_inputs]:
                    (
                        custom_x,
                        custom_outx,
                        custom_y,
                        custom_outy,
                        custom_out,
                        custom_x_grad,
                        custom_y_grad,
                    ) = optional_inplace_vector_dynamic_add(
                        True,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )
                    (
                        pd_x,
                        pd_outx,
                        pd_y,
                        pd_outy,
                        pd_out,
                        pd_x_grad,
                        pd_y_grad,
                    ) = optional_inplace_vector_dynamic_add(
                        False,
                        device,
                        dtype,
                        self.np_x,
                        np_y,
                    )

                    self.check_output(pd_y, pd_outy, "inplace_pd_y")
                    self.check_output(custom_y, custom_outy, "inplace_custom_y")

                    self.check_output(custom_x, pd_x, "x")
                    self.check_output(custom_outx, pd_outx, "outx")
                    self.check_output(custom_y, pd_y, "y")
                    self.check_output(custom_outy, pd_outy, "outy")
                    self.check_output(custom_out, pd_out, "out")
                    self.check_output(custom_x_grad, pd_x_grad, "x_grad")
                    self.check_output(custom_y_grad, pd_y_grad, "y_grad")
762 763 764 765


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