-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_dpi.py
50 lines (35 loc) · 1.16 KB
/
test_dpi.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
import hydra
from hydra.utils import instantiate
from lightning.pytorch import Trainer, seed_everything
from omegaconf import DictConfig
from biomedkg.kge_module import KGEModule
@hydra.main(version_base=None, config_path="configs", config_name="dpi")
def main(cfg: DictConfig):
seed_everything(cfg.seed)
data_module = instantiate(
cfg.data, gcl_model=cfg.gcl_model, gcl_fuse_method=cfg.gcl_fuse_method
)
data_module.setup(stage="split")
print("=" * 20)
print(f"Load from checkpoint: {cfg.pretrained_path}")
print("=" * 20)
model = KGEModule.load_from_checkpoint(cfg.pretrained_path)
model.neg_ratio = cfg.neg_ratio
model.edge_mapping = data_module.edge_map_index
trainer_args = {
"accelerator": "auto",
"log_every_n_steps": 10,
"deterministic": True,
"devices": cfg.devices,
}
print("=" * 20)
print(f"Neg Ratio: {model.neg_ratio}")
print("=" * 20)
trainer = Trainer(**trainer_args)
test_args = {
"model": model,
"dataloaders": data_module.test_dataloader(loader_type="saint"),
}
trainer.test(**test_args)
if __name__ == "__main__":
main()