From 45727e4509980002314c34a359fadcd74730b00a Mon Sep 17 00:00:00 2001 From: cenyk1230 Date: Tue, 27 Jul 2021 21:05:43 +0800 Subject: [PATCH 1/2] Fix actnn tests --- cogdl/utils/utils.py | 6 ++ tests/models/ssl/test_generative_models.py | 1 + tests/tasks/test_link_prediction.py | 6 +- tests/tasks/test_node_classification.py | 86 +++++++++++----------- 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/cogdl/utils/utils.py b/cogdl/utils/utils.py index ca548534..42801c66 100644 --- a/cogdl/utils/utils.py +++ b/cogdl/utils/utils.py @@ -25,6 +25,12 @@ def build_args_from_dict(dic): return args +def update_args_from_dict(args, dic): + for key, value in dic.items(): + args.__setattr__(key, value) + return args + + def set_random_seed(seed): random.seed(seed) np.random.seed(seed) diff --git a/tests/models/ssl/test_generative_models.py b/tests/models/ssl/test_generative_models.py index 3f072992..3a70c16d 100644 --- a/tests/models/ssl/test_generative_models.py +++ b/tests/models/ssl/test_generative_models.py @@ -42,6 +42,7 @@ def get_default_args(): "eval_agc": False, "subgraph_sampling": False, "sample_size": 128, + "actnn": False, } args = build_args_from_dict(args) dataset = build_dataset(args) diff --git a/tests/tasks/test_link_prediction.py b/tests/tasks/test_link_prediction.py index 263311be..51d35d3b 100644 --- a/tests/tasks/test_link_prediction.py +++ b/tests/tasks/test_link_prediction.py @@ -1,10 +1,7 @@ import torch -from torch import argsort -from cogdl import options -from cogdl.tasks import build_task, register_task +from cogdl.tasks import build_task from cogdl.datasets import build_dataset -from cogdl.models import build_model from cogdl.utils import build_args_from_dict @@ -21,6 +18,7 @@ def get_default_args(): "activation": "relu", "residual": False, "norm": None, + "actnn": False, } return build_args_from_dict(default_dict) diff --git a/tests/tasks/test_node_classification.py b/tests/tasks/test_node_classification.py index 8f88273e..7384f6ed 100644 --- a/tests/tasks/test_node_classification.py +++ b/tests/tasks/test_node_classification.py @@ -2,21 +2,19 @@ from cogdl.tasks import build_task from cogdl.datasets import build_dataset from cogdl.models import build_model -from cogdl.utils import build_args_from_dict +from cogdl.utils import update_args_from_dict +from cogdl.options import get_default_args - -def get_default_args(): +def get_default_args_for_nc(): + args = get_default_args(task="node_classification", dataset="cora", model="gcn") default_dict = { "hidden_size": 16, "dropout": 0.5, "patience": 2, - "device_id": [0], "max_epoch": 3, "sampler": "none", "num_layers": 2, "cpu": True, - "lr": 0.01, - "weight_decay": 5e-4, "missing_rate": -1, "task": "node_classification", "dataset": "cora", @@ -28,11 +26,11 @@ def get_default_args(): "norm": None, "num_workers": 1, } - return build_args_from_dict(default_dict) + return update_args_from_dict(args, default_dict) def test_gdc_gcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "gdc_gcn" @@ -54,7 +52,7 @@ def test_gdc_gcn_cora(): def test_gcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.num_layers = 2 args.dataset = "cora" @@ -76,7 +74,7 @@ def test_gcn_cora(): def test_gat_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "gat" @@ -93,7 +91,7 @@ def test_gat_cora(): def test_mlp_pubmed(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "pubmed" args.model = "mlp" @@ -104,7 +102,7 @@ def test_mlp_pubmed(): def test_mixhop_citeseer(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "citeseer" args.model = "mixhop" @@ -116,7 +114,7 @@ def test_mixhop_citeseer(): def test_graphsage_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.model = "graphsage" args.aggr = "mean" @@ -141,7 +139,7 @@ def test_graphsage_cora(): def test_pyg_cheb_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "chebyshev" @@ -153,7 +151,7 @@ def test_pyg_cheb_cora(): def test_pyg_gcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "pyg_gcn" @@ -165,7 +163,7 @@ def test_pyg_gcn_cora(): def test_clustergcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.dataset = "pubmed" args.model = "gcn" args.trainer = "clustergcn" @@ -178,7 +176,7 @@ def test_clustergcn_cora(): def test_gcn_cora_sampler(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.trainer = "graphsaint" @@ -201,7 +199,7 @@ def test_gcn_cora_sampler(): def test_graphsaint_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.trainer = "graphsaint" @@ -225,7 +223,7 @@ def test_graphsaint_cora(): def test_unet_citeseer(): - args = get_default_args() + args = get_default_args_for_nc() args.cpu = True args.model = "unet" args.dataset = "citeseer" @@ -244,7 +242,7 @@ def test_unet_citeseer(): def test_drgcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "drgcn" @@ -255,7 +253,7 @@ def test_drgcn_cora(): def test_drgat_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "drgat" @@ -266,7 +264,7 @@ def test_drgat_cora(): def test_disengcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "disengcn" @@ -280,7 +278,7 @@ def test_disengcn_cora(): def test_graph_mix(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "gcnmix" @@ -298,7 +296,7 @@ def test_graph_mix(): def test_srgcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "srgcn" @@ -338,7 +336,7 @@ def test_srgcn_cora(): def test_gcnii_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.dataset = "cora" args.task = "node_classification" args.model = "gcnii" @@ -355,7 +353,7 @@ def test_gcnii_cora(): def test_deepergcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.dataset = "cora" args.task = "node_classification" args.model = "deepergcn" @@ -382,7 +380,7 @@ def test_deepergcn_cora(): def test_grand_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.model = "grand" args.dataset = "cora" args.task = "node_classification" @@ -401,7 +399,7 @@ def test_grand_cora(): def test_gpt_gnn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "gpt_gnn" @@ -430,7 +428,7 @@ def test_gpt_gnn_cora(): def test_sign_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.model = "sign" args.dataset = "cora" @@ -456,7 +454,7 @@ def test_sign_cora(): def test_jknet_jknet_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "jknet" @@ -477,7 +475,7 @@ def test_jknet_jknet_cora(): def test_ppnp_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.model = "ppnp" args.dataset = "cora" @@ -491,7 +489,7 @@ def test_ppnp_cora(): def test_appnp_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.model = "ppnp" args.dataset = "cora" @@ -505,7 +503,7 @@ def test_appnp_cora(): def test_sgc_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "sgc" @@ -515,7 +513,7 @@ def test_sgc_cora(): def test_dropedge_gcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "dropedge_gcn" @@ -538,7 +536,7 @@ def test_dropedge_gcn_cora(): def test_dropedge_resgcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "dropedge_gcn" @@ -561,7 +559,7 @@ def test_dropedge_resgcn_cora(): def test_dropedge_densegcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "dropedge_gcn" @@ -584,7 +582,7 @@ def test_dropedge_densegcn_cora(): def test_dropedge_inceptiongcn_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.task = "node_classification" args.dataset = "cora" args.model = "dropedge_gcn" @@ -607,7 +605,7 @@ def test_dropedge_inceptiongcn_cora(): def test_pprgo_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.cpu = True args.task = "node_classification" args.dataset = "cora" @@ -632,7 +630,7 @@ def test_pprgo_cora(): def test_gcn_ppi(): - args = get_default_args() + args = get_default_args_for_nc() args.dataset = "ppi" args.model = "gcn" args.cpu = True @@ -641,7 +639,7 @@ def test_gcn_ppi(): def build_custom_dataset(): - args = get_default_args() + args = get_default_args_for_nc() args.dataset = "cora" dataset = build_dataset(args) dataset.data._adj_train = dataset.data._adj_full @@ -649,7 +647,7 @@ def build_custom_dataset(): def test_sagn_cora(): - args = get_default_args() + args = get_default_args_for_nc() dataset = build_custom_dataset() args.model = "sagn" args.nhop = args.label_nhop = 2 @@ -668,7 +666,7 @@ def test_sagn_cora(): def test_c_s_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.use_embeddings = True args.correct_alpha = 0.5 args.smooth_alpha = 0.5 @@ -687,7 +685,7 @@ def test_c_s_cora(): def test_sage_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.aggr = "mean" args.normalize = True args.norm = "layernorm" @@ -697,7 +695,7 @@ def test_sage_cora(): def test_revnets_cora(): - args = get_default_args() + args = get_default_args_for_nc() args.group = 2 args.num_layers = 3 args.last_norm = "batchnorm" From b93647b846e04fb4c2d4b7a61109fde329865a7c Mon Sep 17 00:00:00 2001 From: cenyk1230 Date: Wed, 28 Jul 2021 11:13:44 +0800 Subject: [PATCH 2/2] Fix lp tests --- tests/tasks/test_link_prediction.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/tasks/test_link_prediction.py b/tests/tasks/test_link_prediction.py index 51d35d3b..36865654 100644 --- a/tests/tasks/test_link_prediction.py +++ b/tests/tasks/test_link_prediction.py @@ -57,6 +57,7 @@ def get_kg_default_args(): "activation": "relu", "residual": False, "norm": None, + "actnn": False, } return build_args_from_dict(default_dict) @@ -127,6 +128,7 @@ def get_kge_default_args(): "checkpoint": False, "save_dir": ".", "device_id": [0], + "actnn": False, } return build_args_from_dict(default_dict) @@ -191,6 +193,7 @@ def get_gnn_link_prediction_args(): "activation": "relu", "residual": False, "norm": None, + "actnn": False, } return build_args_from_dict(args)