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

test_dagshub_logger.py 1.8 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
  1. import tempfile
  2. import os.path
  3. import re
  4. from dagshub.logger import *
  5. def in_tmp_dir(f):
  6. with tempfile.TemporaryDirectory() as d:
  7. metrics_path = os.path.join(d, 'metrics.csv')
  8. hparams_path = os.path.join(d, 'hparams.yml')
  9. f(metrics_path, hparams_path)
  10. def test_context_manager_no_eager_logging():
  11. def f(metrics_path, hparams_path):
  12. with dagshub_logger(metrics_path=metrics_path, hparams_path=hparams_path, eager_logging=False) as logger:
  13. logger.log_metrics({'a': 1, 'b': 2})
  14. logger.log_hyperparams({'R': 2, 'D': 2})
  15. logger.log_metrics(a=3, c=42, step_num=2)
  16. logger.log_hyperparams(R=5, lr=1e-4)
  17. assert not os.path.exists(metrics_path)
  18. assert not os.path.exists(hparams_path)
  19. assert os.path.exists(metrics_path)
  20. assert os.path.exists(hparams_path)
  21. with open(metrics_path) as metrics_file:
  22. assert metrics_file.readline() == "Name,Value,Timestamp,Step\n"
  23. assert re.compile('^a,1,\\d+,1\n$').match(metrics_file.readline())
  24. assert re.compile('^b,2,\\d+,1\n$').match(metrics_file.readline())
  25. assert re.compile('^a,3,\\d+,2\n$').match(metrics_file.readline())
  26. assert re.compile('^c,42,\\d+,2\n$').match(metrics_file.readline())
  27. assert not metrics_file.readline()
  28. with open(hparams_path) as hparams_file:
  29. assert yaml.safe_load(hparams_file) == {'R': 5, 'D': 2, 'lr': 1e-4}
  30. in_tmp_dir(f)
  31. def test_eager_logging():
  32. def f(metrics_path, hparams_path):
  33. logger = DAGsHubLogger(metrics_path=metrics_path, hparams_path=hparams_path, eager_logging=True)
  34. assert os.path.exists(metrics_path)
  35. assert os.path.exists(hparams_path)
  36. logger.close()
  37. in_tmp_dir(f)
Tip!

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

Comments

Loading...