-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
appnp.py
61 lines (51 loc) · 2.41 KB
/
appnp.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
import argparse
import torch
import torch.nn.functional as F
from citation import get_planetoid_dataset, random_planetoid_splits, run
from torch.nn import Linear
from torch_geometric.nn import APPNP
from torch_geometric.profile import rename_profile_file
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', type=str, required=True)
parser.add_argument('--random_splits', action='store_true')
parser.add_argument('--runs', type=int, default=100)
parser.add_argument('--epochs', type=int, default=200)
parser.add_argument('--lr', type=float, default=0.01)
parser.add_argument('--weight_decay', type=float, default=0.0005)
parser.add_argument('--early_stopping', type=int, default=10)
parser.add_argument('--hidden', type=int, default=64)
parser.add_argument('--dropout', type=float, default=0.5)
parser.add_argument('--no_normalize_features', action='store_true')
parser.add_argument('--K', type=int, default=10)
parser.add_argument('--alpha', type=float, default=0.1)
parser.add_argument('--inference', action='store_true')
parser.add_argument('--profile', action='store_true')
parser.add_argument('--bf16', action='store_true')
parser.add_argument('--compile', action='store_true')
args = parser.parse_args()
class Net(torch.nn.Module):
def __init__(self, dataset):
super().__init__()
self.lin1 = Linear(dataset.num_features, args.hidden)
self.lin2 = Linear(args.hidden, dataset.num_classes)
self.prop1 = APPNP(args.K, args.alpha)
def reset_parameters(self):
self.lin1.reset_parameters()
self.lin2.reset_parameters()
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = F.dropout(x, p=args.dropout, training=self.training)
x = F.relu(self.lin1(x))
x = F.dropout(x, p=args.dropout, training=self.training)
x = self.lin2(x)
x = self.prop1(x, edge_index)
return F.log_softmax(x, dim=1)
dataset = get_planetoid_dataset(args.dataset, not args.no_normalize_features)
permute_masks = random_planetoid_splits if args.random_splits else None
run(dataset, Net(dataset), args.runs, args.epochs, args.lr, args.weight_decay,
args.early_stopping, args.inference, args.profile, args.bf16, args.compile,
permute_masks)
if args.profile:
rename_profile_file('citation', APPNP.__name__, args.dataset,
str(args.random_splits),
'inference' if args.inference else 'train')