-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_utils.py
88 lines (73 loc) · 2.01 KB
/
setup_utils.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
import dgl
import numpy as np
import pydantic
import random
import torch
import yaml
from typing import Optional
def set_seed(seed=0):
if seed is None:
return
dgl.seed(seed)
np.random.seed(seed)
random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
class DataLoaderYaml(pydantic.BaseModel):
batch_size: int
num_workers: int
class BiMPNNYaml(pydantic.BaseModel):
x_n_emb_size: int
pe_emb_size: Optional[int] = 0
y_emb_size: Optional[int] = 0
num_mpnn_layers: int
pool: Optional[str] = None
pe: Optional[str] = None
class OptimizerYaml(pydantic.BaseModel):
lr: float
amsgrad: bool
class NodeCountYaml(pydantic.BaseModel):
loader: DataLoaderYaml
model: BiMPNNYaml
num_epochs: int
optimizer: OptimizerYaml
class NodePredictorYaml(pydantic.BaseModel):
t_emb_size: int
out_hidden_size: int
num_transformer_layers: int
num_heads: int
dropout: float
class NodePredYaml(pydantic.BaseModel):
T: int
loader: DataLoaderYaml
num_epochs: int
graph_encoder: BiMPNNYaml
predictor: NodePredictorYaml
optimizer: OptimizerYaml
class EdgePredictorYaml(pydantic.BaseModel):
t_emb_size: int
out_hidden_size: int
class EdgePredYaml(pydantic.BaseModel):
T: int
loader: DataLoaderYaml
num_epochs: int
graph_encoder: BiMPNNYaml
predictor: EdgePredictorYaml
optimizer: OptimizerYaml
class GeneralYaml(pydantic.BaseModel):
dataset: str
conditional: bool
patience: Optional[int] = None
class LayerDAGYaml(pydantic.BaseModel):
general: GeneralYaml
node_count: NodeCountYaml
node_pred: NodePredYaml
edge_pred: EdgePredYaml
def load_yaml(config_file):
with open(config_file) as f:
yaml_data = yaml.load(f, Loader=yaml.loader.SafeLoader)
return LayerDAGYaml(**yaml_data).model_dump()