-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_model_training.py
87 lines (74 loc) · 2.48 KB
/
run_model_training.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
import argparse
from datetime import datetime
import torch
import wandb
from configs.run_model import sw, tcga
from configs.utils import str2bool
from experiments.logger import create_logger
from experiments.train import train_and_test
from experiments.utils import init_seeds, save_run_results
TIME_STR = "{:%Y_%m_%d_%H_%M_%S_%f}".format(datetime.now())
DATE_STR = "{:%Y_%m_%d}".format(datetime.now())
def parse_default_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="StructuredInterventionNetworks")
parser.add_argument("--name", type=str, default=TIME_STR)
parser.add_argument("--task", type=str, default="tcga", choices=["sw", "tcga"])
parser.add_argument(
"--model",
type=str,
default="sin",
choices=["sin", "gnn", "graphite", "cat", "zero"],
)
parser.add_argument("--seed", type=int, default=0)
parser.add_argument("--cuda", type=int, default=0)
parser.add_argument(
"--log_interval",
type=int,
default=50,
help="How many batches to wait before logging training status",
)
parser.add_argument(
"--ablation", type=str2bool, default=False, help="Changes wandb project name."
)
parser.add_argument(
"--data_path",
type=str,
default="./generated_data/",
help="Path to save/load generated data",
)
parser.add_argument(
"--results_path",
type=str,
default="./results/",
help="Path to save experimental results",
)
args, _ = parser.parse_known_args()
if args.task == "sw":
sw.add_params(parser)
elif args.task == "tcga":
tcga.add_params(parser)
args = parser.parse_args()
return args
def main() -> None:
args = parse_default_args()
project_name = (
f"sin_{DATE_STR}-{args.task}-ABL"
if args.ablation
else f"sin_{DATE_STR}-{args.task}"
)
wandb.init(
project=project_name, name=args.model + "-" + str(args.seed), config=args
)
init_seeds(seed=args.seed)
logger = create_logger("log/%s.log" % args.name)
logger.info(args)
device = torch.device(f"cuda:{args.cuda}" if torch.cuda.is_available() else "cpu")
test_units_with_predictions, test_errors = train_and_test(args=args, device=device)
save_run_results(
test_units_with_predictions=test_units_with_predictions,
test_errors=test_errors,
time_str=TIME_STR,
args=args,
)
if __name__ == "__main__":
main()