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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  1. from abc import abstractmethod
  2. import numpy as np
  3. __all__ = ["IDecayFunction", "ConstantDecay", "ThresholdDecay", "ExpDecay", "EMA_DECAY_FUNCTIONS"]
  4. class IDecayFunction:
  5. """
  6. Interface for EMA decay schedule. The decay schedule is a function of the maximum decay value and training progress.
  7. Usually it gradually increase EMA from to the maximum value. The exact ramp-up schedule is defined by the concrete
  8. implementation.
  9. """
  10. @abstractmethod
  11. def __call__(self, decay: float, step: int, total_steps: int) -> float:
  12. """
  13. :param decay: The maximum decay value.
  14. :param step: Current training step. The unit-range training percentage can be obtained by `step / total_steps`.
  15. :param total_steps: Total number of training steps.
  16. :return: Computed decay value for a given step.
  17. """
  18. pass
  19. class ConstantDecay(IDecayFunction):
  20. """
  21. Constant decay schedule.
  22. """
  23. def __init__(self, **kwargs):
  24. pass
  25. def __call__(self, decay: float, step: int, total_steps: int) -> float:
  26. return decay
  27. class ThresholdDecay(IDecayFunction):
  28. """
  29. Gradually increase EMA decay from 0.1 to the maximum value using following formula: min(decay, (1 + step) / (10 + step))
  30. """
  31. def __init__(self, **kwargs):
  32. pass
  33. def __call__(self, decay: float, step, total_steps: int) -> float:
  34. return np.minimum(decay, (1 + step) / (10 + step))
  35. class ExpDecay(IDecayFunction):
  36. """
  37. Gradually increase EMA decay from 0.1 to the maximum value using following formula: decay * (1 - math.exp(-x * self.beta))
  38. """
  39. def __init__(self, beta: float, **kwargs):
  40. self.beta = beta
  41. def __call__(self, decay: float, step, total_steps: int) -> float:
  42. x = step / total_steps
  43. return decay * (1 - np.exp(-x * self.beta))
  44. EMA_DECAY_FUNCTIONS = {"constant": ConstantDecay, "threshold": ThresholdDecay, "exp": ExpDecay}
  45. if __name__ == "__main__":
  46. import matplotlib.pyplot as plt
  47. total_steps = 6_00_000
  48. step = np.arange(total_steps)
  49. decay = 0.999
  50. plt.figure()
  51. plt.plot(step, ExpDecay(beta=15)(decay, step, total_steps), label="exp(beta=15)")
  52. plt.plot(step, ThresholdDecay()(decay, step, total_steps), label="threshold")
  53. plt.plot(step, [ConstantDecay()(decay, step, total_steps)] * total_steps, label="constant")
  54. plt.xlabel("Training step")
  55. plt.ylabel("Decay value")
  56. plt.legend()
  57. plt.title(f"EMA Decay Schedules (Max decay is {decay})")
  58. plt.tight_layout()
  59. plt.savefig("ema_decay_schedules.png")
  60. plt.show()
Discard
Tip!

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