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 graph reindex #50171

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 4 additions & 0 deletions paddle/phi/kernels/cpu/graph_reindex_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ void GraphReindexKernel(const Context& dev_ctx,
}
// Reindex Dst
// Add support for multi-type edges reindex
PADDLE_ENFORCE_NE(bs,
0,
phi::errors::InvalidArgument(
"x.dims()[0] should not be 0 (Division by zero)."));
int num_edge_types = count.dims()[0] / bs;
int cnt = 0;
for (int i = 0; i < num_edge_types; i++) {
Expand Down
4 changes: 4 additions & 0 deletions paddle/phi/kernels/gpu/graph_reindex_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ void GraphReindexKernel(const Context& dev_ctx,

// Get reindex dst edge.
// Add support for multi-type edges reindex.
PADDLE_ENFORCE_NE(bs,
0,
phi::errors::InvalidArgument(
"x.dims()[0] should not be 0 (Division by zero)."));
int num_ac_count = count.dims()[0];
int num_edge_types = num_ac_count / bs;
thrust::device_vector<int> unique_dst_reindex(bs);
Expand Down
41 changes: 41 additions & 0 deletions python/paddle/fluid/tests/unittests/test_graph_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ def test_reindex_result(self):
np.testing.assert_allclose(self.reindex_dst, reindex_dst, rtol=1e-05)
np.testing.assert_allclose(self.out_nodes, out_nodes, rtol=1e-05)

with paddle.fluid.dygraph.guard():
tianxingxia-cn marked this conversation as resolved.
Show resolved Hide resolved

def test_reindex_0_result():
"""
division by zero test
issue url: https://github.com/PaddlePaddle/Paddle/issues/49919#issuecomment-1386649810
"""
array = np.array([], dtype=np.float32)
x2 = paddle.to_tensor(np.reshape(array, [0]), dtype='int32')
paddle.incubate.graph_reindex(
x=x2,
neighbors=x2,
count=x2,
value_buffer=x2,
index_buffer=x2,
flag_buffer_hashtable=False,
)

self.assertRaises(ValueError, test_reindex_0_result)

def test_heter_reindex_result(self):
paddle.disable_static()
x = paddle.to_tensor(self.x)
Expand Down Expand Up @@ -258,6 +278,27 @@ def test_reindex_result(self):
np.testing.assert_allclose(self.reindex_dst, reindex_dst, rtol=1e-05)
np.testing.assert_allclose(self.out_nodes, out_nodes, rtol=1e-05)

with paddle.fluid.dygraph.guard():

def test_reindex_0_result():
"""
division by zero test
"""
array = np.array([], dtype=np.float32)
x2 = paddle.to_tensor(np.reshape(array, [0]), dtype='int32')
x3 = paddle.to_tensor(
np.array([0], dtype=np.float32), dtype='int32'
)
paddle.geometric.reindex_graph(
x=x2,
neighbors=x2,
count=x2,
value_buffer=x3,
index_buffer=x3,
)

self.assertRaises(ValueError, test_reindex_0_result)

def test_heter_reindex_result(self):
paddle.disable_static()
x = paddle.to_tensor(self.x)
Expand Down