Unverified Commit b8a4b446 authored by Tianjun Xiao's avatar Tianjun Xiao Committed by GitHub
Browse files

[NN][Fix] fix some random test (#2031)


Co-authored-by: default avatarMinjie Wang <wmjlyjemaine@gmail.com>
parent 1f7b2195
...@@ -436,13 +436,14 @@ def test_sage_conv2(idtype): ...@@ -436,13 +436,14 @@ def test_sage_conv2(idtype):
assert h.shape[-1] == 2 assert h.shape[-1] == 2
assert h.shape[0] == 3 assert h.shape[0] == 3
def test_sgc_conv(): @parametrize_dtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_sgc_conv(g, idtype):
ctx = F.ctx() ctx = F.ctx()
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True) g = g.astype(idtype).to(ctx)
g = g.to(F.ctx())
# not cached # not cached
sgc = nn.SGConv(5, 10, 3) sgc = nn.SGConv(5, 10, 3)
feat = F.randn((100, 5)) feat = F.randn((g.number_of_nodes(), 5))
sgc = sgc.to(ctx) sgc = sgc.to(ctx)
h = sgc(g, feat) h = sgc(g, feat)
...@@ -456,12 +457,13 @@ def test_sgc_conv(): ...@@ -456,12 +457,13 @@ def test_sgc_conv():
assert F.allclose(h_0, h_1) assert F.allclose(h_0, h_1)
assert h_0.shape[-1] == 10 assert h_0.shape[-1] == 10
def test_appnp_conv(): @parametrize_dtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_appnp_conv(g, idtype):
ctx = F.ctx() ctx = F.ctx()
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True) g = g.astype(idtype).to(ctx)
g = g.to(F.ctx())
appnp = nn.APPNPConv(10, 0.1) appnp = nn.APPNPConv(10, 0.1)
feat = F.randn((100, 5)) feat = F.randn((g.number_of_nodes(), 5))
appnp = appnp.to(ctx) appnp = appnp.to(ctx)
h = appnp(g, feat) h = appnp(g, feat)
...@@ -519,13 +521,14 @@ def test_agnn_conv_bi(g, idtype): ...@@ -519,13 +521,14 @@ def test_agnn_conv_bi(g, idtype):
h = agnn(g, feat) h = agnn(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 5) assert h.shape == (g.number_of_dst_nodes(), 5)
def test_gated_graph_conv(): @parametrize_dtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_gated_graph_conv(g, idtype):
ctx = F.ctx() ctx = F.ctx()
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True) g = g.astype(idtype).to(ctx)
g = g.to(F.ctx())
ggconv = nn.GatedGraphConv(5, 10, 5, 3) ggconv = nn.GatedGraphConv(5, 10, 5, 3)
etypes = th.arange(g.number_of_edges()) % 3 etypes = th.arange(g.number_of_edges()) % 3
feat = F.randn((100, 5)) feat = F.randn((g.number_of_nodes(), 5))
ggconv = ggconv.to(ctx) ggconv = ggconv.to(ctx)
etypes = etypes.to(ctx) etypes = etypes.to(ctx)
...@@ -552,7 +555,6 @@ def test_nn_conv(g, idtype): ...@@ -552,7 +555,6 @@ def test_nn_conv(g, idtype):
def test_nn_conv_bi(g, idtype): def test_nn_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx()) g = g.astype(idtype).to(F.ctx())
ctx = F.ctx() ctx = F.ctx()
#g = dgl.bipartite(sp.sparse.random(50, 100, density=0.1))
edge_func = th.nn.Linear(4, 5 * 10) edge_func = th.nn.Linear(4, 5 * 10)
nnconv = nn.NNConv((5, 2), 10, edge_func, 'mean') nnconv = nn.NNConv((5, 2), 10, edge_func, 'mean')
feat = F.randn((g.number_of_src_nodes(), 5)) feat = F.randn((g.number_of_src_nodes(), 5))
...@@ -725,8 +727,10 @@ def test_sequential(): ...@@ -725,8 +727,10 @@ def test_sequential():
n_feat = net([g1, g2, g3], n_feat) n_feat = net([g1, g2, g3], n_feat)
assert n_feat.shape == (4, 4) assert n_feat.shape == (4, 4)
def test_atomic_conv(): @parametrize_dtype
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True).to(F.ctx()) @pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_atomic_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
aconv = nn.AtomicConv(interaction_cutoffs=F.tensor([12.0, 12.0]), aconv = nn.AtomicConv(interaction_cutoffs=F.tensor([12.0, 12.0]),
rbf_kernel_means=F.tensor([0.0, 2.0]), rbf_kernel_means=F.tensor([0.0, 2.0]),
rbf_kernel_scaling=F.tensor([4.0, 4.0]), rbf_kernel_scaling=F.tensor([4.0, 4.0]),
...@@ -736,15 +740,17 @@ def test_atomic_conv(): ...@@ -736,15 +740,17 @@ def test_atomic_conv():
if F.gpu_ctx(): if F.gpu_ctx():
aconv = aconv.to(ctx) aconv = aconv.to(ctx)
feat = F.randn((100, 1)) feat = F.randn((g.number_of_nodes(), 1))
dist = F.randn((g.number_of_edges(), 1)) dist = F.randn((g.number_of_edges(), 1))
h = aconv(g, feat, dist) h = aconv(g, feat, dist)
# current we only do shape check # current we only do shape check
assert h.shape[-1] == 4 assert h.shape[-1] == 4
def test_cf_conv(): @parametrize_dtype
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True).to(F.ctx()) @pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_cf_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
cfconv = nn.CFConv(node_in_feats=2, cfconv = nn.CFConv(node_in_feats=2,
edge_in_feats=3, edge_in_feats=3,
hidden_feats=2, hidden_feats=2,
...@@ -754,7 +760,7 @@ def test_cf_conv(): ...@@ -754,7 +760,7 @@ def test_cf_conv():
if F.gpu_ctx(): if F.gpu_ctx():
cfconv = cfconv.to(ctx) cfconv = cfconv.to(ctx)
node_feats = F.randn((100, 2)) node_feats = F.randn((g.number_of_nodes(), 2))
edge_feats = F.randn((g.number_of_edges(), 3)) edge_feats = F.randn((g.number_of_edges(), 3))
h = cfconv(g, node_feats, edge_feats) h = cfconv(g, node_feats, edge_feats)
# current we only do shape check # current we only do shape check
......
...@@ -313,12 +313,14 @@ def test_sage_conv_bi_empty(idtype, aggre_type): ...@@ -313,12 +313,14 @@ def test_sage_conv_bi_empty(idtype, aggre_type):
assert h.shape[-1] == 2 assert h.shape[-1] == 2
assert h.shape[0] == 3 assert h.shape[0] == 3
def test_sgc_conv(): @parametrize_dtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_sgc_conv(g, idtype):
ctx = F.ctx() ctx = F.ctx()
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True).to(F.ctx()) g = g.astype(idtype).to(ctx)
# not cached # not cached
sgc = nn.SGConv(5, 10, 3) sgc = nn.SGConv(5, 10, 3)
feat = F.randn((100, 5)) feat = F.randn((g.number_of_nodes(), 5))
h = sgc(g, feat) h = sgc(g, feat)
assert h.shape[-1] == 10 assert h.shape[-1] == 10
...@@ -330,10 +332,13 @@ def test_sgc_conv(): ...@@ -330,10 +332,13 @@ def test_sgc_conv():
assert F.allclose(h_0, h_1) assert F.allclose(h_0, h_1)
assert h_0.shape[-1] == 10 assert h_0.shape[-1] == 10
def test_appnp_conv(): @parametrize_dtype
g = dgl.DGLGraph(sp.sparse.random(100, 100, density=0.1), readonly=True).to(F.ctx()) @pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_appnp_conv(g, idtype):
ctx = F.ctx()
g = g.astype(idtype).to(ctx)
appnp = nn.APPNPConv(10, 0.1) appnp = nn.APPNPConv(10, 0.1)
feat = F.randn((100, 5)) feat = F.randn((g.number_of_nodes(), 5))
h = appnp(g, feat) h = appnp(g, feat)
assert h.shape[-1] == 5 assert h.shape[-1] == 5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment