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

#869 Add DagsHub Logger to Super Gradients

Merged
Ghost merged 1 commits into Deci-AI:master from timho102003:dagshub_logger
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
  1. import unittest
  2. from super_gradients import Trainer
  3. from super_gradients.common.auto_logging.auto_logger import AutoLoggerConfig
  4. from super_gradients.training.dataloaders.dataloaders import classification_test_dataloader
  5. from super_gradients.training.metrics import Accuracy, Top5
  6. from super_gradients.training.models import ResNet18
  7. import os
  8. import logging
  9. from super_gradients.common.abstractions.abstract_logger import get_logger
  10. import shutil
  11. class SgTrainerLoggingTest(unittest.TestCase):
  12. def test_train_logging(self):
  13. trainer = Trainer("test_train_with_full_log")
  14. net = ResNet18(num_classes=5, arch_params={})
  15. train_params = {
  16. "max_epochs": 2,
  17. "lr_updates": [1],
  18. "lr_decay_factor": 0.1,
  19. "lr_mode": "step",
  20. "lr_warmup_epochs": 0,
  21. "initial_lr": 0.1,
  22. "loss": "cross_entropy",
  23. "optimizer": "SGD",
  24. "criterion_params": {},
  25. "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  26. "train_metrics_list": [Accuracy(), Top5()],
  27. "valid_metrics_list": [Accuracy(), Top5()],
  28. "metric_to_watch": "Accuracy",
  29. "greater_metric_to_watch_is_better": True,
  30. }
  31. trainer.train(
  32. model=net,
  33. training_params=train_params,
  34. train_loader=classification_test_dataloader(batch_size=10),
  35. valid_loader=classification_test_dataloader(batch_size=10),
  36. )
  37. logfile_path = AutoLoggerConfig.get_log_file_path()
  38. assert os.path.exists(logfile_path) and os.path.getsize(logfile_path) > 0
  39. root_logger_handlers = logging.root.handlers
  40. assert any(isinstance(handler, logging.handlers.FileHandler) and handler.baseFilename == logfile_path for handler in root_logger_handlers)
  41. assert any(isinstance(handler, logging.StreamHandler) and handler.name == "console" for handler in root_logger_handlers)
  42. def test_logger_with_non_existing_deci_logs_dir(self):
  43. user_dir = os.path.expanduser(r"~")
  44. logs_dir_path = os.path.join(user_dir, "non_existing_deci_logs_dir")
  45. if os.path.exists(logs_dir_path):
  46. shutil.rmtree(logs_dir_path)
  47. module_name = "super_gradients.trainer.sg_trainer"
  48. _ = get_logger(module_name, logs_dir_path=logs_dir_path)
  49. root_logger_handlers = logging.root.handlers
  50. assert any(isinstance(handler, logging.StreamHandler) and handler.name == "console" for handler in root_logger_handlers)
  51. if __name__ == "__main__":
  52. unittest.main()
Discard
Tip!

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