espnet2.schedulers.abs_scheduler.AbsEpochStepScheduler
espnet2.schedulers.abs_scheduler.AbsEpochStepScheduler
class espnet2.schedulers.abs_scheduler.AbsEpochStepScheduler
Bases: AbsScheduler
Abstract base class for epoch-based learning rate schedulers.
This class defines the interface for all epoch-based schedulers. It inherits from the AbsScheduler class and requires implementations for methods to manage the learning rate at each epoch.
None
- Parameters:epoch (int , optional) – The current epoch. Defaults to None.
step(epoch
int = None): Updates the learning rate based on the current epoch.
state_dict()
Returns the state of the scheduler as a dictionary.
load_state_dict(state)
Loads the state of the scheduler from a given dictionary.
########### Examples
Example of a custom epoch scheduler implementation
class CustomEpochScheduler(AbsEpochStepScheduler):
def __init__(self, optimizer): : self.optimizer = optimizer self.initial_lr = optimizer.param_groups[0][‘lr’]
def step(self, epoch: int = None): : new_lr = self.initial_lr * (0.1 ** (epoch // 10)) for param_group in self.optimizer.param_groups: <br/>
param_group[‘lr’] = new_lr
def state_dict(self): : return
def load_state_dict(self, state): : self.initial_lr = state[‘initial_lr’]
abstract load_state_dict(state)
Abstract base class for epoch step learning rate schedulers.
This class defines the interface for epoch-based learning rate schedulers. Subclasses must implement the step, state_dict, and load_state_dict methods to manage the learning rate scheduling.
None
- Parameters:state – The state dictionary to load into the scheduler.
- Returns: None
- Yields: None
- Raises:NotImplementedError – If the method is not implemented in a subclass.
########### Examples
class MyScheduler(AbsEpochStepScheduler): : def step(self, epoch: int = None): : # Implementation for stepping the scheduler pass <br/> def state_dict(self): : # Implementation for saving the state pass <br/> def load_state_dict(self, state): : # Implementation for loading the state pass
my_scheduler = MyScheduler() my_scheduler.load_state_dict({‘some_key’: ‘some_value’})
NOTE
This class is meant to be subclassed and should not be instantiated directly.
abstract state_dict()
Abstract base class for epoch-based step learning rate schedulers.
This class provides the interface for implementing learning rate schedulers that adjust the learning rate at the end of each epoch.
None
- Parameters:epoch (int , optional) – The current epoch. Defaults to None.
- Returns: A state dictionary containing the current state of the scheduler.
- Return type: dict
- Yields: None
- Raises:
- NotImplementedError – If the method is not implemented in a
- subclass. –
########### Examples
To create a custom epoch step scheduler, inherit from this class and implement the required methods:
``
`
python class MyCustomScheduler(AbsEpochStepScheduler):
def step(self, epoch: int = None): : # Custom logic to update the learning rate pass
def state_dict(self): : # Return the state of the scheduler return {}
def load_state_dict(self, state): : # Load the state into the scheduler pass
``
`
abstract step(epoch: int | None = None)
Abstract base class for epoch-based learning rate schedulers.
This class serves as a blueprint for creating custom epoch-based learning rate schedulers by inheriting from it. Implementations must define the step, state_dict, and load_state_dict methods.
None
- Parameters:epoch (int , optional) – The current epoch number. Defaults to None.
- Returns: None
- Yields: None
- Raises:NotImplementedError – If the step method is not implemented by a subclass.
########### Examples
To create a custom scheduler, you would inherit from this class and implement the required methods. For example:
class CustomEpochScheduler(AbsEpochStepScheduler): : def step(self, epoch: int = None): : # Custom logic to update learning rate pass <br/> def state_dict(self): : # Logic to return the state dictionary pass <br/> def load_state_dict(self, state): : # Logic to load the state dictionary pass