o
    ॵiv                     @   s   d dl mZ d dlmZ ddlmZ ejejdG dd deZejejdG dd	 d	eZejej	dG d
d deZ	dS )    )LR_Schedulers)LR_SCHEDULER   )
BaseWarmup)module_namec                       .   e Zd ZdZ		d fdd	Zdd Z  ZS )	ConstantWarmupaJ  Linear warmup scheduler.

    Args:
        base_scheduler (torch.optim._LRScheduler): an instance of torch.optim._LRScheduler type
        warmup_ratio (float): Lr used at warmup stage equals to warmup_ratio * initial_lr
        warmup_iters (int | list): Warmup iterations
        last_epoch (int): The index of last epoch.
    皙?c                        || _ tt| j|||d d S N)warmup_iters
last_epoch)warmup_ratiosuperr   __init__selfbase_schedulerr   r   r   	__class__ a/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/trainers/lrscheduler/warmup/warmup.pyr         

zConstantWarmup.__init__c                 C   s   || j krdS | jS )Ng      ?r   r   )r   cur_iterr   r   r   get_warmup_scale   s   
zConstantWarmup.get_warmup_scaler	   r
   __name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r          	r   c                       r   )	LinearWarmupaU  Linear warmup scheduler.

    Args:
        base_scheduler (torch.optim._LRScheduler): an instance of torch.optim._LRScheduler type
        warmup_iters (int | list): Warmup iterations
        warmup_ratio (float): Lr used at the beginning of warmup equals to warmup_ratio * initial_lr
        last_epoch (int): The index of last epoch.
    r	   r
   c                    r   r   )r   r   r%   r   r   r   r   r   r   ,   r   zLinearWarmup.__init__c                 C   s    d|| j   d| j  }d| S Nr   r   r   r   kr   r   r   r   5   s   zLinearWarmup.get_warmup_scaler   r   r   r   r   r   r%   !   r$   r%   c                       r   )	ExponentialWarmupaZ  Exponential warmup scheduler.

    Args:
        base_scheduler (torch.optim._LRScheduler): an instance of torch.optim._LRScheduler type
        warmup_iters (int | list): Warmup iterations
        warmup_ratio (float): Lr used at the beginning of warmup equals to warmup_ratio * initial_lr
        last_epoch (int): The index of last epoch.
    r	   r
   c                    r   r   )r   r   r)   r   r   r   r   r   r   E   r   zExponentialWarmup.__init__c                 C   s   | j d|| j   }|S r&   )r   r   r'   r   r   r   r   N   s   z"ExponentialWarmup.get_warmup_scaler   r   r   r   r   r   r)   :   r$   r)   N)
modelscope.metainfor   'modelscope.trainers.lrscheduler.builderr   baser   register_moduler   r%   r)   r   r   r   r   <module>   s   