"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "9366c8f84bfe47099ff047272661786ebb54721d"
Unverified Commit dec8b49b authored by Minjie Wang's avatar Minjie Wang Committed by GitHub
Browse files

[Examples] Run all the examples (#623)

* all pytorch examples

* scan through mxnet examples

* change reddit data

* tweak numerical range for unittest

* fix ci

* fix ci

* fix

* add seed to workaround
parent 74e13eea
......@@ -23,6 +23,7 @@ endif()
# and add set(OPTION VALUE) to override these build options.
# Alernatively, use cmake -DOPTION=VALUE through command-line.
dgl_option(USE_CUDA "Build with CUDA" OFF)
dgl_option(USE_OPENMP "Build with OpenMP" ON)
dgl_option(BUILD_CPP_TEST "Build cpp unittest executables" OFF)
if(USE_CUDA)
......
......@@ -52,7 +52,7 @@ def main(args):
n_test_samples))
# create GCN model
g = DGLGraph(data.graph, readonly=True)
g = data.graph
g.ndata['features'] = features
g.ndata['labels'] = labels
......
......@@ -23,7 +23,6 @@ DGLBACKEND=mxnet python3 sse_batch.py --graph-file ../../data/5_5_csr.nd \
--lr 0.0005 \
--batch-size 1024 \
--use-spmv \
--dgl \
--num-parallel-subgraphs 32 \
--gpu 1 \
--num-feats 100 \
......@@ -38,7 +37,6 @@ DGLBACKEND=mxnet python3 sse_batch.py --dataset "pubmed" \
--n-epochs 1000 \
--lr 0.001 \
--batch-size 30 \
--dgl \
--use-spmv \
--neigh-expand 8 \
--n-hidden 16
......
......@@ -21,7 +21,7 @@ The script will download the [SST dataset] (http://nlp.stanford.edu/sentiment/in
## Usage
```
python3 train.py --gpu 0
DGLBACKEND=mxnet python3 train.py --gpu 0
```
## Speed Test
......
......@@ -33,7 +33,7 @@ class GraphPropagation(nn.Module):
self.g.ndata['h'] = h
if self.edge_drop:
# performing edge dropout
ed = self.edge_drop(torch.ones((self.g.number_of_edges(), 1)))
ed = self.edge_drop(torch.ones((self.g.number_of_edges(), 1), device=h.device))
self.g.edata['d'] = ed
self.g.update_all(fn.src_mul_edge(src='h', edge='d', out='m'),
fn.sum(msg='m', out='h'))
......
......@@ -4,7 +4,6 @@ import scipy.sparse as sp
import numpy as np
import dgl
import os, sys
from ..graph_index import create_graph_index
from .utils import download, extract_archive, get_download_dir, _get_dgl_url
......@@ -20,7 +19,7 @@ class RedditDataset(object):
extract_archive(zip_file_path, extract_dir)
# graph
coo_adj = sp.load_npz(os.path.join(extract_dir, "reddit{}_graph.npz".format(self_loop_str)))
self.graph = create_graph_index(coo_adj, readonly=True)
self.graph = dgl.DGLGraph(coo_adj, readonly=True)
# features and labels
reddit_data = np.load(os.path.join(extract_dir, "reddit_data.npz"))
self.features = reddit_data["feature"]
......
import dgl
import dgl.function as fn
import networkx as nx
import numpy as np
import backend as F
from itertools import product
np.random.seed(42)
def udf_copy_src(edges):
return {'m': edges.src['u']}
......@@ -36,21 +38,21 @@ def generate_feature(g, broadcast='none'):
nv = g.number_of_nodes()
ne = g.number_of_edges()
if broadcast == 'e':
u = F.randn((nv, D1, D2, D3))
e = F.randn((ne, D2, 1))
v = F.randn((nv, D1, D2, D3))
u = F.tensor(np.random.randn(nv, D1, D2, D3) + 1)
e = F.tensor(np.random.randn(ne, D2, 1) - 1)
v = F.tensor(np.random.randn(nv, D1, D2, D3))
elif broadcast == 'u':
u = F.randn((nv, D2, 1))
e = F.randn((ne, D1, D2, D3))
v = F.randn((nv, D1, D2, D3))
u = F.tensor(np.random.randn(nv, D2, 1) + 1)
e = F.tensor(np.random.randn(ne, D1, D2, D3) - 1)
v = F.tensor(np.random.randn(nv, D1, D2, D3))
elif broadcast == 'v':
u = F.randn((nv, D1, D2, D3))
e = F.randn((ne, D1, D2, D3))
v = F.randn((nv, D2, 1))
u = F.tensor(np.random.randn(nv, D1, D2, D3) + 1)
e = F.tensor(np.random.randn(ne, D1, D2, D3) - 1)
v = F.tensor(np.random.randn(nv, D2, 1))
else:
u = F.randn((nv, D1, D2, D3))
e = F.randn((ne, D1, D2, D3))
v = F.randn((nv, D1, D2, D3))
u = F.tensor(np.random.randn(nv, D1, D2, D3) + 1)
e = F.tensor(np.random.randn(ne, D1, D2, D3) - 1)
v = F.tensor(np.random.randn(nv, D1, D2, D3))
return u, v, e
......@@ -175,16 +177,10 @@ def test_all_binary_builtins():
with F.record_grad():
g.update_all(mfunc, rfunc)
r2 = g.ndata['r2']
F.backward(r2.sum())
F.backward(r2.sum(), F.tensor([1.]))
lhs_grad_2 = F.grad(target_feature_switch(g, lhs))
rhs_grad_2 = F.grad(target_feature_switch(g, rhs))
def _print_error(a, b):
print("Test {}_{}_{}_{} {}".
format(lhs, binary_op, rhs, reducer, broadcast))
print(a)
print(b)
if reducer == 'prod':
rtol = 1e-2
atol = 1e-2
......@@ -192,13 +188,23 @@ def test_all_binary_builtins():
rtol = 1e-4
atol = 1e-4
def _print_error(a, b):
print("ERROR: Test {}_{}_{}_{} {}".
format(lhs, binary_op, rhs, reducer, broadcast))
print(a, b)
for i, (x, y) in enumerate(zip(F.asnumpy(a).flatten(), F.asnumpy(b).flatten())):
if not np.allclose(x, y, rtol, atol):
print('@{} {} v.s. {}'.format(i, x, y))
if not F.allclose(r1, r2, rtol, atol):
_print_error(r1, r2)
assert F.allclose(r1, r2, rtol, atol)
if not F.allclose(rhs_grad_1, rhs_grad_2, rtol, atol):
if not F.allclose(lhs_grad_1, lhs_grad_2, rtol, atol):
print("left grad")
_print_error(lhs_grad_1, lhs_grad_2)
assert(F.allclose(lhs_grad_1, lhs_grad_2, rtol, atol))
if not F.allclose(rhs_grad_1, rhs_grad_2, rtol, atol):
print("right grad")
_print_error(rhs_grad_1, rhs_grad_2)
......@@ -224,7 +230,6 @@ def test_all_binary_builtins():
for broadcast in ["none", lhs, rhs]:
_test(g, lhs, rhs, binary_op, reducer)
if __name__ == '__main__':
test_copy_src_reduce()
test_copy_edge_reduce()
......
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