1: import os
2: import sys
3: import logging
4: import hydra
5: from omegaconf import DictConfig, OmegaConf
6: from omegaconf.omegaconf import open_dict
7: 
8: from calibrate.engine import Trainer, SegmentTrainer, NLPTrainer
9: from calibrate.utils import set_random_seed
10: 
11: logger = logging.getLogger(__name__)
12: 
13: TRAINERS = {
14:     "cv": Trainer,
15:     "segment": SegmentTrainer,
16:     "nlp": NLPTrainer,
17: }
18: 
19: 
20: @hydra.main(config_path="./configs", config_name="defaults")
21: def main(cfg: DictConfig):
22:     logger.info("Launch command : ")
23:     logger.info(" ".join(sys.argv))
24:     with open_dict(cfg):
25:         cfg.work_dir = os.getcwd()
26:     logger.info("\n" + OmegaConf.to_yaml(cfg))
27: 
28:     set_random_seed(
29:         cfg.seed if cfg.seed is not None else None,
30:         deterministic=True if cfg.seed is not None else False
31:     )
32: 
33:     trainer = TRAINERS[cfg.task](cfg)
34:     trainer.run()
35: 
36:     logger.info("Job complete !\n")
37: 
38: 
39: if __name__ == "__main__":
40:     main()