未验证 提交 c31ffbe8 编写于 作者: Z Zero Rains 提交者: GitHub

【Hackathon No.31】 Fix Null pointer bug for Case4:paddle.incubate.graph_khop_sampler (#51784)

* fix divide zero bug for softmax_with_cross_entropy

* change the single test way

* fix the null pointer in graph_khop_sampler

* fix the case5
上级 01eeba5e
......@@ -423,6 +423,31 @@ class GraphKhopSamplerOpCUDAKernel : public framework::OpKernel<T> {
std::vector<int> sample_sizes = ctx.Attr<std::vector<int>>("sample_sizes");
bool return_eids = ctx.Attr<bool>("return_eids");
auto row_dims = src->dims();
auto row_dims_lens = row_dims.size();
auto col_dims = dst_count->dims();
auto col_dims_lens = col_dims.size();
auto x_dims = vertices->dims();
auto x_dims_lens = x_dims.size();
for (int i = 0; i < row_dims_lens; i++) {
PADDLE_ENFORCE_NE(
row_dims[i],
0,
phi::errors::InvalidArgument("The size of Row(X) should not be 0."));
}
for (int i = 0; i < col_dims_lens; i++) {
PADDLE_ENFORCE_NE(col_dims[i],
0,
phi::errors::InvalidArgument(
"The size of Col_Ptr(X) should not be 0."));
}
for (int i = 0; i < x_dims_lens; i++) {
PADDLE_ENFORCE_NE(x_dims[i],
0,
phi::errors::InvalidArgument(
"The size of Input_Node(X) should not be 0."));
}
const T* src_data = src->data<T>();
const T* dst_count_data = dst_count->data<T>();
const T* p_vertices = vertices->data<T>();
......
......@@ -199,6 +199,31 @@ class GraphKhopSamplerOpKernel : public framework::OpKernel<T> {
auto* src = ctx.Input<phi::DenseTensor>("Row");
auto* dst_count = ctx.Input<phi::DenseTensor>("Col_Ptr");
auto* vertices = ctx.Input<phi::DenseTensor>("X");
auto row_dims = src->dims();
auto row_dims_lens = row_dims.size();
auto col_dims = dst_count->dims();
auto col_dims_lens = col_dims.size();
auto x_dims = vertices->dims();
auto x_dims_lens = x_dims.size();
for (int i = 0; i < row_dims_lens; i++) {
PADDLE_ENFORCE_NE(
row_dims[i],
0,
phi::errors::InvalidArgument("The size of Row(X) should not be 0."));
}
for (int i = 0; i < col_dims_lens; i++) {
PADDLE_ENFORCE_NE(col_dims[i],
0,
phi::errors::InvalidArgument(
"The size of Col_Ptr(X) should not be 0."));
}
for (int i = 0; i < x_dims_lens; i++) {
PADDLE_ENFORCE_NE(x_dims[i],
0,
phi::errors::InvalidArgument(
"The size of Input_Node(X) should not be 0."));
}
std::vector<int> sample_sizes = ctx.Attr<std::vector<int>>("sample_sizes");
bool return_eids = ctx.Attr<bool>("return_eids");
......
......@@ -259,6 +259,36 @@ class TestGraphKhopSampler(unittest.TestCase):
in_neighbors = np.isin(edge_src_n, self.dst_src_dict[n])
self.assertTrue(np.sum(in_neighbors) == in_neighbors.shape[0])
def test_for_null_pointer_error(self):
def test_in_row():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor(np.reshape(array, [0]), dtype='int32')
y = paddle.to_tensor([10], dtype='int32')
layer = paddle.incubate.graph_khop_sampler(
row=x, colptr=x, input_nodes=y, sample_sizes=[0]
)
def test_in_col():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor([10], dtype='int32')
col = paddle.to_tensor(np.reshape(array, [0]), dtype='int32')
y = paddle.to_tensor([10], dtype='int32')
layer = paddle.incubate.graph_khop_sampler(
row=x, colptr=col, input_nodes=y, sample_sizes=[0]
)
def test_in_input_nodes():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor(np.reshape(array, [0]), dtype='int32')
y = paddle.to_tensor([10], dtype='int32')
layer = paddle.incubate.graph_khop_sampler(
row=y, colptr=y, input_nodes=x, sample_sizes=[0]
)
self.assertRaises(ValueError, test_in_row)
self.assertRaises(ValueError, test_in_col)
self.assertRaises(ValueError, test_in_input_nodes)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册