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

【Fix PIR Unittest No.498,505,275】Fix some test case in PIR #65617

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions python/paddle/nn/functional/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ def adaptive_max_pool1d(x, output_size, return_mask=False, name=None):
pool_size = [1] + convert_to_list(output_size, 1, 'pool_size')

x = unsqueeze(x, [2])
if in_dygraph_mode():
if in_dynamic_or_pir_mode():
pool_out = _C_ops.max_pool2d_with_index(
x, pool_size, [1, 1], [0, 0], False, True
)
Expand Down Expand Up @@ -1912,7 +1912,7 @@ def adaptive_max_pool2d(x, output_size, return_mask=False, name=None):
output_size[0] = in_h
if output_size[1] is None:
output_size[1] = in_w
if in_dygraph_mode():
if in_dynamic_or_pir_mode():
pool_out = _C_ops.max_pool2d_with_index(
x, output_size, [1, 1], [0, 0], False, True
)
Expand Down Expand Up @@ -2003,7 +2003,7 @@ def adaptive_max_pool3d(x, output_size, return_mask=False, name=None):
if output_size[2] is None:
output_size[2] = in_w

if in_dygraph_mode():
if in_dynamic_or_pir_mode():
# By default, strides is [1,1,1] and paddings is [0, 0, 0]
pool_out = _C_ops.max_pool3d_with_index(
x, output_size, [1, 1, 1], [0, 0, 0], False, True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,46 +279,53 @@ 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, 7, 7], dtype="float32"
)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()
paddle.enable_static()
x = paddle.static.data(
name="x", shape=[2, 3, 7, 7], dtype="float32"
)

adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(output_size=[3, 3])
out_1 = adaptive_max_pool(x=x)
adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
output_size=[3, 3]
)
out_1 = adaptive_max_pool(x=x)

adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(output_size=5)
out_2 = adaptive_max_pool(x=x)
adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(output_size=5)
out_2 = adaptive_max_pool(x=x)

adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(output_size=[2, 5])
out_3 = adaptive_max_pool(x=x)
adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
output_size=[2, 5]
)
out_3 = adaptive_max_pool(x=x)

# adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
# output_size=[3, 3], data_format="NHWC")
# out_4 = adaptive_max_pool(x=x)
# adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
# output_size=[3, 3], data_format="NHWC")
# out_4 = adaptive_max_pool(x=x)

adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
output_size=[None, 3]
)
out_5 = adaptive_max_pool(x=x)
adaptive_max_pool = paddle.nn.AdaptiveMaxPool2D(
output_size=[None, 3]
)
out_5 = adaptive_max_pool(x=x)

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

np.testing.assert_allclose(res_1, self.res_1_np)
np.testing.assert_allclose(res_1, self.res_1_np)

np.testing.assert_allclose(res_2, self.res_2_np)
np.testing.assert_allclose(res_2, self.res_2_np)

np.testing.assert_allclose(res_3, self.res_3_np)
np.testing.assert_allclose(res_3, self.res_3_np)

# np.testing.assert_allclose(res_4, self.res_4_np)
# np.testing.assert_allclose(res_4, self.res_4_np)

np.testing.assert_allclose(res_5, self.res_5_np)
np.testing.assert_allclose(res_5, self.res_5_np)

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