You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							27 lines
						
					
					
						
							810 B
						
					
					
				
			
		
		
	
	
							27 lines
						
					
					
						
							810 B
						
					
					
				from torch import optim
 | 
						|
from pydantic import BaseModel
 | 
						|
 | 
						|
 | 
						|
class BaseScheduler:
 | 
						|
    """
 | 
						|
    Abstract base class for learning rate schedulers.
 | 
						|
    Wraps a PyTorch LR scheduler and provides a unified interface.
 | 
						|
    """
 | 
						|
 | 
						|
    def __init__(self, optimizer: optim.Optimizer, params: BaseModel) -> None:
 | 
						|
        self.scheduler: optim.lr_scheduler.LRScheduler | None = None
 | 
						|
 | 
						|
    def step(self) -> None:
 | 
						|
        """
 | 
						|
        Performs a single scheduler step. This typically updates the learning rate
 | 
						|
        based on the current epoch or step count.
 | 
						|
        """
 | 
						|
        if self.scheduler is not None:
 | 
						|
            self.scheduler.step()
 | 
						|
 | 
						|
    def get_last_lr(self) -> list[float]:
 | 
						|
        """
 | 
						|
        Returns the most recent learning rate(s).
 | 
						|
        """
 | 
						|
        return self.scheduler.get_last_lr() if self.scheduler else []
 |