forked from OMichaud0/COMP597-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
65 lines (54 loc) · 1.9 KB
/
Copy pathlaunch.py
File metadata and controls
65 lines (54 loc) · 1.9 KB
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
import logging
import os
logger = logging.getLogger(__name__)
logging.basicConfig(
level=os.environ.get("COMP597_LOG_LEVEL", "WARNING").upper(),
format="[{levelname:.4}] : {asctime} : {module:<24.24} : {message}",
datefmt="%Y-%m-%dT%H:%M:%S",
style='{',
)
from typing import Any, Dict, Optional, Tuple
import argparse
import gc
import src.config as config
import src.data as data
import src.models as models
import src.trainer as trainer
import src.trainer.stats as trainer_stats
def setup_logging(conf : config.Config) -> None:
logging.basicConfig(
filename=conf.logging.filename,
filemode=conf.logging.filemode,
format=conf.logging.format,
datefmt=conf.logging.datefmt,
style=conf.logging.style,
level=conf.logging.level,
force=True,
)
def process_conf(conf : config.Config) -> Tuple[trainer.Trainer, Optional[Dict[str, Any]]]:
dataset = data.load_data(conf)
logger.debug(f"Dataset loaded with {len(dataset)} samples.")
return models.model_factory(conf, dataset)
def get_conf() -> config.Config:
parser = argparse.ArgumentParser()
conf = config.Config()
conf.add_arguments(parser)
args, _ = parser.parse_known_args()
conf.parse_arguments(args)
return conf
def main():
conf = get_conf()
setup_logging(conf)
logger.debug(f"Configuration: \n{conf}")
logger.info(f"available models: {models.get_available_models()}")
logger.info(f"available data load functions: {data.get_available_data_load_functions()}")
logger.info(f"available trainer stats classes: {trainer_stats.get_available_trainer_stats()}")
model_trainer, model_kwargs = process_conf(conf)
model_trainer.train(model_kwargs)
# This forces garbage collection at process exit. It ensure proper closing of resources.
del conf
del model_kwargs
del model_trainer
if __name__ == "__main__":
main()
gc.collect()