forked from ml-energy/zeus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_profiling.py
53 lines (45 loc) · 1.91 KB
/
run_profiling.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
"""Run profiling for Imagenet dataset"""
import os
import argparse
import json
def parse_args() -> argparse.Namespace:
"""Parse command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--profile_folder", type=str, default=None, help="Unique folder name for profiling", required=True
)
parser.add_argument(
"--epochs", type=int, default=10, help="Maximum number of epochs to profile.", required=True
)
parser.add_argument(
"--batch_sizes", type=int, nargs="+", help="Batch size.", required=True
)
parser.add_argument(
"--power_limits", type=int, nargs="+", help="Define range of power limits", required=True
)
parser.add_argument(
"--warmup_steps", type=int, default=10, help="Warm up steps for profiling"
)
parser.add_argument(
"--profile_steps", type=int, default=40, help="Profile steps"
)
return parser.parse_args()
def main(args: argparse.Namespace) -> None:
power_limits = " ".join(str(pl) for pl in args.power_limits)
os.system(f"mkdir {args.profile_folder}")
for bs in args.batch_sizes:
profile_path =f"{args.profile_folder}/{str(bs)}.json"
os.system(
f"python train_single.py --profile True --profile_path {profile_path} --epochs {args.epochs} --batch_size {bs} --power_limits {power_limits} --warmup_steps {args.warmup_steps} --profile_steps {args.profile_steps} --data /imagenet"
)
result = {}
for file in os.listdir(f"{args.profile_folder}"):
with open(f"{args.profile_folder}/{file}", 'r') as infile:
result.update(json.load(infile))
key = str(file)[:-5]
result[key] = result["measurements"]
del result["measurements"]
with open(f"{args.profile_folder}/profiling.json", 'w') as output_file:
json.dump(result, output_file)
if __name__ == "__main__":
main(parse_args())