Skip to content

Commit

Permalink
[Misc] Black auto fix. (dmlc#4640)
Browse files Browse the repository at this point in the history
* auto fix

* add more

* sort

Co-authored-by: Steve <[email protected]>
  • Loading branch information
frozenbugs and Steve authored Sep 26, 2022
1 parent 23d0905 commit d78a3a4
Show file tree
Hide file tree
Showing 45 changed files with 978 additions and 658 deletions.
15 changes: 8 additions & 7 deletions benchmarks/benchmarks/api/bench_add_self_loop.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import time
import dgl
import torch

import numpy as np
import dgl.function as fn
import torch

import dgl
import dgl.function as fn

from .. import utils


@utils.benchmark('time')
@utils.parametrize('graph_name', ['cora', 'livejournal'])
@utils.parametrize('format', ['coo'])
@utils.benchmark("time")
@utils.parametrize("graph_name", ["cora", "livejournal"])
@utils.parametrize("format", ["coo"])
def track_time(graph_name, format):
device = utils.get_bench_device()
graph = utils.get_graph(graph_name, format)
Expand All @@ -21,7 +22,7 @@ def track_time(graph_name, format):
g = graph.add_self_loop()

# timing

with utils.Timer() as t:
for i in range(3):
edges = graph.add_self_loop()
Expand Down
11 changes: 7 additions & 4 deletions benchmarks/benchmarks/api/bench_batch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import time
import dgl

import torch

import dgl

from .. import utils

@utils.benchmark('time')
@utils.parametrize('batch_size', [4, 32, 256, 1024])

@utils.benchmark("time")
@utils.parametrize("batch_size", [4, 32, 256, 1024])
def track_time(batch_size):
device = utils.get_bench_device()
ds = dgl.data.QM7bDataset()
Expand All @@ -20,7 +23,7 @@ def track_time(batch_size):
g = dgl.batch(graphs)

# timing

with utils.Timer() as t:
for i in range(100):
g = dgl.batch(graphs)
Expand Down
27 changes: 15 additions & 12 deletions benchmarks/benchmarks/api/bench_builtin_apply_edges.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import time
import dgl
import torch

import numpy as np
import torch

import dgl
import dgl.function as fn

from .. import utils


@utils.benchmark('time', timeout=600)
@utils.parametrize('graph_name', ['cora', 'ogbn-arxiv'])
@utils.parametrize('format', ['coo', 'csr'])
@utils.parametrize('feat_size', [8, 128, 512])
@utils.parametrize('reduce_type', ['u->e', 'u+v'])
@utils.benchmark("time", timeout=600)
@utils.parametrize("graph_name", ["cora", "ogbn-arxiv"])
@utils.parametrize("format", ["coo", "csr"])
@utils.parametrize("feat_size", [8, 128, 512])
@utils.parametrize("reduce_type", ["u->e", "u+v"])
def track_time(graph_name, format, feat_size, reduce_type):
device = utils.get_bench_device()
graph = utils.get_graph(graph_name, format)
graph = graph.to(device)
graph.ndata['h'] = torch.randn(
(graph.num_nodes(), feat_size), device=device)
graph.ndata["h"] = torch.randn(
(graph.num_nodes(), feat_size), device=device
)

reduce_builtin_dict = {
'u->e': fn.copy_u('h', 'x'),
'u+v': fn.u_add_v('h', 'h', 'x'),
"u->e": fn.copy_u("h", "x"),
"u+v": fn.u_add_v("h", "h", "x"),
}

# dry run
for i in range(3):
graph.apply_edges(reduce_builtin_dict[reduce_type])

# timing

with utils.Timer() as t:
for i in range(10):
graph.apply_edges(reduce_builtin_dict[reduce_type])
Expand Down
46 changes: 26 additions & 20 deletions benchmarks/benchmarks/api/bench_builtin_apply_edges_hetero.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import time
import dgl
import torch

import numpy as np
import torch

import dgl
import dgl.function as fn

from .. import utils


@utils.benchmark('time', timeout=600)
@utils.parametrize('num_relations', [5, 50, 500])
@utils.parametrize('format', ['coo', 'csr'])
@utils.parametrize('feat_size', [8, 128, 512])
@utils.parametrize('reduce_type', ['u->e']) #, 'e->u'])

def track_time( num_relations, format, feat_size, reduce_type):
@utils.benchmark("time", timeout=600)
@utils.parametrize("num_relations", [5, 50, 500])
@utils.parametrize("format", ["coo", "csr"])
@utils.parametrize("feat_size", [8, 128, 512])
@utils.parametrize("reduce_type", ["u->e"]) # , 'e->u'])
def track_time(num_relations, format, feat_size, reduce_type):
device = utils.get_bench_device()
dd = {}
candidate_edges = [dgl.data.CoraGraphDataset(verbose=False)[0].edges(), dgl.data.PubmedGraphDataset(verbose=False)[
0].edges(), dgl.data.CiteseerGraphDataset(verbose=False)[0].edges()]
candidate_edges = [
dgl.data.CoraGraphDataset(verbose=False)[0].edges(),
dgl.data.PubmedGraphDataset(verbose=False)[0].edges(),
dgl.data.CiteseerGraphDataset(verbose=False)[0].edges(),
]
for i in range(num_relations):
dd[('n1', 'e_{}'.format(i), 'n2')] = candidate_edges[i %
len(candidate_edges)]
dd[("n1", "e_{}".format(i), "n2")] = candidate_edges[
i % len(candidate_edges)
]
graph = dgl.heterograph(dd)

graph = graph.to(device)
graph.nodes['n1'].data['h'] = torch.randn(
(graph.num_nodes('n1'), feat_size), device=device)
graph.nodes['n2'].data['h'] = torch.randn(
(graph.num_nodes('n2'), feat_size), device=device)

graph.nodes["n1"].data["h"] = torch.randn(
(graph.num_nodes("n1"), feat_size), device=device
)
graph.nodes["n2"].data["h"] = torch.randn(
(graph.num_nodes("n2"), feat_size), device=device
)

reduce_builtin_dict = {
'u->e': fn.copy_u('h', 'x'),
"u->e": fn.copy_u("h", "x"),
# 'e->u': fn.copy_e('h', 'x'),
}

Expand All @@ -40,7 +46,7 @@ def track_time( num_relations, format, feat_size, reduce_type):
graph.apply_edges(reduce_builtin_dict[reduce_type])

# timing

with utils.Timer() as t:
for i in range(10):
graph.apply_edges(reduce_builtin_dict[reduce_type])
Expand Down
44 changes: 24 additions & 20 deletions benchmarks/benchmarks/api/bench_builtin_update_all_coo.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
import time
import dgl
import torch

import numpy as np
import torch

import dgl
import dgl.function as fn

from .. import utils


@utils.benchmark('time', timeout=600)
@utils.parametrize('graph_name', ['ogbn-arxiv'])
@utils.parametrize('format', ['coo'])
@utils.parametrize('feat_size', [4, 32, 256])
@utils.parametrize('msg_type', ['copy_u', 'u_mul_e'])
@utils.parametrize('reduce_type', ['sum', 'mean', 'max'])
@utils.benchmark("time", timeout=600)
@utils.parametrize("graph_name", ["ogbn-arxiv"])
@utils.parametrize("format", ["coo"])
@utils.parametrize("feat_size", [4, 32, 256])
@utils.parametrize("msg_type", ["copy_u", "u_mul_e"])
@utils.parametrize("reduce_type", ["sum", "mean", "max"])
def track_time(graph_name, format, feat_size, msg_type, reduce_type):
device = utils.get_bench_device()
graph = utils.get_graph(graph_name, format)
graph = graph.to(device)
graph.ndata['h'] = torch.randn(
(graph.num_nodes(), feat_size), device=device)
graph.edata['e'] = torch.randn(
(graph.num_edges(), 1), device=device)
graph.ndata["h"] = torch.randn(
(graph.num_nodes(), feat_size), device=device
)
graph.edata["e"] = torch.randn((graph.num_edges(), 1), device=device)

msg_builtin_dict = {
'copy_u': fn.copy_u('h', 'x'),
'u_mul_e': fn.u_mul_e('h', 'e', 'x'),
"copy_u": fn.copy_u("h", "x"),
"u_mul_e": fn.u_mul_e("h", "e", "x"),
}

reduce_builtin_dict = {
'sum': fn.sum('x', 'h_new'),
'mean': fn.mean('x', 'h_new'),
'max': fn.max('x', 'h_new'),
"sum": fn.sum("x", "h_new"),
"mean": fn.mean("x", "h_new"),
"max": fn.max("x", "h_new"),
}

# dry run
graph.update_all(msg_builtin_dict[msg_type],
reduce_builtin_dict[reduce_type])
graph.update_all(
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type]
)

# timing

with utils.Timer() as t:
for i in range(3):
graph.update_all(
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type])
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type]
)

return t.elapsed_secs / 3
46 changes: 25 additions & 21 deletions benchmarks/benchmarks/api/bench_builtin_update_all_csc.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
import time
import dgl
import torch

import numpy as np
import torch

import dgl
import dgl.function as fn

from .. import utils


@utils.benchmark('time', timeout=600)
@utils.parametrize('graph_name', ['ogbn-arxiv', 'reddit', 'ogbn-proteins'])
@utils.parametrize('format', ['csc'])
@utils.parametrize('feat_size', [4, 32, 256])
@utils.parametrize('msg_type', ['copy_u', 'u_mul_e'])
@utils.parametrize('reduce_type', ['sum', 'mean', 'max'])
@utils.benchmark("time", timeout=600)
@utils.parametrize("graph_name", ["ogbn-arxiv", "reddit", "ogbn-proteins"])
@utils.parametrize("format", ["csc"])
@utils.parametrize("feat_size", [4, 32, 256])
@utils.parametrize("msg_type", ["copy_u", "u_mul_e"])
@utils.parametrize("reduce_type", ["sum", "mean", "max"])
def track_time(graph_name, format, feat_size, msg_type, reduce_type):
device = utils.get_bench_device()
graph = utils.get_graph(graph_name, format)
graph = graph.to(device)
graph.ndata['h'] = torch.randn(
(graph.num_nodes(), feat_size), device=device)
graph.edata['e'] = torch.randn(
(graph.num_edges(), 1), device=device)
graph.ndata["h"] = torch.randn(
(graph.num_nodes(), feat_size), device=device
)
graph.edata["e"] = torch.randn((graph.num_edges(), 1), device=device)

msg_builtin_dict = {
'copy_u': fn.copy_u('h', 'x'),
'u_mul_e': fn.u_mul_e('h', 'e', 'x'),
"copy_u": fn.copy_u("h", "x"),
"u_mul_e": fn.u_mul_e("h", "e", "x"),
}

reduce_builtin_dict = {
'sum': fn.sum('x', 'h_new'),
'mean': fn.mean('x', 'h_new'),
'max': fn.max('x', 'h_new'),
"sum": fn.sum("x", "h_new"),
"mean": fn.mean("x", "h_new"),
"max": fn.max("x", "h_new"),
}

# dry run

for i in range(3):
graph.update_all(msg_builtin_dict[msg_type],
reduce_builtin_dict[reduce_type])
graph.update_all(
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type]
)

# timing

with utils.Timer() as t:
for i in range(10):
graph.update_all(
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type])
msg_builtin_dict[msg_type], reduce_builtin_dict[reduce_type]
)

return t.elapsed_secs / 10
26 changes: 16 additions & 10 deletions benchmarks/benchmarks/api/bench_edge_ids.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import time
import dgl
import torch

import numpy as np
import torch

import dgl

from .. import utils


# edge_ids is not supported on cuda
# @utils.skip_if_gpu()
@utils.benchmark('time', timeout=1200)
@utils.parametrize_cpu('graph_name', ['cora', 'livejournal', 'friendster'])
@utils.parametrize_gpu('graph_name', ['cora', 'livejournal'])
@utils.parametrize('format', ['coo', 'csr', 'csc'])
@utils.parametrize('fraction', [0.01, 0.1])
@utils.parametrize('return_uv', [True, False])
@utils.benchmark("time", timeout=1200)
@utils.parametrize_cpu("graph_name", ["cora", "livejournal", "friendster"])
@utils.parametrize_gpu("graph_name", ["cora", "livejournal"])
@utils.parametrize("format", ["coo", "csr", "csc"])
@utils.parametrize("fraction", [0.01, 0.1])
@utils.parametrize("return_uv", [True, False])
def track_time(graph_name, format, fraction, return_uv):
device = utils.get_bench_device()
graph = utils.get_graph(graph_name, format)
coo_graph = utils.get_graph(graph_name, 'coo')
coo_graph = utils.get_graph(graph_name, "coo")
graph = graph.to(device)
eids = np.random.choice(
np.arange(graph.num_edges(), dtype=np.int64), int(graph.num_edges()*fraction))
np.arange(graph.num_edges(), dtype=np.int64),
int(graph.num_edges() * fraction),
)
eids = torch.tensor(eids, device="cpu", dtype=torch.int64)
u, v = coo_graph.find_edges(eids)
del coo_graph, eids
Expand Down
Loading

0 comments on commit d78a3a4

Please sign in to comment.