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

lr_cooldown_test.py 1.9 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
  1. import unittest
  2. from super_gradients.training import Trainer
  3. from super_gradients.training.metrics import Accuracy
  4. from super_gradients.training.datasets import ClassificationTestDatasetInterface
  5. from super_gradients.training.models import LeNet
  6. from super_gradients.training.utils.callbacks import TestLRCallback
  7. class LRCooldownTest(unittest.TestCase):
  8. def setUp(self) -> None:
  9. self.dataset_params = {"batch_size": 4}
  10. self.dataset = ClassificationTestDatasetInterface(dataset_params=self.dataset_params)
  11. self.arch_params = {'num_classes': 10}
  12. def test_lr_cooldown_with_lr_scheduling(self):
  13. # Define Model
  14. net = LeNet()
  15. trainer = Trainer("lr_warmup_test", model_checkpoints_location='local')
  16. trainer.connect_dataset_interface(self.dataset)
  17. lrs = []
  18. phase_callbacks = [TestLRCallback(lr_placeholder=lrs)]
  19. train_params = {"max_epochs": 7, "cosine_final_lr_ratio": 0.2, "lr_mode": "cosine",
  20. "lr_cooldown_epochs": 2,
  21. "lr_warmup_epochs": 3, "initial_lr": 1, "loss": "cross_entropy", "optimizer": 'SGD',
  22. "criterion_params": {}, "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  23. "train_metrics_list": [Accuracy()], "valid_metrics_list": [Accuracy()],
  24. "loss_logging_items_names": ["Loss"], "metric_to_watch": "Accuracy",
  25. "greater_metric_to_watch_is_better": True, "ema": False, "phase_callbacks": phase_callbacks}
  26. expected_lrs = [0.25, 0.5, 0.75, 0.9236067977499791, 0.4763932022500211, 0.4763932022500211, 0.4763932022500211]
  27. trainer.train(model=net, training_params=train_params)
  28. # ALTHOUGH NOT SEEN IN HERE, THE 4TH EPOCH USES LR=1, SO THIS IS THE EXPECTED LIST AS WE COLLECT
  29. # THE LRS AFTER THE UPDATE
  30. self.assertListEqual(lrs, expected_lrs)
Tip!

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

Comments

Loading...