Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

logger.py 2.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. from argparse import Namespace
  2. import pytorch_lightning
  3. from pytorch_lightning.logging import rank_zero_only
  4. from ..logger import DAGsHubLogger as LoggerImpl
  5. class DAGsHubLogger(pytorch_lightning.logging.LightningLoggerBase):
  6. def __init__(self,
  7. metrics_path: str = 'metrics.csv',
  8. should_log_metrics: bool = True,
  9. hparams_path: str = 'params.yml',
  10. should_log_hparams: bool = True,
  11. should_make_dirs: bool = True,
  12. status_hyperparam_name: str = 'status',
  13. ):
  14. """
  15. :param metrics_path: Where to save the single metrics CSV file.
  16. :param should_log_metrics: Whether to log metrics at all. Should probably always be True.
  17. :param hparams_path: Where to save the single hyperparameter YAML file.
  18. :param should_log_hparams: Whether to log hyperparameters to a file.
  19. Should be False if you want to work with hyperparameters in a dependency file,
  20. rather than specifying them using command line arguments.
  21. :param should_make_dirs: If true, the directory structure required by metrics_path and hparams_path
  22. will be created. Has no effect if the directory structure already exists.
  23. :param status_hyperparam_name: The 'status' passed by pytorch_lightning at the end of training
  24. will be saved as an additional hyperparameter, with this name.
  25. This can be useful for filtering and searching later on.
  26. Set to None if you don't want this to happen.
  27. """
  28. super(DAGsHubLogger, self).__init__()
  29. self.status_hyperparam_name = status_hyperparam_name
  30. self.logger = LoggerImpl(metrics_path=metrics_path, should_log_metrics=should_log_metrics,
  31. hparams_path=hparams_path, should_log_hparams=should_log_hparams,
  32. should_make_dirs=should_make_dirs, eager_logging=False)
  33. @rank_zero_only
  34. def log_metrics(self, metrics: dict, step_num: int):
  35. self.logger.log_metrics(metrics, step_num)
  36. @rank_zero_only
  37. def log_hyperparams(self, params: Namespace):
  38. self.logger.log_hyperparams(params.__dict__)
  39. @rank_zero_only
  40. def save(self):
  41. self.logger.save()
  42. @rank_zero_only
  43. def close(self):
  44. self.logger.close()
  45. @rank_zero_only
  46. def finalize(self, status: str):
  47. if self.status_hyperparam_name is not None and self.status_hyperparam_name not in self.logger.hparams:
  48. self.logger.log_hyperparams({self.status_hyperparam_name: status})
  49. self.logger.save_hparams()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...