o
    }oiW!                     @   s  d dl mZ d dlmZ d dlmZmZmZ eG dd dZeG dd deZ	eG dd	 d	eZ
eG d
d de
ZeG dd de
ZeG dd de
ZeG dd de
ZeG dd deZeG dd de
ZeG dd deZeG dd de
ZeG dd de
ZeG dd de
ZeG dd de
Z	 eG d d! d!eZeG d"d# d#eZeG d$d% d%ZeG d&d' d'eZd(ed)efd*d+Zd(ed,eeeef  d-efd.d/Zee
eeeeee	eeeeeeed0Zd1S )2    )	dataclass)partial)AnyDictOptionalc                   @      e Zd ZU dZdZeed< dS )SchedulerParams
    Base configuration for all schedulers.
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    
last_epochN)__name__
__module____qualname____doc__r   int__annotations__ r   r   O/home/ubuntu/.local/lib/python3.10/site-packages/nemo/core/config/schedulers.pyr         
 r   c                   @   s2   e Zd ZU dZdZee ed< dZee ed< dS )!SquareRootConstantSchedulerParamsr	   Nconstant_stepsconstant_ratio)	r   r   r   r   r   r   floatr   r   r   r   r   r   r      s   
 r   c                   @   s>   e Zd ZU dZdZeed< dZee	 ed< dZ
ee	 ed< dS )WarmupSchedulerParamsr	   r   	max_stepsNwarmup_stepswarmup_ratio)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )   s
   
 r   c                   @   >   e Zd ZU dZdZee ed< dZee ed< dZ	eed< dS )WarmupHoldSchedulerParamsr	   N
hold_steps
hold_ratio        min_lr)
r   r   r   r   r   r   r   r   r    r"   r   r   r   r   r   5   
   
 r   c                   @   r   )"WarmupAnnealingHoldSchedulerParamsr	   Nr   r   r!   r"   )
r   r   r   r   r   r   r   r   r   r"   r   r   r   r   r$   A   r#   r$   c                   @   r   )SquareAnnealingParamsz
    Square Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    gh㈵>r"   Nr   r   r   r   r"   r   r   r   r   r   r   r%   M   r   r%   c                   @   r   )SquareRootAnnealingParamsz
    Square Root Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    r!   r"   Nr&   r   r   r   r   r'   W   r   r'   c                   @   r   )CosineAnnealingParams
    Cosine Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    r!   r"   Nr&   r   r   r   r   r(   a   r   r(   c                   @   r   )NoamAnnealingParamsr)   r!   r"   Nr&   r   r   r   r   r*   k   r   r*   c                   @   r   )NoamHoldAnnealingParams
    Polynomial Hold Decay Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    g      ?
decay_rateN)r   r   r   r   r-   r   r   r   r   r   r   r+   u   r   r+   c                   @   s"   e Zd ZU dZdZee ed< dS )WarmupAnnealingParamsz
    Warmup Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    Nr   )r   r   r   r   r   r   r   r   r   r   r   r   r.      s   
 r.   c                   @   s   e Zd ZdZdS ) InverseSquareRootAnnealingParamsz
    Inverse Square Root Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    N)r   r   r   r   r   r   r   r   r/      s    r/   c                   @   *   e Zd ZU dZdZeed< dZeed< dS )PolynomialDecayAnnealingParamsz
    Polynomial Decay Annealing parameter config
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
          ?powerFcycleN	r   r   r   r   r3   r   r   r4   boolr   r   r   r   r1         
 r1   c                   @   r0   )"PolynomialHoldDecayAnnealingParamsr,   r2   r3   Fr4   Nr5   r   r   r   r   r8      r7   r8   c                   @   s*   e Zd ZU dZdZeed< dZeed< dS )StepLRParamsz
    Config for StepLR.
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    皙?	step_sizegammaN)r   r   r   r   r;   r   r   r<   r   r   r   r   r9      r7   r9   c                   @   r   )ExponentialLRParamsz
    Config for ExponentialLR.
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    ?r<   N)r   r   r   r   r<   r   r   r   r   r   r   r=      r   r=   c                   @   s~   e Zd ZU dZdZeed< dZeed< dZ	e
ed< dZeed	< d
Zeed< dZeed< dZe
ed< dZeed< dZeed< dS )ReduceLROnPlateauParamsz
    Config for ReduceLROnPlateau.
    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    minmoder:   factor
   patienceFverboseg-C6?	thresholdrelthreshold_moder   cooldownr"   g:0yE>epsN)r   r   r   r   rA   strr   rB   r   rD   r   rE   r6   rF   rH   rI   r"   rJ   r   r   r   r   r?      s   
 r?   c                   @   s   e Zd ZU dZdZeed< dZeed< dZe	ed< dZ
ee	 ed	< d
Zeed< dZeed< dZeed< dZeed< dZeed< dZeed< dS )CyclicLRParamsz
    Config for CyclicLR.
    NOTE:
    # `scale_fn` is not supported

    It is not derived from Config as it is not a NeMo object (and in particular it doesn't need a name).
    gMbP?base_lrr:   max_lri  step_size_upNstep_size_down
triangularrA   r2   r<   r4   
scale_modeTcycle_momentumg?base_momentumr>   max_momentum)r   r   r   r   rM   r   r   rN   rO   r   rP   r   rA   rK   r<   rR   rS   r6   rT   rU   r   r   r   r   rL      s   
 rL   namescheduler_paramsc                 C   s"   | t v rtd|  |t | < dS )aF  
    Checks if the schduler config name exists in the registry, and if it doesnt, adds it.

    This allows custom schedulers to be added and called by name during instantiation.

    Args:
        name: Name of the optimizer. Will be used as key to retrieve the optimizer.
        scheduler_params: SchedulerParams class
    zFCannot override pre-existing optimizers. Conflicting optimizer name = N)AVAILABLE_SCHEDULER_PARAMS
ValueError)rV   rW   r   r   r   register_scheduler_params   s   
rZ   kwargsreturnc                 K   s<   | t vrtd|  dt   t |  }t|fi |}|S )aC  
    Convenience method to obtain a SchedulerParams class and partially instantiate it with optimizer kwargs.

    Args:
        name: Name of the SchedulerParams in the registry.
        kwargs: Optional kwargs of the optimizer used during instantiation.

    Returns:
        a partially instantiated SchedulerParams
    z%Cannot resolve scheduler parameters 'z('. Available scheduler parameters are : )rX   rY   keysr   )rV   r[   rW   r   r   r   get_scheduler_config   s   r^   )r   WarmupPolicyParamsWarmupHoldPolicyParamsr$   r%   r'   r/   r   r(   r*   r+   r.   r1   r8   r?   N)dataclassesr   	functoolsr   typingr   r   r   r   r   r   r   r$   r%   r'   r(   r*   r+   r.   r/   r1   r8   r9   r=   r?   rL   rK   rZ   r^   rX   r   r   r   r   <module>   st   	
						


	"
