forked from graphcore/distributed-kge-poplar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_profile.py
68 lines (54 loc) · 2.07 KB
/
run_profile.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
# Copyright (c) 2022 Graphcore Ltd. All rights reserved.
"""Profiling script."""
import argparse
import json
import os
from pathlib import Path
import numpy as np
import poplar_kge as kge
import poplar_kge_utility as kge_utility
import test_poplar_kge
def profile(settings: kge.Settings, run_predict: bool) -> None:
if settings.logging.path:
settings.logging.path.mkdir(parents=True, exist_ok=True)
assert (
"POPLAR_ENGINE_OPTIONS" not in os.environ
), "POPLAR_ENGINE_OPTIONS should not be set outside the run_profile script"
os.environ["POPLAR_ENGINE_OPTIONS"] = json.dumps(
{
"autoReport.directory": str(settings.logging.path),
"autoReport.all": True,
"autoReport.outputArchive": False,
"autoReport.executionProfileProgramRunCount": 1,
"profiler.replicaToProfile": 0,
}
)
logger = kge_utility.Logger(settings, __file__, truncate_train=False)
engine = kge.Engine(
settings, np.full(settings.model.n_shard, settings.model.n_entity - 1)
)
logger.log("compile", {})
engine.initialise_variables()
# hack to avoid having to run additional 'fill' programs
engine.uninitialized_entity_data[:] = False
logger.log("initialise", {})
train_batch = test_poplar_kge._random_batch(engine)
predict_query = test_poplar_kge._random_prediction_query(
engine, engine.settings.execution.predict_hr_batch_size
)
logger.log("sample", {})
for _ in range(5):
engine.train_step_loop(train_batch)
logger.log("train_step_loop", {})
if run_predict:
engine.predict(predict_query)
logger.log("predict_step", {})
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("output", nargs="?", type=Path)
args = parser.parse_args()
settings = kge.Settings.create_wikikg90mv2()
settings.logging.wandb = False
settings.logging.path = args.output
settings.prepare()
profile(settings, run_predict=False)