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

#381 Feature/sg 000 connect to lab

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/sg-000_connect_to_lab
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
  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 import HpmStruct, get_param
  7. from super_gradients.training.utils.callbacks import TestLRCallback
  8. import numpy as np
  9. class TestNet(LeNet):
  10. """
  11. Toy test net with update_param_groups method that hard codes some lr.
  12. """
  13. def __init__(self):
  14. super(TestNet, self).__init__()
  15. def update_param_groups(
  16. self, param_groups: list, lr: float, epoch: int, iter: int, training_params: HpmStruct, total_batch: int
  17. ) -> list:
  18. initial_lr = get_param(training_params, "initial_lr")
  19. for param_group in param_groups:
  20. param_group["lr"] = initial_lr * (epoch + 1)
  21. return param_groups
  22. class UpdateParamGroupsTest(unittest.TestCase):
  23. def test_lr_scheduling_with_update_param_groups(self):
  24. # Define Model
  25. net = TestNet()
  26. trainer = Trainer("lr_warmup_test", model_checkpoints_location='local')
  27. lrs = []
  28. phase_callbacks = [TestLRCallback(lr_placeholder=lrs)]
  29. train_params = {"max_epochs": 3,
  30. "lr_mode": "step",
  31. "lr_updates": [0, 1, 2],
  32. "initial_lr": 0.1,
  33. "lr_decay_factor": 1,
  34. "loss": "cross_entropy", "optimizer": 'SGD',
  35. "criterion_params": {}, "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  36. "train_metrics_list": [Accuracy()], "valid_metrics_list": [Accuracy()],
  37. "loss_logging_items_names": ["Loss"], "metric_to_watch": "Accuracy",
  38. "greater_metric_to_watch_is_better": True, "ema": False, "phase_callbacks": phase_callbacks,
  39. }
  40. expected_lrs = np.array([0.1, 0.2, 0.3])
  41. trainer.train(model=net, training_params=train_params,
  42. train_loader=classification_test_dataloader(),
  43. valid_loader=classification_test_dataloader())
  44. self.assertTrue(np.allclose(np.array(lrs), expected_lrs, rtol=0.0000001))
Discard
Tip!

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