Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR]Open uts for AdaptiveAvgPool3D #60636

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 104 additions & 94 deletions test/legacy_test/test_adaptive_avg_pool3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import numpy as np

import paddle
from paddle import base
from paddle.base import core
from paddle.pir_utils import test_with_pir_api


def adaptive_start_index(index, input_size, output_size):
Expand Down Expand Up @@ -134,56 +134,62 @@ def setUp(self):
x=self.x_np, output_size=[None, 3, None], pool_type="avg"
)

@test_with_pir_api
def test_static_graph(self):
for use_cuda in (
[False, True] if core.is_compiled_with_cuda() else [False]
):
place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()
paddle.enable_static()
x = paddle.static.data(
name="x", shape=[2, 3, 5, 7, 7], dtype="float32"
)

out_1 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[3, 3, 3]
)

out_2 = paddle.nn.functional.adaptive_avg_pool3d(x=x, output_size=5)

out_3 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[2, 3, 5]
)

out_4 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[3, 3, 3], data_format="NDHWC"
)

out_5 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[None, 3, None]
)

exe = paddle.static.Executor(place=place)
[res_1, res_2, res_3, res_4, res_5] = exe.run(
base.default_main_program(),
feed={"x": self.x_np},
fetch_list=[out_1, out_2, out_3, out_4, out_5],
)

np.testing.assert_allclose(
res_1, self.res_1_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_2, self.res_2_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_3, self.res_3_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_4, self.res_4_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_5, self.res_5_np, rtol=1e-5, atol=1e-8
)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
x = paddle.static.data(
name="x", shape=[2, 3, 5, 7, 7], dtype="float32"
)

out_1 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[3, 3, 3]
)

out_2 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=5
)

out_3 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[2, 3, 5]
)

out_4 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[3, 3, 3], data_format="NDHWC"
)

out_5 = paddle.nn.functional.adaptive_avg_pool3d(
x=x, output_size=[None, 3, None]
)

exe = paddle.static.Executor(place=place)
[res_1, res_2, res_3, res_4, res_5] = exe.run(
paddle.static.default_main_program(),
feed={"x": self.x_np},
fetch_list=[out_1, out_2, out_3, out_4, out_5],
)

np.testing.assert_allclose(
res_1, self.res_1_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_2, self.res_2_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_3, self.res_3_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_4, self.res_4_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_5, self.res_5_np, rtol=1e-5, atol=1e-8
)

def test_dynamic_graph(self):
for use_cuda in (
Expand Down Expand Up @@ -261,61 +267,65 @@ def setUp(self):
x=self.x_np, output_size=[None, 3, None], pool_type="avg"
)

@test_with_pir_api
def test_static_graph(self):
for use_cuda in (
[False, True] if core.is_compiled_with_cuda() else [False]
):
place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()
paddle.enable_static()
x = paddle.static.data(
name="x", shape=[2, 3, 5, 7, 7], dtype="float32"
)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[3, 3, 3]
)
out_1 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(output_size=5)
out_2 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[2, 3, 5]
)
out_3 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[3, 3, 3], data_format="NDHWC"
)
out_4 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[None, 3, None]
)
out_5 = adaptive_avg_pool(x=x)

exe = paddle.static.Executor(place=place)
[res_1, res_2, res_3, res_4, res_5] = exe.run(
base.default_main_program(),
feed={"x": self.x_np},
fetch_list=[out_1, out_2, out_3, out_4, out_5],
)

np.testing.assert_allclose(
res_1, self.res_1_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_2, self.res_2_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_3, self.res_3_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_4, self.res_4_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_5, self.res_5_np, rtol=1e-5, atol=1e-8
)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
x = paddle.static.data(
name="x", shape=[2, 3, 5, 7, 7], dtype="float32"
)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[3, 3, 3]
)
out_1 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(output_size=5)
out_2 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[2, 3, 5]
)
out_3 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[3, 3, 3], data_format="NDHWC"
)
out_4 = adaptive_avg_pool(x=x)

adaptive_avg_pool = paddle.nn.AdaptiveAvgPool3D(
output_size=[None, 3, None]
)
out_5 = adaptive_avg_pool(x=x)

exe = paddle.static.Executor(place=place)
[res_1, res_2, res_3, res_4, res_5] = exe.run(
paddle.static.default_main_program(),
feed={"x": self.x_np},
fetch_list=[out_1, out_2, out_3, out_4, out_5],
)

np.testing.assert_allclose(
res_1, self.res_1_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_2, self.res_2_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_3, self.res_3_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_4, self.res_4_np, rtol=1e-5, atol=1e-8
)
np.testing.assert_allclose(
res_5, self.res_5_np, rtol=1e-5, atol=1e-8
)

def test_dynamic_graph(self):
for use_cuda in (
Expand Down