forked from quiver-team/torch-quiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_feature.py
140 lines (129 loc) · 5.41 KB
/
bench_feature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import torch
from ogb.nodeproppred import PygNodePropPredDataset
from torch_geometric.datasets import Reddit
from torch_geometric.loader import NeighborSampler
import time
import numpy as np
import os.path as osp
import quiver
def bench_on_ogbproduct():
print("=" * 20 + "OGBn-Product" + "=" * 20)
root = "/data/data/products"
dataset = PygNodePropPredDataset('ogbn-products', root)
train_idx = dataset.get_idx_split()["train"]
train_loader = torch.utils.data.DataLoader(train_idx,
batch_size=1024,
pin_memory=True,
shuffle=True)
csr_topo = quiver.CSRTopo(dataset[0].edge_index)
quiver_sampler = quiver.pyg.GraphSageSampler(csr_topo, [15, 10, 5],
device=0,
mode="UVA")
quiver_feature = quiver.Feature(rank=0,
device_list=[0, 1],
device_cache_size="200M",
cache_policy="device_replicate",
csr_topo=csr_topo)
feature = torch.zeros(dataset[0].x.shape)
feature[:] = dataset[0].x
quiver_feature.from_cpu_tensor(feature)
accessed_feature_size = 0
feature_time = 0
for seeds in train_loader:
nid, _, _ = quiver_sampler.sample(seeds)
torch.cuda.synchronize()
feature_start = time.time()
res = quiver_feature[nid]
torch.cuda.synchronize()
feature_time += time.time() - feature_start
accessed_feature_size += res.numel() * 4
torch.cuda.synchronize()
print(
f"Feature Collection Throughput {accessed_feature_size / feature_time / 1024 / 1024 / 1024} GB/s"
)
def bench_on_ogbproduct_cpu():
print("=" * 20 + "OGBn-Product CPU" + "=" * 20)
root = "/data/data/products"
dataset = PygNodePropPredDataset('ogbn-products', root)
feature = dataset[0].x
train_idx = dataset.get_idx_split()["train"]
train_loader = NeighborSampler(dataset[0].edge_index,
node_idx=train_idx,
sizes=[15, 10, 5],
batch_size=1024,
shuffle=True)
accessed_feature_size = 0
feature_time = 0
for batch_size, n_id, adjs in train_loader:
feature_start = time.time()
res = feature[n_id].to(0)
torch.cuda.synchronize()
feature_time += time.time() - feature_start
accessed_feature_size += res.numel() * 4
torch.cuda.synchronize()
print(
f"Feature Collection Throughput {accessed_feature_size / feature_time / 1024 / 1024 / 1024} GB/s"
)
def bench_on_reddit():
print("=" * 20 + "Reddit" + "=" * 20)
dataset = Reddit('/data/data/Reddit')
train_mask = dataset[0].train_mask
train_idx = train_mask.nonzero(as_tuple=False).view(-1)
train_loader = torch.utils.data.DataLoader(train_idx,
batch_size=1024,
pin_memory=True,
shuffle=True)
csr_topo = quiver.CSRTopo(dataset[0].edge_index)
quiver_sampler = quiver.pyg.GraphSageSampler(csr_topo, [25, 10],
device=0,
mode="UVA")
quiver_feature = quiver.Feature(rank=0,
device_list=[0, 1],
device_cache_size="110M",
cache_policy="device_replicate",
csr_topo=csr_topo)
quiver_feature.from_cpu_tensor(dataset[0].x)
accessed_feature_size = 0
feature_time = 0
for seeds in train_loader:
nid, _, _ = quiver_sampler.sample(seeds)
torch.cuda.synchronize()
feature_start = time.time()
res = quiver_feature[nid]
torch.cuda.synchronize()
feature_time += time.time() - feature_start
accessed_feature_size += res.numel() * 4
torch.cuda.synchronize()
print(
f"Feature Collection Throughput {accessed_feature_size / feature_time / 1024 / 1024 / 1024} GB/s"
)
def bench_on_reddit_cpu():
print("=" * 20 + "Reddit CPU" + "=" * 20)
root = '/data/data/Reddit'
dataset = Reddit(root)
feature = dataset[0].x
train_mask = dataset[0].train_mask
train_idx = train_mask.nonzero(as_tuple=False).view(-1)
train_loader = NeighborSampler(dataset[0].edge_index,
node_idx=train_idx,
sizes=[25, 10],
batch_size=1024,
shuffle=True)
accessed_feature_size = 0
feature_time = 0
for batch_size, n_id, adjs in train_loader:
feature_start = time.time()
res = feature[n_id].to(0)
torch.cuda.synchronize()
feature_time += time.time() - feature_start
accessed_feature_size += res.numel() * 4
torch.cuda.synchronize()
print(
f"Feature Collection Throughput {accessed_feature_size / feature_time / 1024 / 1024 / 1024} GB/s"
)
if __name__ == "__main__":
quiver.init_p2p([0, 1])
#bench_on_ogbproduct()
#bench_on_ogbproduct_cpu()
bench_on_reddit()
#bench_on_reddit_cpu()