Skip to content

Fix 堆栈溢出 (stack overflow) of case8: paddle.unique_consecutive #49983

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

Merged
merged 3 commits into from
Feb 3, 2023
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
1 change: 1 addition & 0 deletions paddle/phi/kernels/cpu/unique_consecutive_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void UniqueConsecutiveKernel(const Context& dev_ctx,
dev_ctx, x, out, return_inverse, return_counts, index, counts));
} else {
int valid_axis = axis[0];
if (valid_axis < 0) valid_axis += x.dims().size();
phi::VisitDataTypeTiny(
data_type,
UniqueConsecutiveDimFunctor<Context, T>(dev_ctx,
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/kernels/gpu/unique_consecutive_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void UniqueConsecutiveKernel(const Context& dev_ctx,
} else {
// 'axis' is required.
int valid_axis = axis[0];
if (valid_axis < 0) valid_axis += x.dims().size();
phi::VisitDataTypeTiny(
data_type,
UniqueConsecutiveDimsCUDAFunctor<Context, T>(dev_ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import paddle.fluid.core as core


def reference_unique_consecutive(X, return_inverse=False, return_counts=False):
def reference_unique_consecutive(
X, return_inverse=False, return_counts=False, axis=None
):
"""
Reference unique_consecutive implementation using python.
Args:
Expand Down Expand Up @@ -273,6 +275,47 @@ def test_dygraph(self):
)


class TestUniqueConsecutiveCase3API(unittest.TestCase):
def setUp(self):
self.places = [fluid.CPUPlace()]
if core.is_compiled_with_cuda():
self.places.append(fluid.CUDAPlace(0))

def check_static_result(self, place):
with fluid.program_guard(fluid.Program(), fluid.Program()):
paddle.enable_static()
input_x = fluid.data(
name="input_x",
shape=[
100,
],
dtype="float32",
)
result, inverse, counts = paddle.unique_consecutive(
input_x, return_inverse=True, return_counts=True, axis=-1
)
x_np = np.random.randint(20, size=100).astype("float32")
exe = fluid.Executor(place)
fetches = exe.run(
fluid.default_main_program(),
feed={"input_x": x_np},
fetch_list=[result],
)

def test_static(self):
for place in self.places:
self.check_static_result(place=place)

def test_dygraph(self):
for place in self.places:
with fluid.dygraph.guard(place):
input_x = np.random.randint(20, size=100).astype("float64")
x = paddle.to_tensor(input_x)
result, inverse, counts = paddle.unique_consecutive(
x, return_inverse=True, return_counts=True, axis=-1
)


class TestUniqueConsecutiveEmptyInput(OpTest):
"""empty input"""

Expand Down