espnet2.schedulers.abs_scheduler.AbsValEpochStepScheduler
espnet2.schedulers.abs_scheduler.AbsValEpochStepScheduler
class espnet2.schedulers.abs_scheduler.AbsValEpochStepScheduler
Bases: AbsEpochStepScheduler
Abstract base class for validation epoch step learning rate schedulers.
This class serves as a blueprint for implementing custom learning rate schedulers that adjust the learning rate based on validation metrics and epoch count. Subclasses must implement the step, state_dict, and load_state_dict methods.
None
- Parameters:
- val (float) – The validation metric to consider for adjusting the learning rate.
- epoch (int , optional) – The current epoch number. If not provided, defaults to None.
- Returns: None
- Yields: None
- Raises:NotImplementedError – If the method is not implemented in a subclass.
########### Examples
class CustomValScheduler(AbsValEpochStepScheduler): : def step(self, val, epoch=None): : # Implement custom logic to adjust learning rate based on # validation metric and epoch. pass <br/> def state_dict(self): : # Return the state of the scheduler. pass <br/> def load_state_dict(self, state): : # Load the state of the scheduler. pass
abstract load_state_dict(state)
Abstract base class for value-based epoch step learning rate schedulers.
This class extends the AbsEpochStepScheduler and provides a blueprint for implementing schedulers that adjust the learning rate based on validation metrics.
None
- Parameters:state (dict) – A dictionary containing the state information to load.
- Raises:NotImplementedError – If the method is not overridden in a derived class.
########### Examples
To create a custom scheduler, inherit from this class and implement the abstract methods.
``
`
python class MyCustomScheduler(AbsValEpochStepScheduler):
def step(self, val, epoch=None): : # Custom logic for adjusting the learning rate based on val pass
def state_dict(self): : # Return the state of the scheduler pass
def load_state_dict(self, state): : # Load the state into the scheduler pass
``
`
NOTE
This class is designed to be inherited. Ensure that all abstract methods are implemented in the derived class.
abstract state_dict()
Abstract base class for validation-based epoch step learning rate schedulers.
This class defines the interface for creating custom learning rate schedulers that adjust the learning rate based on validation metrics at the end of each epoch.
None
- Parameters:
- val (float) – The validation metric to base the learning rate adjustment on.
- epoch (int , optional) – The current epoch number. Defaults to None.
- Returns: None
- Yields: None
- Raises:NotImplementedError – If the method is not overridden in a derived class.
########### Examples
To create a custom scheduler, inherit from this class and implement the required methods:
``
`
python class MyCustomScheduler(AbsValEpochStepScheduler):
def step(self, val, epoch=None): : # Custom implementation for step pass
def state_dict(self): : # Return the state of the scheduler pass
def load_state_dict(self, state): : # Load the state into the scheduler pass
``
`
abstract step(val, epoch: int | None = None)
Abstract base class for defining a validation epoch step scheduler.
This class serves as a blueprint for custom validation epoch step schedulers that can adjust learning rates based on validation metrics. Implementing classes must define the step, state_dict, and load_state_dict methods.
None
- Parameters:
- val (float) – The validation metric used to determine the adjustment of the learning rate.
- epoch (int , optional) – The current epoch number. If not provided, defaults to None.
- Returns: None
- Yields: None
- Raises:NotImplementedError – If the method is called without being overridden in a subclass.
########### Examples
class CustomScheduler(AbsValEpochStepScheduler): : def step(self, val, epoch=None): : # Implement logic to adjust learning rate based on val pass <br/> def state_dict(self): : # Implement logic to return the state of the scheduler pass <br/> def load_state_dict(self, state): : # Implement logic to load the state of the scheduler pass