forked from Sheepsody/Batched-Impala-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
53 lines (42 loc) · 1.32 KB
/
run.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
# Running the configuration(s)
import torch
from torch.multiprocessing import cpu_count
import torch.multiprocessing as mp
import argparse
from src.Manager import Manager
import warnings
# The fork method has to be setted in the main method, before any CUDA call
if __name__ == "__main__":
# Parse arguments
try:
mp.set_start_method("forkserver", force=True)
print("forkserver init")
except RuntimeError:
pass
# Disabling the warnings (or messages from PyTorch concerning LSTM's memory blocks)
warnings.filterwarnings("ignore")
# Prompt messages
print(f"PyTorch version {torch.__version__}")
print(f"Number of CPU {cpu_count()}")
print(f"Cuda enabled device {torch.cuda.is_available()}")
parser = argparse.ArgumentParser()
parser.add_argument(
"-c", "--configs", nargs="+", help="Configurations to run", default=["default.cfg"]
)
parser.add_argument(
"-p",
"--parallel",
action="store_true",
help="Run configurations in parallel",
default=False,
)
if __name__ == "__main__":
args = parser.parse_args()
managers = [Manager(config) for config in args.configs]
if args.parallel:
[manager.start() for manager in managers]
[manager.join() for manager in managers]
else:
for manager in managers:
manager.start()
manager.join()