Skip to content

Commit

Permalink
[Dataset] Update ogb arxiv & Fix epochs (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
cenyk1230 authored Oct 28, 2021
1 parent 0a64b59 commit e34f305
Show file tree
Hide file tree
Showing 53 changed files with 507 additions and 1,207 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ from cogdl import experiment
experiment(dataset="cora", model="gcn")

# set other hyper-parameters
experiment(dataset="cora", model="gcn", hidden_size=32, max_epoch=200)
experiment(dataset="cora", model="gcn", hidden_size=32, epochs=200)

# run over multiple models on different seeds
experiment(dataset="cora", model=["gcn", "gat"], seed=[1, 2])
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ from cogdl import experiment
experiment(dataset="cora", model="gcn")

# set other hyper-parameters
experiment(dataset="cora", model="gcn", hidden_size=32, max_epoch=200)
experiment(dataset="cora", model="gcn", hidden_size=32, epochs=200)

# run over multiple models on different seeds
experiment(dataset="cora", model=["gcn", "gat"], seed=[1, 2])
Expand Down
38 changes: 19 additions & 19 deletions cogdl/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"chebyshev": {"general": {}},
"dropedge_gcn": {"general": {}},
"gat": {
"general": {"lr": 0.005, "max_epoch": 1000},
"general": {"lr": 0.005, "epochs": 1000},
"citeseer": {"weight_decay": 0.001},
"pubmed": {"weight_decay": 0.001},
"ppi-large": {
Expand All @@ -24,7 +24,7 @@
"hidden_size": 2048,
"num_layers": 2,
"dropout": 0.3,
"max_epoch": 7000,
"epochs": 7000,
# 78.04
},
"flickr": {
Expand All @@ -39,7 +39,7 @@
},
"gcnii": {
"general": {
"max_epoch": 1000,
"epochs": 1000,
"dropout": 0.5,
"wd1": 0.001,
"wd2": 5e-4,
Expand All @@ -54,7 +54,7 @@
"hidden_size": 256,
"lr": 0.001,
"patience": 200,
"max_epoch": 2000,
"epochs": 2000,
"lmbda": 0.6,
"dropout": 0.7,
},
Expand All @@ -73,7 +73,7 @@
"wd2": 0,
"lr": 0.001,
"residual": True,
"max_epoch": 1000,
"epochs": 1000,
"lmbda": 1.0,
# 96.42
},
Expand All @@ -93,7 +93,7 @@
},
"grand": {
"general": {
"max_epoch": 1000,
"epochs": 1000,
},
"cora": {
"order": 8,
Expand Down Expand Up @@ -139,7 +139,7 @@
"sgcpn": {
"general": {
"lr": 0.005,
"max_epoch": 1000,
"epochs": 1000,
"patience": 1000,
"norm_mode": "PN",
"norm_scale": 10,
Expand All @@ -157,14 +157,14 @@
"srgcn": {
"general": {
"lr": 0.005,
"max_epoch": 1000,
"epochs": 1000,
},
"cora": {"dropout": 0.6},
"citeseer": {"dropout": 0.6},
},
"unet": {
"general": {
"max_epoch": 1000,
"epochs": 1000,
"n_dropout": 0.90,
"adj_dropout": 0.05,
"hidden_size": 128,
Expand All @@ -182,7 +182,7 @@
"dropout": 0.3,
"num_layers": 2,
"hidden_size": 256,
"max_epoch": 1000,
"epochs": 1000,
"num_iterations": 4,
"alpha": 0.5,
# 0.5227
Expand All @@ -193,7 +193,7 @@
"alpha": 0.1087,
"num_iterations": 7,
"num_layers": 2,
"max_epoch": 1000,
"epochs": 1000,
"hidden_size": 32,
"dropout": 0.8185,
#
Expand All @@ -206,7 +206,7 @@
"alpha": 0.171,
"weight_decay": 0.0004117,
"num_layers": 2,
"max_epoch": 1000,
"epochs": 1000,
# 0.7199
},
"pubmed": {
Expand All @@ -215,7 +215,7 @@
"dropout": 0.3766,
"alpha": 0.1201,
"weight_decay": 0.0002754,
"max_epoch": 1000,
"epochs": 1000,
"lr": 0.001,
},
"reddit": {
Expand Down Expand Up @@ -289,7 +289,7 @@
"general": {
"hidden_size": 128,
"lr": 0.001,
"max_epoch": 500,
"epochs": 500,
"hidden_size1": 1000,
"hidden_size2": 128,
"noise": 0.2,
Expand Down Expand Up @@ -342,7 +342,7 @@
"grace": {
"general": {
"weight_decay": 0,
"max_epoch": 1000,
"epochs": 1000,
"patience": 20,
},
"cora": {
Expand All @@ -351,7 +351,7 @@
"tau": 0.4,
"drop_feature_rates": [0.3, 0.4],
"drop_edge_rates": [0.2, 0.4],
"max_epoch": 200,
"epochs": 200,
"hidden_size": 128,
"proj_hidden_size": 128,
},
Expand All @@ -378,7 +378,7 @@
"unsup_graphsage": {
"lr": 0.001,
"weight_decay": 0,
"max_epoch": 3000,
"epochs": 3000,
},
"revgcn": {
"general": {},
Expand Down Expand Up @@ -417,7 +417,7 @@
},
"mutag": {
"num_layers": 1,
"epoch": 20,
"epochs": 20,
},
"imdb-b": {"degree_feature": True},
"imdb-m": {"degree_feature": True},
Expand Down Expand Up @@ -449,7 +449,7 @@
"nci1": {
"lr": 0.001,
"window_size": 8,
"epoch": 10,
"epochs": 10,
"iteration": 4,
},
"reddit-b": {
Expand Down
5 changes: 4 additions & 1 deletion cogdl/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def num_graphs(self):
return 1

def __repr__(self): # pragma: no cover
return "{}({})".format(self.__class__.__name__, len(self))
return "{}".format(self.__class__.__name__)


class MultiGraphDataset(Dataset):
Expand Down Expand Up @@ -268,3 +268,6 @@ def __getitem__(self, item):

def __len__(self):
return len(self.data)

def __repr__(self): # pragma: no cover
return "{}({})".format(self.__class__.__name__, len(self))
13 changes: 1 addition & 12 deletions cogdl/datasets/ogb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def process(self):
name = self.name.replace("_", "-")
dataset = NodePropPredDataset(name, self.root)
graph, y = dataset[0]
x = torch.tensor(graph["node_feat"]) if graph["node_feat"] is not None else None
x = torch.tensor(graph["node_feat"]).contiguous() if graph["node_feat"] is not None else None
y = torch.tensor(y.squeeze())
row, col = graph["edge_index"][0], graph["edge_index"][1]
row = torch.from_numpy(row)
Expand Down Expand Up @@ -75,17 +75,6 @@ def __init__(self, data_path="data"):
dataset = "ogbn-arxiv"
super(OGBArxivDataset, self).__init__(data_path, dataset)

def get_evaluator(self):
evaluator = NodeEvaluator(name="ogbn-arxiv")

def wrap(y_pred, y_true):
y_pred = y_pred.argmax(dim=-1, keepdim=True)
y_true = y_true.view(-1, 1)
input_dict = {"y_true": y_true, "y_pred": y_pred}
return evaluator.eval(input_dict)["acc"]

return wrap


class OGBProductsDataset(OGBNDataset):
def __init__(self, data_path="data"):
Expand Down
12 changes: 10 additions & 2 deletions cogdl/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import inspect
from collections import defaultdict, namedtuple
import warnings

import torch
import torch.nn as nn
Expand Down Expand Up @@ -177,7 +178,7 @@ def train(args): # noqa: C901
lr=args.lr,
weight_decay=args.weight_decay,
n_warmup_steps=args.n_warmup_steps,
max_epoch=args.max_epoch,
epochs=args.epochs,
batch_size=args.batch_size if hasattr(args, "batch_size") else 0,
)

Expand All @@ -194,7 +195,7 @@ def train(args): # noqa: C901

# setup controller
trainer = Trainer(
max_epoch=args.max_epoch,
epochs=args.epochs,
device_ids=args.devices,
cpu=args.cpu,
save_emb_path=args.save_emb_path,
Expand Down Expand Up @@ -285,9 +286,16 @@ def experiment(dataset, model, **kwargs):
for key, value in kwargs.items():
if key != "args":
args.__setattr__(key, value)
if isinstance(model[0], nn.Module):
args.model = [x.model_name for x in model]
print(args)
args.dataset = dataset
args.model = model

if args.max_epoch is not None:
warnings.warn("The max_epoch is deprecated and will be removed in the future, please use epochs instead!")
args.epochs = args.max_epoch

if "search_space" in kwargs:
return auto_experiment(args)

Expand Down
12 changes: 6 additions & 6 deletions cogdl/models/emb/dgk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeepGraphKernel(BaseModel):
window (int) : The actual context size which is considered in language model.
sampling_rate (float) : Parameter in word2vec.
iteration (int) : The number of iteration in WL method.
epoch (int) : The number of training iteration.
epochs (int) : The number of training iteration.
alpha (float) : The learning rate of word2vec.
"""

Expand All @@ -29,13 +29,13 @@ def add_args(parser):
parser.add_argument("--min-count", type=int, default=1)
parser.add_argument("--sampling", type=float, default=0.0001)
parser.add_argument("--iteration", type=int, default=2)
parser.add_argument("--epoch", type=int, default=20)
parser.add_argument("--epochs", type=int, default=20)
parser.add_argument("--alpha", type=float, default=0.01)

@classmethod
def build_model_from_args(cls, args):
return cls(
args.hidden_size, args.min_count, args.window_size, args.sampling, args.iteration, args.epoch, args.alpha
args.hidden_size, args.min_count, args.window_size, args.sampling, args.iteration, args.epochs, args.alpha
)

@staticmethod
Expand Down Expand Up @@ -67,7 +67,7 @@ def wl_iterations(graph, features, rounds):
features = new_feats
return wl_features

def __init__(self, hidden_dim, min_count, window_size, sampling_rate, rounds, epoch, alpha, n_workers=4):
def __init__(self, hidden_dim, min_count, window_size, sampling_rate, rounds, epochs, alpha, n_workers=4):
super(DeepGraphKernel, self).__init__()
self.hidden_dim = hidden_dim
self.min_count = min_count
Expand All @@ -77,7 +77,7 @@ def __init__(self, hidden_dim, min_count, window_size, sampling_rate, rounds, ep
self.rounds = rounds
self.model = None
self.gl_collections = None
self.epoch = epoch
self.epochs = epochs
self.alpha = alpha

def forward(self, graphs, **kwargs):
Expand All @@ -93,7 +93,7 @@ def forward(self, graphs, **kwargs):
min_count=self.min_count,
sample=self.sampling_rate,
workers=self.n_workers,
iter=self.epoch,
iter=self.epochs,
alpha=self.alpha,
)
vectors = np.asarray([model.wv[str(node)] for node in model.wv.index2word])
Expand Down
10 changes: 5 additions & 5 deletions cogdl/models/emb/dngr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DNGR(BaseModel):
noise (float) : Denoise rate of DAE.
alpha (float) : Parameter in DNGR.
step (int) : The max step in random surfing.
max_epoch (int) : The max epoches in training step.
epochs (int) : The max epoches in training step.
lr (float) : Learning rate in DNGR.
"""

Expand All @@ -67,17 +67,17 @@ def add_args(parser):
@classmethod
def build_model_from_args(cls, args):
return cls(
args.hidden_size1, args.hidden_size2, args.noise, args.alpha, args.step, args.max_epoch, args.lr, args.cpu
args.hidden_size1, args.hidden_size2, args.noise, args.alpha, args.step, args.epochs, args.lr, args.cpu
)

def __init__(self, hidden_size1, hidden_size2, noise, alpha, step, max_epoch, lr, cpu):
def __init__(self, hidden_size1, hidden_size2, noise, alpha, step, epochs, lr, cpu):
super(DNGR, self).__init__()
self.hidden_size1 = hidden_size1
self.hidden_size2 = hidden_size2
self.noise = noise
self.alpha = alpha
self.step = step
self.max_epoch = max_epoch
self.epochs = epochs
self.lr = lr
self.cpu = cpu

Expand Down Expand Up @@ -144,7 +144,7 @@ def forward(self, graph, return_dict=False):
opt = torch.optim.Adam(model.parameters(), lr=self.lr)
loss_func = nn.MSELoss()

epoch_iter = tqdm(range(self.max_epoch))
epoch_iter = tqdm(range(self.epochs))
for epoch in epoch_iter:
opt.zero_grad()
encoded, decoded = model.forward(input_mat)
Expand Down
Loading

0 comments on commit e34f305

Please sign in to comment.