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

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

Comments

Loading...