Bases: ABC
Abstract base class for all schedulers.
This class defines the common interface that every scheduler must implement.
A scheduler is responsible for returning a scalar value (e.g. weight,
learning rate, coefficient) as a function of the current epoch.
Notes
- All derived classes must implement the
get_weight method.
- Input validation should be handled inside each concrete implementation.
- This class does not enforce a specific scheduling strategy.
Source code in aidevelopementtoolkit/torch_utils/schedulers.py
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 | class AbstractScheduler(ABC):
"""Abstract base class for all schedulers.
This class defines the common interface that every scheduler must implement.
A scheduler is responsible for returning a scalar value (e.g. weight,
learning rate, coefficient) as a function of the current epoch.
Notes
-----
- All derived classes must implement the `get_weight` method.
- Input validation should be handled inside each concrete implementation.
- This class does not enforce a specific scheduling strategy.
"""
@abstractmethod
def get_weight(self, current_epoch: int) -> float:
"""Returns the scheduled value for a given epoch.
Parameters
----------
current_epoch : int
The current epoch for which the scheduler value is requested.
Returns
-------
float
The scheduled value at `current_epoch`.
"""
logger.error(
"Not implemented error: The method `get_weight` must be "
"implemented in the derived scheduler class.",
NotImplementedError,
)
@staticmethod
def get_scheduler(class_name: str, scheduler_kwargs: Dict[str, Any]) -> "AbstractScheduler":
"""Returns an instance of the specified scheduler class.
Parameters
----------
class_name : str
The name of the scheduler class to instantiate.
scheduler_kwargs : Dict[str, Any]
The keyword arguments to pass to the scheduler class constructor.
Returns
-------
AbstractScheduler
An instance of the specified scheduler class.
"""
scheduler_class = globals().get(class_name)
if (
not isinstance(scheduler_class, type)
or scheduler_class is AbstractScheduler
or not issubclass(scheduler_class, AbstractScheduler)
or scheduler_class.__module__ != __name__
):
logger.error(
f"Value error: '{class_name}' is not a concrete scheduler class "
"defined in this module.",
ValueError,
)
return scheduler_class(**scheduler_kwargs)
|
Returns the scheduled value for a given epoch.
| Parameters: |
-
current_epoch
(int)
–
The current epoch for which the scheduler value is requested.
|
| Returns: |
-
float
–
The scheduled value at current_epoch.
|
Source code in aidevelopementtoolkit/torch_utils/schedulers.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | @abstractmethod
def get_weight(self, current_epoch: int) -> float:
"""Returns the scheduled value for a given epoch.
Parameters
----------
current_epoch : int
The current epoch for which the scheduler value is requested.
Returns
-------
float
The scheduled value at `current_epoch`.
"""
logger.error(
"Not implemented error: The method `get_weight` must be "
"implemented in the derived scheduler class.",
NotImplementedError,
)
|
Returns an instance of the specified scheduler class.
| Parameters: |
-
class_name
(str)
–
The name of the scheduler class to instantiate.
-
scheduler_kwargs
(Dict[str, Any])
–
The keyword arguments to pass to the scheduler class constructor.
|
Source code in aidevelopementtoolkit/torch_utils/schedulers.py
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 | @staticmethod
def get_scheduler(class_name: str, scheduler_kwargs: Dict[str, Any]) -> "AbstractScheduler":
"""Returns an instance of the specified scheduler class.
Parameters
----------
class_name : str
The name of the scheduler class to instantiate.
scheduler_kwargs : Dict[str, Any]
The keyword arguments to pass to the scheduler class constructor.
Returns
-------
AbstractScheduler
An instance of the specified scheduler class.
"""
scheduler_class = globals().get(class_name)
if (
not isinstance(scheduler_class, type)
or scheduler_class is AbstractScheduler
or not issubclass(scheduler_class, AbstractScheduler)
or scheduler_class.__module__ != __name__
):
logger.error(
f"Value error: '{class_name}' is not a concrete scheduler class "
"defined in this module.",
ValueError,
)
return scheduler_class(**scheduler_kwargs)
|