§
    ‚ŠtjïÖ  ã                  óÖ  — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	Z	ddl
mZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ  ej        e¦  «        ZdRd„ZdSdTd„ZdUd„ZdVd„ZdSdWd„ZdXd„ZdSd„ZdYd„Z 	 dZd[d„Z!d\d „Z"	 d]d^d!„Z#d_d%„Z$	 d`d(„Z%dd)œdad,„Z&	 dbdcd-„Z'd.d/œddd1„Z 	 	 	 	 dedfd4„Z(d.dd5œdgd7„Z)	 	 	 	 	 dhdid8„Z*djd?„Z+	 	 	 	 	 	 	 dkdldB„Z, G dC„ dD¦  «        Z- G dE„ dF¦  «        Z.dUdG„Z/ej0        eej1        e!ej2        e#ej3        e%ej4        eej5        eej6        e'ej7        eej8        e(ej9        e*ej:        e,ej;        e/iZ<	 	 	 dmdndL„Z= G dM„ dNe¦  «        Z> G dO„ dPe¦  «        Z?dodQ„Z@dS )pz$PyTorch optimization for BERT model.é    )ÚannotationsN)Úpartial)ÚAny)Ú	Optimizer)ÚLambdaLRÚReduceLROnPlateaué   )ÚLayerWiseDummyOptimizerÚLayerWiseDummyScheduler)ÚSchedulerType)Úloggingc                ó   — dS ©Nr	   © )Ú_s    úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/optimization.pyÚ_get_constant_lambdar   #   s   € Øˆ1ó    éÿÿÿÿÚ	optimizerr   Ú
last_epochÚintc                ó0   — t          | t          |¬¦  «        S )a²  
    Create a schedule with a constant learning rate, using the learning rate set in optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    ©r   )r   r   )r   r   s     r   Úget_constant_scheduler   '   s   € õ �IÕ3À
ÐKÑKÔKÐKr   c                ó   — t          | fi |¤ŽS )a  
    Create a schedule with a constant learning rate that decreases when a metric has stopped improving.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        kwargs (`dict`, *optional*):
            Extra parameters to be passed to the scheduler. See `torch.optim.lr_scheduler.ReduceLROnPlateau`
            for possible parameters.

    Return:
        `torch.optim.lr_scheduler.ReduceLROnPlateau` with the appropriate schedule.
    )r   ©r   Úkwargss     r   Úget_reduce_on_plateau_scheduler   8   s   € õ ˜YÐ1Ð1¨&Ð1Ð1Ð1r   Úcurrent_stepÚnum_warmup_stepsc               ól   — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S dS )Nç      ð?©ÚfloatÚmax)r    r!   s     r   Ú,_get_constant_schedule_with_warmup_lr_lambdar'   J   s9   € ØÐ&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨sÐ4DÑ+EÔ+EÑ%FÔ%FÑFÐFØˆ3r   c                óR   — t          t          |¬¦  «        }t          | ||¬¦  «        S )ad  
    Create a schedule with a constant learning rate preceded by a warmup period during which the learning rate
    increases linearly between 0 and the initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    ©r!   r   )r   r'   r   )r   r!   r   Ú	lr_lambdas       r   Ú!get_constant_schedule_with_warmupr+   P   s-   € õ" ÕDÐWgÐhÑhÔh€IÝ�I˜y°ZÐ@Ñ@Ô@Ð@r   Únum_training_stepsc               óê   — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S t          dt          || z
  ¦  «        t          t          d||z
  ¦  «        ¦  «        z  ¦  «        S )Nr	   ç        r$   )r    r!   r,   s      r   Ú*_get_linear_schedule_with_warmup_lr_lambdar/   e   sp   € ØÐ&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDÝˆs•EÐ,¨|Ñ;Ñ<Ô<½uÅSÈÐL^ÐaqÑLqÑErÔErÑ?sÔ?sÑsÑtÔtÐtr   c                óR   — t          t          ||¬¦  «        }t          | ||¦  «        S )aÝ  
    Create a schedule with a learning rate that decreases linearly from the initial lr set in the optimizer to 0, after
    a warmup period during which it increases linearly from 0 to the initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    ©r!   r,   )r   r/   r   )r   r!   r,   r   r*   s        r   Úget_linear_schedule_with_warmupr2   k   s5   € õ& Ý2Ø)Ø-ðñ ô €Iõ
 �I˜y¨*Ñ5Ô5Ð5r   Ú
num_cyclesr%   c               ó^  — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S t          | |z
  ¦  «        t          t          d||z
  ¦  «        ¦  «        z  }t          dddt          j        t          j        t          |¦  «        z  dz  |z  ¦  «        z   z  ¦  «        S )Nr	   r.   ç      à?r#   ç       @©r%   r&   ÚmathÚcosÚpi©r    r!   r,   r3   Úprogresss        r   Ú*_get_cosine_schedule_with_warmup_lr_lambdar=   †   s¤   € ð Ð&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDÝ�\Ð$4Ñ4Ñ5Ô5½½cÀ!ÐEWÐZjÑEjÑ>kÔ>kÑ8lÔ8lÑl€HÝˆs�C˜3¥¤­$¬'µE¸*Ñ4EÔ4EÑ*EÈÑ*KÈhÑ*VÑ!WÔ!WÑWÑXÑYÔYÐYr   r5   c                óT   — t          t          |||¬¦  «        }t          | ||¦  «        S )aÝ  
    Create a schedule with a learning rate that decreases following the values of the cosine function between the
    initial lr set in the optimizer to 0, after a warmup period during which it increases linearly between 0 and the
    initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        num_cycles (`float`, *optional*, defaults to 0.5):
            The number of waves in the cosine schedule (the defaults is to just decrease from the max value to 0
            following a half-cosine).
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    ©r!   r,   r3   )r   r=   r   ©r   r!   r,   r3   r   r*   s         r   Úget_cosine_schedule_with_warmuprA   �   s8   € õ2 Ý2Ø)Ø-Øð	ñ ô €Iõ �I˜y¨*Ñ5Ô5Ð5r   c               ón  — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S t          | |z
  ¦  «        t          t          d||z
  ¦  «        ¦  «        z  }|dk    rdS t          dddt          j        t          j        t          |¦  «        |z  dz  z  ¦  «        z   z  ¦  «        S )Nr	   r#   r.   r5   r7   r;   s        r   Ú=_get_cosine_with_hard_restarts_schedule_with_warmup_lr_lambdarC   ±   s³   € ð Ð&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDÝ�\Ð$4Ñ4Ñ5Ô5½½cÀ!ÐEWÐZjÑEjÑ>kÔ>kÑ8lÔ8lÑl€HØ�3‚€ØˆsÝˆs�C˜3¥¤­$¬'µe¸JÑ6GÔ6GÈ(Ñ6RÐVYÑ5YÑ*ZÑ![Ô![Ñ[Ñ\Ñ]Ô]Ð]r   c                óT   — t          t          |||¬¦  «        }t          | ||¦  «        S )aŽ  
    Create a schedule with a learning rate that decreases following the values of the cosine function between the
    initial lr set in the optimizer to 0, with several hard restarts, after a warmup period during which it increases
    linearly between 0 and the initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        num_cycles (`int`, *optional*, defaults to 1):
            The number of hard restarts to use.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    r?   )r   rC   r   r@   s         r   Ú2get_cosine_with_hard_restarts_schedule_with_warmuprE   ¼   s8   € õ0 ÝEØ)Ø-Øð	ñ ô €Iõ �I˜y¨*Ñ5Ô5Ð5r   Úlr_endÚpowerÚlr_initc               óÈ   — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S | |k    r||z  S ||z
  }||z
  }d| |z
  |z  z
  }|||z  z  |z   }	|	|z  S r   r$   )
r    r!   r,   rF   rG   rH   Úlr_rangeÚdecay_stepsÚpct_remainingÚdecays
             r   Ú4_get_polynomial_decay_schedule_with_warmup_lr_lambdarN   Ý   s•   € ð Ð&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDØ	Ð*Ò	*Ð	*Ø˜ÑÐà˜VÑ#ˆØ(Ð+;Ñ;ˆØ˜\Ð,<Ñ<ÀÑKÑKˆØ˜=¨%Ñ/Ñ/°&Ñ8ˆØ�w‰Ðr   çH¯¼šò×z>r#   c                óª   — | j         d         }||k    st          d|› d|› d�¦  «        ‚t          t          |||||¬¦  «        }t	          | ||¦  «        S )a�  
    Create a schedule with a learning rate that decreases as a polynomial decay from the initial lr set in the
    optimizer to end lr defined by *lr_end*, after a warmup period during which it increases linearly from 0 to the
    initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        lr_end (`float`, *optional*, defaults to 1e-7):
            The end LR.
        power (`float`, *optional*, defaults to 1.0):
            Power factor.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Note: *power* defaults to 1.0 as in the fairseq implementation, which in turn is based on the original BERT
    implementation at
    https://github.com/google-research/bert/blob/f39e881b169b9d53bea03d2d341b31707a6c052b/optimization.py#L37

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.

    Úlrzlr_end (z#) must be smaller than initial lr (ú))r!   r,   rF   rG   rH   )ÚdefaultsÚ
ValueErrorr   rN   r   )r   r!   r,   rF   rG   r   rH   r*   s           r   Ú)get_polynomial_decay_schedule_with_warmuprU   ò   sx   € ð> Ô  Ô&€GØ�fÒÐÝÐY FÐYÐYÈwÐYÐYÐYÑZÔZÐZåÝ<Ø)Ø-ØØØðñ ô €Iõ �I˜y¨*Ñ5Ô5Ð5r   )Ú	timescalerV   ú
int | Nonec               ó°   — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S ||z
  }dt          j        | |z   |z  ¦  «        z  }|S )Nr	   r#   )r%   r&   r8   Úsqrt)r    r!   rV   ÚshiftrM   s        r   Ú$_get_inverse_sqrt_schedule_lr_lambdar[      sb   € ØÐ&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDØÐ(Ñ(€EØ•$”)˜\¨EÑ1°YÑ>Ñ?Ô?Ñ?€EØ€Lr   c                ó`   — |€|pd}t          t          ||¬¦  «        }t          | ||¬¦  «        S )aÚ  
    Create a schedule with an inverse square-root learning rate, from the initial lr set in the optimizer, after a
    warmup period which increases lr linearly from 0 to the initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        timescale (`int`, *optional*, defaults to `num_warmup_steps`):
            Time scale.
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    Ni'  )r!   rV   r   )r   r[   r   )r   r!   rV   r   r*   s        r   Úget_inverse_sqrt_scheduler]   (  s@   € ð. ÐØ$Ð.¨ˆ	åÕ<ÐO_ÐktÐuÑuÔu€IÝ�I˜y°ZÐ@Ñ@Ô@Ð@r   r.   )Úmin_lr_rater^   c               óx  — | |k     r-t          | ¦  «        t          t          d|¦  «        ¦  «        z  S t          | |z
  ¦  «        t          t          d||z
  ¦  «        ¦  «        z  }ddt          j        t          j        t          |¦  «        z  dz  |z  ¦  «        z   z  }|d|z
  z  |z   }t          d|¦  «        S )Nr	   r5   r#   r6   r   r7   )r    r!   r,   r3   r^   r<   Úfactors          r   r=   r=   F  sº   € ð Ð&Ò&Ð&Ý�\Ñ"Ô"¥U­3¨qÐ2BÑ+CÔ+CÑ%DÔ%DÑDÐDÝ�\Ð$4Ñ4Ñ5Ô5½½cÀ!ÐEWÐZjÑEjÑ>kÔ>kÑ8lÔ8lÑl€HØ�C�$œ(¥4¤7­U°:Ñ->Ô->Ñ#>ÀÑ#DÀxÑ#OÑPÔPÑPÑQ€FØ�q˜;‘Ñ'¨+Ñ5€FÝˆq�&‰>Œ>Ðr   Úmin_lrúfloat | Nonec                óÄ   — |�|�t          d¦  «        ‚|�|| j        d         z  }n|€t          d¦  «        ‚t          t          ||||¬¦  «        }t	          | ||¦  «        S )að  
    Create a schedule with a learning rate that decreases following the values of the cosine function between the
    initial lr set in the optimizer to min_lr, after a warmup period during which it increases linearly between 0 and the
    initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        num_cycles (`float`, *optional*, defaults to 0.5):
            The number of waves in the cosine schedule (the defaults is to just decrease from the max value to 0
            following a half-cosine).
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.
        min_lr (`float`, *optional*):
            The minimum learning rate to reach after the cosine schedule.
        min_lr_rate (`float`, *optional*):
            The minimum learning rate as a ratio of the initial learning rate. If set, `min_lr` should not be set.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    Nú/Only one of min_lr or min_lr_rate should be setrQ   úLOne of min_lr or min_lr_rate should be set through the `lr_scheduler_kwargs`)r!   r,   r3   r^   )rT   rS   r   r=   r   )r   r!   r,   r3   r   ra   r^   r*   s           r   Ú+get_cosine_with_min_lr_schedule_with_warmuprf   Q  s…   € ðF Ð˜kÐ5ÝÐJÑKÔKÐKØ	Ð	Ø˜yÔ1°$Ô7Ñ7ˆˆØ	Ð	ÝÐgÑhÔhÐhåÝ2Ø)Ø-ØØðñ ô €Iõ �I˜y¨*Ñ5Ô5Ð5r   )r^   Úwarmup_lr_raterg   c               ó¼  — t          | ¦  «        } t          |¦  «        }t          |¦  «        }| |k     rF|€| dz   t          d|¦  «        z  S t          |¦  «        }|d|z
  | z  t          d|dz
  ¦  «        z  z   S | |z
  dz   t          d||z
  ¦  «        z  }ddt          j        t          j        |z  dz  |z  ¦  «        z   z  }|d|z
  z  |z   }t          d|¦  «        S )Nr#   r	   r5   r6   r   r7   )r    r!   r,   r3   r^   rg   r<   r`   s           r   Ú;_get_cosine_with_min_lr_schedule_with_warmup_lr_rate_lambdari   …  s  € õ ˜Ñ&Ô&€LÝÐ-Ñ.Ô.ÐÝÐ1Ñ2Ô2ÐàÐ&Ò&Ð&ØÐ!Ø  3Ñ&­#¨cÐ3CÑ*DÔ*DÑDÐDå" >Ñ2Ô2ˆNØ! S¨>Ñ%9¸lÑ$KÍsÐSTÐVfÐijÑVjÑOkÔOkÑ$lÑlÐlØÐ/Ñ/°#Ñ5½#¸cÐCUÐXhÑChÑ:iÔ:iÑj€HØ�C�$œ(¥4¤7¨ZÑ#7¸#Ñ#=ÀÑ#HÑIÔIÑIÑJ€FØ�q˜;‘Ñ'¨+Ñ5€FÝˆq�&‰>Œ>Ðr   c                óÆ   — |�|�t          d¦  «        ‚|�|| j        d         z  }n|€t          d¦  «        ‚t          t          |||||¬¦  «        }t	          | ||¦  «        S )a¶  
    Create a schedule with a learning rate that decreases following the values of the cosine function between the
    initial lr set in the optimizer to min_lr, after a warmup period during which it increases linearly between 0 and the
    initial lr set in the optimizer.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_training_steps (`int`):
            The total number of training steps.
        num_cycles (`float`, *optional*, defaults to 0.5):
            The number of waves in the cosine schedule (the defaults is to just decrease from the max value to 0
            following a half-cosine).
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.
        min_lr (`float`, *optional*):
            The minimum learning rate to reach after the cosine schedule.
        min_lr_rate (`float`, *optional*):
            The minimum learning rate as a ratio of the initial learning rate. If set, `min_lr` should not be set.
        warmup_lr_rate (`float`, *optional*):
            The minimum learning rate as a ratio of the start learning rate. If not set, `warmup_lr_rate` will be treated as float(1/num_warmup_steps).

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    Nrd   rQ   re   )r!   r,   r3   r^   rg   )rT   rS   r   ri   r   )	r   r!   r,   r3   r   ra   r^   rg   r*   s	            r   Ú3get_cosine_with_min_lr_schedule_with_warmup_lr_raterk   ž  sˆ   € ðL Ð˜kÐ5ÝÐJÑKÔKÐKØ	Ð	Ø˜yÔ1°$Ô7Ñ7ˆˆØ	Ð	ÝÐgÑhÔhÐhåÝCØ)Ø-ØØØ%ðñ ô €Iõ �I˜y¨*Ñ5Ô5Ð5r   Únum_stable_stepsÚnum_decay_stepsÚwarmup_typeÚstrÚ
decay_typeÚmin_lr_ratioc               óî  — | |k     rŸt          | ¦  «        t          t          d|¦  «        ¦  «        z  }|dk    r|}	nN|dk    r(ddt          j        t          j        |z  ¦  «        z
  z  }	n |dk    rdt          j        d|z
  ¦  «        z
  }	|	d|z
  z  |z   }	t          d|	¦  «        S | ||z   k     rdS | ||z   |z   k     r¸t          | |z
  |z
  ¦  «        t          t          d|¦  «        ¦  «        z  }|dk    rd|z
  }	n^|dk    r;ddt          j        t          j        t          |¦  «        z  dz  |z  ¦  «        z   z  }	n|dk    rdt          j        |¦  «        z
  }	|	d|z
  z  |z   }	t          d|	¦  «        S |S )	Nr	   ÚlinearÚcosiner5   r#   ú1-sqrtr.   r6   )r%   r&   r8   r9   r:   rY   )
r    r!   rl   rm   rn   rp   rq   r3   r<   r`   s
             r   Ú_get_wsd_scheduler_lambdarv   Ö  sº  € ð Ð&Ò&Ð&Ý˜Ñ&Ô&­­s°1Ð6FÑ/GÔ/GÑ)HÔ)HÑHˆØ˜(Ò"Ð"ØˆFˆFØ˜HÒ$Ð$Ø˜C¥$¤(­4¬7°XÑ+=Ñ">Ô">Ñ>Ñ?ˆFˆFØ˜HÒ$Ð$Ø�4œ9 S¨8¡^Ñ4Ô4Ñ4ˆFØ˜3 Ñ-Ñ.°Ñ=ˆÝ�3˜ÑÔÐàÐ&Ð)9Ñ9Ò9Ð9ØˆsàÐ&Ð)9Ñ9¸OÑKÒKÐKÝ˜Ð(8Ñ8Ð;KÑKÑLÔLÍuÕUXÐYZÐ\kÑUlÔUlÑOmÔOmÑmˆØ˜Ò!Ð!Ø˜8‘^ˆFˆFØ˜8Ò#Ð#Ø˜C¥$¤(­4¬7µU¸:Ñ5FÔ5FÑ+FÈÑ+LÈxÑ+WÑ"XÔ"XÑXÑYˆFˆFØ˜8Ò#Ð#Ø�4œ9 XÑ.Ô.Ñ.ˆFØ˜3 Ñ-Ñ.°Ñ=ˆÝ�3˜ÑÔÐØÐr   rs   rt   c
           
     ó"  — |€|€t          d¦  «        ‚|�|�t          j        d¦  «         |dvrt          d|› d�¦  «        ‚|dvrt          d|› d�¦  «        ‚|€||z
  |z
  }t          t          |||||||¬¦  «        }
t          | |
|	¦  «        S )	aÿ  
    Create a schedule with a learning rate that has three stages:
    1. warmup: increase from min_lr_ratio times the initial learning rate to the initial learning rate following a warmup_type.
    2. stable: constant learning rate.
    3. decay: decrease from the initial learning rate to min_lr_ratio times the initial learning rate following a decay_type.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        num_warmup_steps (`int`):
            The number of steps for the warmup phase.
        num_decay_steps (`int`):
            The number of steps for the decay phase.
        num_training_steps (`int`, *optional*):
            The total number of training steps. This is the sum of the warmup, stable and decay steps. If `num_stable_steps` is not provided, the stable phase will be `num_training_steps - num_warmup_steps - num_decay_steps`.
        num_stable_steps (`int`, *optional*):
            The number of steps for the stable phase. Please ensure that `num_warmup_steps + num_stable_steps + num_decay_steps` equals `num_training_steps`, otherwise the other steps will default to the minimum learning rate.
        warmup_type (`str`, *optional*, defaults to "linear"):
            The type of warmup to use. Can be 'linear', 'cosine' or '1-sqrt'.
        decay_type (`str`, *optional*, defaults to "cosine"):
            The type of decay to use. Can be 'linear', 'cosine' or '1-sqrt'.
        min_lr_ratio (`float`, *optional*, defaults to 0):
            The minimum learning rate as a ratio of the initial learning rate.
        num_cycles (`float`, *optional*, defaults to 0.5):
            The number of waves in the cosine schedule (the defaults is to just decrease from the max value to 0
            following a half-cosine).
        last_epoch (`int`, *optional*, defaults to -1):
            The index of the last epoch when resuming training.

    Return:
        `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
    Nz@Either num_training_steps or num_stable_steps must be specified.zZBoth num_training_steps and num_stable_steps are specified. num_stable_steps will be used.)rs   rt   ru   zUnknown warmup type: z), expected 'linear', 'cosine' or '1-sqrt'zUnknown decay type: )r!   rl   rm   rn   rp   rq   r3   )rT   ÚwarningsÚwarnr   rv   r   )r   r!   rm   r,   rl   rn   rp   rq   r3   r   r*   s              r   Úget_wsd_schedulerz   ü  sà   € ðZ Ð!Ð&6Ð&>ÝÐ[Ñ\Ô\Ð\àÐ%Ð*:Ð*FÝŒÐrÑsÔsÐsàÐ8Ð8Ð8ÝÐg°ÐgÐgÐgÑhÔhÐhàÐ7Ð7Ð7ÝÐe°
ÐeÐeÐeÑfÔfÐfàÐØ-Ð0@Ñ@À?ÑRÐåÝ!Ø)Ø)Ø'ØØØ!Øð	ñ 	ô 	€Iõ �I˜y¨*Ñ5Ô5Ð5r   c                  ó2   — e Zd ZdZdd„Zdd	„Zdd„Zdd„ZdS )ÚStreamingAverageaB  Rolling window average for smoothing metric values.

    Maintains a sliding window of values and computes their average,
    useful for smoothing noisy metric values before making learning rate decisions.

    Args:
        window_size (`int`):
            The maximum number of values to keep in the rolling window.
    Úwindow_sizer   ÚreturnÚNonec                ó0   — || _         g | _        d| _        d S )Nr.   ©r}   ÚvaluesÚsum)Úselfr}   s     r   Ú__init__zStreamingAverage.__init__P  s   € Ø +ˆÔØ#%ˆŒØˆŒˆˆr   Úvaluer%   c                ó  — | j                              |¦  «         | xj        |z  c_        t          | j         ¦  «        | j        k    r*| j                              d¦  «        }| xj        |z  c_        | j        t          | j         ¦  «        z  S )z3Add a value and return the current rolling average.r   )r‚   Úappendrƒ   Úlenr}   Úpop)r„   r†   Úremoveds      r   Ú	streamavgzStreamingAverage.streamavgU  sz   € àŒ×Ò˜5Ñ!Ô!Ð!ØˆŒ�EÑˆŒåˆtŒ{ÑÔ˜dÔ.Ò.Ð.Ø”k—o’o aÑ(Ô(ˆGØˆHŒH˜ÑˆHŒHàŒx�#˜dœkÑ*Ô*Ñ*Ð*r   údict[str, Any]c                óP   — | j         | j                             ¦   «         | j        dœS )Nr�   )r}   r‚   Úcopyrƒ   ©r„   s    r   Ú
state_dictzStreamingAverage.state_dict`  s-   € àÔ+Ø”k×&Ò&Ñ(Ô(Ø”8ð
ð 
ð 	
r   r‘   c                óÖ   — |                      d| j        ¦  «        | _        |                      dg ¦  «                             ¦   «         | _        |                      dd¦  «        | _        d S )Nr}   r‚   rƒ   r.   )Úgetr}   r�   r‚   rƒ   )r„   r‘   s     r   Úload_state_dictz StreamingAverage.load_state_dictg  sU   € Ø%Ÿ>š>¨-¸Ô9IÑJÔJˆÔØ —n’n X¨rÑ2Ô2×7Ò7Ñ9Ô9ˆŒØ—>’> %¨Ñ-Ô-ˆŒˆˆr   N)r}   r   r~   r   )r†   r%   r~   r%   ©r~   r�   ©r‘   r�   r~   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r…   rŒ   r‘   r”   r   r   r   r|   r|   E  sn   € € € € € ðð ðð ð ð ð
	+ð 	+ð 	+ð 	+ð
ð 
ð 
ð 
ð.ð .ð .ð .ð .ð .r   r|   c                  óz   — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7d8d%„Zd9d:d*„Zd;d-„Zd<d.„Zd<d/„Zd=d0„Z	d>d2„Z
d?d4„Zd@d6„Zd&S )AÚGreedyLRa�  Adaptive learning rate scheduler that responds to training metrics.

    GreedyLR dynamically adjusts the learning rate based on training performance:
    - Increases LR when metrics improve consistently (divides by factor)
    - Decreases LR when metrics plateau (multiplies by factor)

    This differs from traditional schedulers like cosine annealing by responding
    to actual training dynamics rather than following a predetermined schedule.

    Reference: `GreedyLR: A Novel Adaptive Learning Rate Scheduler <https://arxiv.org/abs/2512.14527>`_

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        mode (`str`, *optional*, defaults to `"min"`):
            One of 'min' or 'max'. In 'min' mode, LR will be reduced when the
            metric has stopped decreasing; in 'max' mode when it has stopped increasing.
        factor (`float`, *optional*, defaults to 0.95):
            Factor by which the learning rate will be adjusted. LR is multiplied by
            factor on plateau and divided by factor on improvement. Must be < 1.0.
        patience (`int`, *optional*, defaults to 10):
            Number of epochs with no improvement after which learning rate will be adjusted.
        threshold (`float`, *optional*, defaults to 1e-06):
            Threshold for measuring the new optimum.
        threshold_mode (`str`, *optional*, defaults to `"abs"`):
            One of 'rel' or 'abs'.
        cooldown (`int`, *optional*, defaults to 0):
            Number of epochs to wait before resuming normal operation after LR has been reduced.
        warmup (`int`, *optional*, defaults to 0):
            Number of epochs to wait before resuming normal operation after LR has been increased.
        min_lr (`float` or `list[float]`, *optional*, defaults to 0.001):
            A lower bound on the learning rate.
        max_lr (`float` or `list[float]`, *optional*, defaults to 1.0):
            An upper bound on the learning rate.
        eps (`float`, *optional*, defaults to 1e-08):
            Minimal decay applied to lr.
        verbose (`bool`, *optional*, defaults to `False`):
            If True, prints a message to stdout for each update.
        smooth (`bool`, *optional*, defaults to `False`):
            If True, applies streaming average smoothing to metrics.
        window_size (`int`, *optional*, defaults to 50):
            The window size for the streaming average when smooth=True.
        reset_start (`int`, *optional*, defaults to 500):
            Number of steps to wait at min_lr before resetting to initial state.

    Example:
        ```python
        >>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
        >>> scheduler = GreedyLR(optimizer, mode="min", patience=10)
        >>> for epoch in range(100):
        ...     train(...)
        ...     val_loss = validate(...)
        ...     scheduler.step(val_loss)
        ```
    Úminçffffffî?é
   ç�íµ ÷Æ°>Úabsr   çü©ñÒMbP?r#   ç:Œ0âŽyE>Fé2   éô  r   r   Úmodero   r`   r%   Úpatiencer   Ú	thresholdÚthreshold_modeÚcooldownÚwarmupra   úfloat | list[float]Úmax_lrÚepsÚverboseÚboolÚsmoothr}   Úreset_startr~   r   c                óœ  — |dk    rt          d¦  «        ‚t          |t          ¦  «        s$t          t	          |¦  «        j        › d�¦  «        ‚|| _        || _        || _        || _	        || _
        || _        d| _        d| _        || _        || _        || _        || _        || _        || _        || _        || _        d| _        t          |	t.          t0          f¦  «        rnt3          |	¦  «        t3          |j        ¦  «        k    r4t          dt3          |j        ¦  «        › dt3          |	¦  «        › �¦  «        ‚t/          |	¦  «        | _        n|	gt3          |j        ¦  «        z  | _        t          |
t.          t0          f¦  «        rnt3          |
¦  «        t3          |j        ¦  «        k    r4t          dt3          |j        ¦  «        › dt3          |
¦  «        › �¦  «        ‚t/          |
¦  «        | _        n|
gt3          |j        ¦  «        z  | _        d„ |j        D ¦   «         | _        | j                             ¦   «         | _        |d	k    rtA          d
¦  «        ntA          d¦  «        | _!        d| _"        d| _#        |dvrt          d|› d�¦  «        ‚|dvrt          d|› d�¦  «        ‚d | _$        |rtK          |¦  «        | _$        d S d S )Nr#   zFactor should be < 1.0.z is not an Optimizerr   z	expected z min_lrs, got z max_lrs, got c                ó   — g | ]
}|d          ‘ŒS ©rQ   r   ©Ú.0Úgroups     r   ú
<listcomp>z%GreedyLR.__init__.<locals>.<listcomp>Ý  s   € ÐJÐJÐJ¨%˜% œ+ÐJÐJÐJr   r�   Úinfú-inf)r�   r&   zmode z is unknown!)Úrelr¡   zthreshold mode )&rT   Ú
isinstancer   Ú	TypeErrorÚtyper—   r   r`   r§   r¯   rª   r«   Úcooldown_counterÚwarmup_counterr¦   r¨   r©   r®   r±   r}   r²   Úreset_start_originalr   ÚlistÚtupler‰   Úparam_groupsÚmin_lrsÚmax_lrsÚ	_init_lrsr�   Ú_last_lrr%   ÚbestÚnum_bad_epochsÚnum_good_epochsÚ_streaming_avgr|   )r„   r   r¦   r`   r§   r¨   r©   rª   r«   ra   r­   r®   r¯   r±   r}   r²   s                   r   r…   zGreedyLR.__init__¦  sÃ  € ð$ �SŠ=ˆ=ÝÐ6Ñ7Ô7Ð7Ý˜)¥YÑ/Ô/ð 	OÝ�t I™œÔ7ÐMÐMÐMÑNÔNÐNà"ˆŒØˆŒØ ˆŒØˆŒØ ˆŒØˆŒØ !ˆÔØˆÔØˆŒ	Ø"ˆŒØ,ˆÔØˆŒØˆŒØ&ˆÔØ&ˆÔØ$/ˆÔ!ØˆŒå�f�t¥U˜mÑ,Ô,ð 	BÝ�6‰{Œ{�c )Ô"8Ñ9Ô9Ò9Ð9Ý Ð!e­S°Ô1GÑ-HÔ-HÐ!eÐ!eÕX[Ð\bÑXcÔXcÐ!eÐ!eÑfÔfÐfÝ ™<œ<ˆDŒLˆLà"˜8¥c¨)Ô*@Ñ&AÔ&AÑAˆDŒLå�f�t¥U˜mÑ,Ô,ð 	BÝ�6‰{Œ{�c )Ô"8Ñ9Ô9Ò9Ð9Ý Ð!e­S°Ô1GÑ-HÔ-HÐ!eÐ!eÕX[Ð\bÑXcÔXcÐ!eÐ!eÑfÔfÐfÝ ™<œ<ˆDŒLˆLà"˜8¥c¨)Ô*@Ñ&AÔ&AÑAˆDŒLàJÐJ°9Ô3IÐJÑJÔJˆŒØœ×+Ò+Ñ-Ô-ˆŒà+/°5ª=¨=�5 ™<œ<˜<½eÀF¹m¼mˆŒ	ØˆÔØ ˆÔà�~Ð%Ð%ÝÐ7 TÐ7Ð7Ð7Ñ8Ô8Ð8Ø Ð/Ð/ÝÐK¨~ÐKÐKÐKÑLÔLÐLà7;ˆÔØð 	@Ý"2°;Ñ"?Ô"?ˆDÔÐÐð	@ð 	@r   NÚmetricsÚepochrW   c                óü  — t          |¦  «        }| j        r!| j        �| j                             |¦  «        }|€
| j        dz   }|| _        | j        dk    r| xj        dz  c_        d| _        d| _        nì| j        dk    r| xj        dz  c_        d| _        d| _        nÂ|  	                    || j
        ¦  «        r|| _
        d| _        | xj        dz  c_        n| xj        dz  c_        d| _        | j        | j        k    r)|                      |¦  «         | j        | _        d| _        n8| j        | j        k    r(|                      |¦  «         | j        | _        d| _        d„ | j        j        D ¦   «         | _        dS )a!  Perform a scheduler step based on the given metrics.

        Args:
            metrics (`float`):
                The metric value to use for LR adjustment decisions.
            epoch (`int`, *optional*):
                The current epoch number. If None, uses internal counter.
        Nr	   r   c                ó   — g | ]
}|d          ‘ŒS rµ   r   r¶   s     r   r¹   z!GreedyLR.step.<locals>.<listcomp>  s   € ÐNÐNÐN¨˜˜tœÐNÐNÐNr   )r%   r±   rÍ   rŒ   r   rÀ   rË   rÌ   rÁ   Ú	is_betterrÊ   r§   Ú_increase_lrr«   Ú
_reduce_lrrª   r   rÅ   rÉ   )r„   rÎ   rÏ   Úcurrents       r   ÚstepzGreedyLR.stepí  sž  € õ ˜‘.”.ˆàŒ;ð 	=˜4Ô.Ð:ØÔ)×3Ò3°GÑ<Ô<ˆGàˆ=Ø”O aÑ'ˆEØˆŒàÔ  1Ò$Ð$ØÐ!Ô! QÑ&Ð!Ô!Ø"#ˆDÔØ#$ˆDÔ Ð ØÔ  1Ò$Ð$ØÐÔ 1Ñ$ÐÔØ"#ˆDÔØ#$ˆDÔ Ð à�~Š~˜g t¤yÑ1Ô1ð )Ø#�”	Ø&'�Ô#ØÐ$Ô$¨Ñ)Ð$Ô$Ð$àÐ#Ô# qÑ(Ð#Ô#Ø'(�Ô$àÔ# d¤mÒ3Ð3Ø×!Ò! %Ñ(Ô(Ð(Ø&*¤k�Ô#Ø'(�Ô$Ð$ØÔ$ t¤}Ò4Ð4Ø—’ Ñ&Ô&Ð&Ø(,¬�Ô%Ø&'�Ô#àNÐN°$´.Ô2MÐNÑNÔNˆŒˆˆr   rÕ   rÊ   c                óÀ   — | j         dk    r*| j        dk    r||d| j        z
  z  k     S ||| j        z
  k     S | j        dk    r||d| j        z   z  k    S ||| j        z   k    S )Nr�   r¼   r#   )r¦   r©   r¨   )r„   rÕ   rÊ   s      r   rÒ   zGreedyLR.is_better  s}   € ØŒ9˜ÒÐØÔ" eÒ+Ð+Ø ¨¨t¬~Ñ)=Ñ!>Ò>Ð>à ¨¬Ñ!6Ò6Ð6àÔ" eÒ+Ð+Ø ¨¨t¬~Ñ)=Ñ!>Ò>Ð>à ¨¬Ñ!6Ò6Ð6r   c           
     ó¼  — d}t          | j        j        ¦  «        D ]Š\  }}t          |d         ¦  «        }t	          || j        z  | j        |         ¦  «        }||z
  | j        k    r&||d<   | j        rt          d|› d|› d|d›d�¦  «         |d         | j        |         k    rd}Œ‹|r1| xj
        d	z  c_
        | j
        d
k    r|                      ¦   «          d S d S d S )NTrQ   úEpoch z": reducing learning rate of group ú to ú.4eú.Fr	   r   )Ú	enumerater   rÅ   r%   r&   r`   rÆ   r®   r¯   Úprintr²   Ú_reset)r„   rÏ   Ú
all_at_minÚiÚparam_groupÚold_lrÚnew_lrs          r   rÔ   zGreedyLR._reduce_lr'  s  € Øˆ
Ý'¨¬Ô(CÑDÔDð 
	#ð 
	#‰NˆAˆ{Ý˜; tÔ,Ñ-Ô-ˆFÝ˜ $¤+Ñ-¨t¬|¸A¬Ñ?Ô?ˆFà˜‰ ¤Ò)Ð)Ø$*�˜DÑ!Ø”<ð bÝÐ` 5Ð`Ð`ÈAÐ`Ð`ÐSYÐ`Ð`Ð`Ð`ÑaÔaÐaà˜4Ô  4¤<°¤?Ò2Ð2Ø"�
øàð 	ØÐÔ Ñ!ÐÔØÔ 1Ò$Ð$Ø—’‘”���ð	ð 	à$Ð$r   c           
     ó4  — t          | j        j        ¦  «        D ]q\  }}t          |d         ¦  «        }t	          || j        z  | j        |         ¦  «        }||z
  | j        k    r&||d<   | j        rt          d|› d|› d|d›d�¦  «         Œr| j
        | _        d S )NrQ   rÙ   z$: increasing learning rate of group rÚ   rÛ   rÜ   )rÝ   r   rÅ   r%   r�   r`   rÇ   r®   r¯   rÞ   rÂ   r²   )r„   rÏ   rá   râ   rã   rä   s         r   rÓ   zGreedyLR._increase_lr:  s¸   € Ý'¨¬Ô(CÑDÔDð 	dð 	d‰NˆAˆ{Ý˜; tÔ,Ñ-Ô-ˆFÝ˜ $¤+Ñ-¨t¬|¸A¬Ñ?Ô?ˆFà˜‰ ¤Ò)Ð)Ø$*�˜DÑ!Ø”<ð dÝÐb 5ÐbÐbÈaÐbÐbÐU[ÐbÐbÐbÐbÑcÔcÐcøàÔ4ˆÔÐÐr   c                óŽ  — t          | j        j        ¦  «        D ]\  }}| j        |         |d<   Œ| j        dk    rt          d¦  «        nt          d¦  «        | _        d| _        d| _        d| _	        d| _
        | j        | _        | j        r | j        �t          | j        ¦  «        | _        | j        rt%          d¦  «         d S d S )NrQ   r�   rº   r»   r   z!Scheduler reset to initial state.)rÝ   r   rÅ   rÈ   r¦   r%   rÊ   rË   rÌ   rÀ   rÁ   rÂ   r²   r±   rÍ   r|   r}   r¯   rÞ   )r„   rá   râ   s      r   rß   zGreedyLR._resetF  sÓ   € Ý'¨¬Ô(CÑDÔDð 	2ð 	2‰NˆAˆ{Ø $¤¨qÔ 1ˆK˜ÑÐà$(¤I°Ò$6Ð$6•E˜%‘L”L�L½EÀ&¹M¼MˆŒ	ØˆÔØ ˆÔØ !ˆÔØˆÔØÔ4ˆÔàŒ;ð 	E˜4Ô.Ð:Ý"2°4Ô3CÑ"DÔ"DˆDÔàŒ<ð 	7ÝÐ5Ñ6Ô6Ð6Ð6Ð6ð	7ð 	7r   úlist[float]c                ó   — | j         S )z8Return last computed learning rate by current scheduler.)rÉ   r�   s    r   Úget_last_lrzGreedyLR.get_last_lrW  s
   € àŒ}Ðr   r�   c                ó¼  — i d| j         “d| j        “d| j        “d| j        “d| j        “d| j        “d| j        “d| j        “d	| j        “d
| j	        “d| j
        “d| j        “d| j        “d| j        “d| j        “d| j        “d| j        “| j        | j        | j        | j        | j        | j        dœ¥}| j        r#| j        �| j                             ¦   «         |d<   |S )z2Return the state of the scheduler as a dictionary.r`   rÆ   rÇ   r§   r¯   rª   r«   rÀ   rÁ   r¦   r¨   r©   rÊ   rË   rÌ   r®   r   )r±   r}   r²   rÂ   rÉ   rÈ   NrÍ   )r`   rÆ   rÇ   r§   r¯   rª   r«   rÀ   rÁ   r¦   r¨   r©   rÊ   rË   rÌ   r®   r   r±   r}   r²   rÂ   rÉ   rÈ   rÍ   r‘   )r„   Ústates     r   r‘   zGreedyLR.state_dict[  s^  € ð
Ø�d”kð
à�t”|ð
ð �t”|ð
ð ˜œð	
ð
 �t”|ð
ð ˜œð
ð �d”kð
ð  Ô 5ð
ð ˜dÔ1ð
ð �D”Ið
ð ˜œð
ð ˜dÔ1ð
ð �D”Ið
ð ˜dÔ1ð
ð ˜tÔ3ð
ð  �4”8ð!
ð" ˜$œ/ð#
ð$ ”kØÔ+ØÔ+Ø$(Ô$=ØœØœð/
ð 
ð 
ˆð4 Œ;ð 	G˜4Ô.Ð:Ø&*Ô&9×&DÒ&DÑ&FÔ&FˆEÐ"Ñ#àˆr   r‘   c                ó®  — |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d	| j	        ¦  «        | _	        |                      d
| j
        ¦  «        | _
        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        |                      d| j        ¦  «        | _        d|v r@| j        €t3          | j        ¦  «        | _        | j                             |d         ¦  «         d|v r*t7          | j        j        | j        ¦  «        D ]\  }}||d<   ŒdS dS )zLoad state from a dictionary.r`   rÆ   rÇ   r§   r¯   rª   r«   rÀ   rÁ   r¦   r¨   r©   rÊ   rË   rÌ   r®   r   r±   r}   r²   rÂ   rÉ   rÈ   rÍ   NrQ   )r“   r`   rÆ   rÇ   r§   r¯   rª   r«   rÀ   rÁ   r¦   r¨   r©   rÊ   rË   rÌ   r®   r   r±   r}   r²   rÂ   rÉ   rÈ   rÍ   r|   r”   Úzipr   rÅ   )r„   r‘   râ   rQ   s       r   r”   zGreedyLR.load_state_dict|  s»  € à —n’n X¨t¬{Ñ;Ô;ˆŒØ!—~’~ i°´Ñ>Ô>ˆŒØ!—~’~ i°´Ñ>Ô>ˆŒØ"Ÿš z°4´=ÑAÔAˆŒØ!—~’~ i°´Ñ>Ô>ˆŒØ"Ÿš z°4´=ÑAÔAˆŒØ —n’n X¨t¬{Ñ;Ô;ˆŒØ *§¢Ð/AÀ4ÔCXÑ YÔ YˆÔØ(ŸnšnÐ-=¸tÔ?RÑSÔSˆÔØ—N’N 6¨4¬9Ñ5Ô5ˆŒ	Ø#Ÿš¨°T´^ÑDÔDˆŒØ(ŸnšnÐ-=¸tÔ?RÑSÔSˆÔØ—N’N 6¨4¬9Ñ5Ô5ˆŒ	Ø(ŸnšnÐ-=¸tÔ?RÑSÔSˆÔØ)Ÿ~š~Ð.?ÀÔAUÑVÔVˆÔØ—>’> %¨¬Ñ2Ô2ˆŒØ$Ÿ.š.¨°t´ÑGÔGˆŒØ —n’n X¨t¬{Ñ;Ô;ˆŒØ%Ÿ>š>¨-¸Ô9IÑJÔJˆÔØ%Ÿ>š>¨-¸Ô9IÑJÔJˆÔØ$.§N¢NÐ3IÈ4ÔKdÑ$eÔ$eˆÔ!Ø"Ÿš z°4´=ÑAÔAˆŒØ#Ÿš¨°T´^ÑDÔDˆŒà˜zÐ)Ð)ØÔ"Ð*Ý&6°tÔ7GÑ&HÔ&H�Ô#ØÔ×/Ò/°
Ð;KÔ0LÑMÔMÐMà˜Ð#Ð#Ý#& t¤~Ô'BÀDÄMÑ#RÔ#Rð 'ð '‘�˜RØ$&�˜DÑ!Ð!ð $Ð#ð'ð 'r   )r�   rž   rŸ   r    r¡   r   r   r¢   r#   r£   FFr¤   r¥   ) r   r   r¦   ro   r`   r%   r§   r   r¨   r%   r©   ro   rª   r   r«   r   ra   r¬   r­   r¬   r®   r%   r¯   r°   r±   r°   r}   r   r²   r   r~   r   ©N)rÎ   r%   rÏ   rW   r~   r   )rÕ   r%   rÊ   r%   r~   r°   )rÏ   r   r~   r   )r~   r   )r~   rç   r•   r–   )r—   r˜   r™   rš   r…   rÖ   rÒ   rÔ   rÓ   rß   ré   r‘   r”   r   r   r   rœ   rœ   m  s  € € € € € ð6ð 6ðv ØØØØ#ØØØ&*Ø&)ØØØØØð!E@ð E@ð E@ð E@ð E@ðN,Oð ,Oð ,Oð ,Oð ,Oð\
7ð 
7ð 
7ð 
7ðð ð ð ð&
5ð 
5ð 
5ð 
5ð7ð 7ð 7ð 7ð"ð ð ð ðð ð ð ðB!'ð !'ð !'ð !'ð !'ð !'r   rœ   c                ó   — t          | fi |¤ŽS )a£  
    Create an adaptive learning rate scheduler that adjusts LR based on training metrics.

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        kwargs (`dict`, *optional*):
            Extra parameters passed to the scheduler. See [`GreedyLR`] for possible parameters.

    Return:
        [`GreedyLR`] with the appropriate schedule.
    )rœ   r   s     r   Úget_greedy_schedulerð      s   € õ �IÐ(Ð( Ð(Ð(Ð(r   Únameústr | SchedulerTypeÚscheduler_specific_kwargsúdict | Nonec                óö  ‡	— t          | ¦  «        } t          |          }|�‚t          |t          ¦  «        rm|j        }i Š	|D ]}t          | ||         |||¬¦  «        ‰	|<   Œ ˆ	fd„}|D ]}|j        r|                     |¦  «         Œt          ||j	        d         ¬¦  «        S | t           j
        k    r ||¦  «        S |€i }| t           j        k    r	 ||fi |¤ŽS | t           j        k    r	 ||fi |¤ŽS |€t          | › d�¦  «        ‚| t           j        k    r |||¬¦  «        S | t           j        k    r ||fd|i|¤ŽS | t           j        k    r ||f||d	œ|¤ŽS |€t          | › d
�¦  «        ‚ ||f||d	œ|¤ŽS )a  
    Unified API to get any scheduler from its name.

    Args:
        name (`str` or `SchedulerType`):
            The name of the scheduler to use.
        optimizer (`torch.optim.Optimizer`):
            The optimizer that will be used during training.
        num_warmup_steps (`int`, *optional*):
            The number of warmup steps to do. This is not required by all schedulers (hence the argument being
            optional), the function will raise an error if it's unset and the scheduler type requires it.
        num_training_steps (`int``, *optional*):
            The number of training steps to do. This is not required by all schedulers (hence the argument being
            optional), the function will raise an error if it's unset and the scheduler type requires it.
        scheduler_specific_kwargs (`dict`, *optional*):
            Extra parameters for schedulers such as cosine with restarts. Mismatched scheduler types and scheduler
            parameters will cause the scheduler function to raise a TypeError.
    N)r   r!   r,   ró   c                ó<   •— ‰|                                ¦   «          d S rî   )rÖ   )ÚparamÚscheduler_dicts    €r   Úscheduler_hookz%get_scheduler.<locals>.scheduler_hookë  s"   ø€ ð ˜5Ô!×&Ò&Ñ(Ô(Ð(Ð(Ð(r   rQ   )Úoptimizer_dictrQ   z; requires `num_warmup_steps`, please provide that argument.r)   r!   r1   z= requires `num_training_steps`, please provide that argument.)r   ÚTYPE_TO_SCHEDULER_FUNCTIONr½   r
   rú   Úget_schedulerÚrequires_gradÚ"register_post_accumulate_grad_hookr   rS   ÚCONSTANTÚREDUCE_ON_PLATEAUÚGREEDYrT   ÚCONSTANT_WITH_WARMUPÚINVERSE_SQRTÚWARMUP_STABLE_DECAY)
rñ   r   r!   r,   ró   Úschedule_funcrú   r÷   rù   rø   s
            @r   rü   rü   À  sb  ø€ õ2 ˜ÑÔ€DÝ.¨tÔ4€Mð Ð¥¨IÕ7NÑ!OÔ!OÐØ"Ô1ˆØˆà#ð 	ð 	ˆEÝ$1ØØ(¨Ô/Ø!1Ø#5Ø*Cð%ñ %ô %ˆN˜5Ñ!Ð!ð	)ð 	)ð 	)ð 	)ð 	)ð
 $ð 	Ið 	IˆEØÔ"ð IØ×8Ò8¸ÑHÔHÐHøå&°nÈÔI[Ð\`ÔIaÐbÑbÔbÐbà�}Ô%Ò%Ð%Øˆ}˜YÑ'Ô'Ð'à Ð(Ø$&Ð!à�}Ô.Ò.Ð.Øˆ}˜YÐDÐDÐ*CÐDÐDÐDà�}Ô#Ò#Ð#Øˆ}˜YÐDÐDÐ*CÐDÐDÐDð ÐÝ˜DÐ]Ð]Ð]Ñ^Ô^Ð^à�}Ô1Ò1Ð1Øˆ}˜YÐ9IÐJÑJÔJÐJà�}Ô)Ò)Ð)Øˆ}˜YÐgÐgÐ9IÐgÐMfÐgÐgÐgð �}Ô0Ò0Ð0Øˆ}Øð
à-Ø1ð
ð 
ð (ð	
ð 
ð 	
ð Ð!Ý˜DÐ_Ð_Ð_Ñ`Ô`Ð`àˆ=Øðà)Ø-ðð ð $ð	ð ð r   c                  óÀ   ‡ — e Zd ZdZ	 	 	 	 	 	 	 	 	 dˆ fd	„	Zed
„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	 e
j        ¦   «         dd„¦   «         Zˆ xZS )Ú	Adafactora9  
    AdaFactor pytorch implementation can be used as a drop in replacement for Adam original fairseq code:
    https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py

    Paper: *Adafactor: Adaptive Learning Rates with Sublinear Memory Cost* https://huggingface.co/papers/1804.04235 Note that
    this optimizer internally adjusts the learning rate depending on the `scale_parameter`, `relative_step` and
    `warmup_init` options. To use a manual (external) learning rate schedule you should set `scale_parameter=False` and
    `relative_step=False`.

    Arguments:
        params (`Iterable[nn.parameter.Parameter]`):
            Iterable of parameters to optimize or dictionaries defining parameter groups.
        lr (`float`, *optional*):
            The external learning rate.
        eps (`tuple[float, float]`, *optional*, defaults to `(1e-30, 0.001)`):
            Regularization constants for square gradient and parameter scale respectively
        clip_threshold (`float`, *optional*, defaults to 1.0):
            Threshold of root mean square of final gradient update
        decay_rate (`float`, *optional*, defaults to -0.8):
            Coefficient used to compute running averages of square
        beta1 (`float`, *optional*):
            Coefficient used for computing running averages of gradient
        weight_decay (`float`, *optional*, defaults to 0.0):
            Weight decay (L2 penalty)
        scale_parameter (`bool`, *optional*, defaults to `True`):
            If True, learning rate is scaled by root mean square
        relative_step (`bool`, *optional*, defaults to `True`):
            If True, time-dependent learning rate is computed instead of external learning rate
        warmup_init (`bool`, *optional*, defaults to `False`):
            Time-dependent learning rate computation depends on whether warm-up initialization is being used

    This implementation handles low-precision (FP16, bfloat) values, but we have not thoroughly tested.

    Recommended T5 finetuning settings (https://discuss.huggingface.co/t/t5-finetuning-tips/684/3):

        - Training without LR warmup or clip_threshold is not recommended.

           - use scheduled LR warm-up to fixed LR
           - use clip_threshold=1.0 (https://huggingface.co/papers/1804.04235)
        - Disable relative updates
        - Use scale_parameter=False
        - Additional optimizer operations like gradient clipping should not be used alongside Adafactor

    Example:

    ```python
    Adafactor(model.parameters(), scale_parameter=False, relative_step=False, warmup_init=False, lr=1e-3)
    ```

    Others reported the following combination to work well:

    ```python
    Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None)
    ```

    When using `lr=None` with [`Trainer`] you will most likely need to use [`~optimization.AdafactorSchedule`]
    scheduler as following:

    ```python
    from transformers.optimization import Adafactor, AdafactorSchedule

    optimizer = Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None)
    lr_scheduler = AdafactorSchedule(optimizer)
    trainer = Trainer(..., optimizers=(optimizer, lr_scheduler))
    ```

    Usage:

    ```python
    # replace AdamW with Adafactor
    optimizer = Adafactor(
        model.parameters(),
        lr=1e-3,
        eps=(1e-30, 1e-3),
        clip_threshold=1.0,
        decay_rate=-0.8,
        beta1=None,
        weight_decay=0.0,
        relative_step=False,
        scale_parameter=False,
        warmup_init=False,
    )
    ```N©g ÂëþKH´9r¢   r#   çš™™™™™é¿r.   TFc           
     ó°   •— |�|	rt          d¦  «        ‚|
r|	st          d¦  «        ‚||||||||	|
dœ	}t          ¦   «                              ||¦  «         d S )Nz;Cannot combine manual `lr` and `relative_step=True` optionsz0`warmup_init=True` requires `relative_step=True`)	rQ   r®   Úclip_thresholdÚ
decay_rateÚbeta1Úweight_decayÚscale_parameterÚrelative_stepÚwarmup_init)rT   Úsuperr…   )r„   ÚparamsrQ   r®   r  r  r  r  r  r  r  rS   Ú	__class__s               €r   r…   zAdafactor.__init__v  sˆ   ø€ ð ˆ>˜mˆ>ÝÐZÑ[Ô[Ð[Øð 	Q˜}ð 	QÝÐOÑPÔPÐPð ØØ,Ø$ØØ(Ø.Ø*Ø&ð

ð 

ˆõ 	‰Œ×Ò˜ Ñ*Ô*Ð*Ð*Ð*r   c                ó  — | d         }| d         r@| d         rd|d         z  nd}t          |dt          j        |d         ¦  «        z  ¦  «        }d}| d         r"t          | d	         d
         |d         ¦  «        }||z  S )NrQ   r  r  r    rÖ   g{®Gáz„?r#   r  r®   r	   ÚRMS)r�   r8   rY   r&   )râ   Úparam_stateÚrel_step_szÚmin_stepÚparam_scales        r   Ú_get_lrzAdafactor._get_lr•  s™   € à! $Ô'ˆØ�Ô'ð 	NØ5@ÀÔ5OÐY�t˜k¨&Ô1Ñ1Ð1ÐUYˆHÝ˜h¨­d¬i¸ÀFÔ8KÑ.LÔ.LÑ(LÑMÔMˆKØˆØÐ(Ô)ð 	IÝ˜k¨%Ô0°Ô3°[ÀÔ5GÑHÔHˆKØ˜[Ñ(Ð(r   c                óD   — t          |¦  «        dk    }| d         d u}||fS )Né   r  )r‰   )râ   Úparam_shapeÚfactoredÚuse_first_moments       r   Ú_get_optionszAdafactor._get_options   s0   € å�{Ñ#Ô# qÒ(ˆØ& wÔ/°tÐ;ÐØÐ)Ð)Ð)r   c                ó\   — |                       d¦  «        |                      ¦   «         dz  z  S )Nr  r5   )ÚnormÚnumel)Útensors    r   Ú_rmszAdafactor._rms¦  s$   € à�{Š{˜1‰~Œ~ §¢¡¤°3Ñ!6Ñ7Ð7r   c                óø   — | |                       dd¬¦  «        z                       ¦   «                              d¦  «        }|                     d¦  «                             ¦   «         }t	          j        ||¦  «        S )Nr   T)ÚdimÚkeepdiméþÿÿÿ)ÚmeanÚrsqrt_Ú	unsqueezeÚrsqrtÚtorchÚmul)Úexp_avg_sq_rowÚexp_avg_sq_colÚr_factorÚc_factors       r   Ú_approx_sq_gradzAdafactor._approx_sq_gradª  sm   € ð # ^×%8Ò%8¸RÈÐ%8Ñ%NÔ%NÑN×VÒVÑXÔX×bÒbÐceÑfÔfˆØ!×+Ò+¨BÑ/Ô/×5Ò5Ñ7Ô7ˆÝŒy˜ 8Ñ,Ô,Ð,r   c                ó’	  — d}|�
 |¦   «         }| j         D �]¯}|d         D �]¢}|j        €Œ|j        }|j        t          j        t          j        hv r|                     ¦   «         }|j        rt          d¦  «        ‚| j	        |         }|j
        }|                      ||¦  «        \  }}	t          |¦  «        dk    r­d|d<   |	rt          j        |¦  «        |d<   |rpt          j        |dd…         ¦  «                             |¦  «        |d<   t          j        |dd	…         |dd…         z   ¦  «                             |¦  «        |d
<   nt          j        |¦  «        |d<   d|d<   n}|	r|d                              |¦  «        |d<   |r=|d                              |¦  «        |d<   |d
                              |¦  «        |d
<   n|d                              |¦  «        |d<   |}
|j        t          j        t          j        hv r|
                     ¦   «         }
|dxx         dz  cc<   |                      |
¦  «        |d<   |                      ||¦  «        }dt%          j        |d         |d         ¦  «        z
  }|dz  |d         d         z   }|r¾|d         }|d
         }|                     |¦  «                             |                     d¬¦  «        d|z
  ¬¦  «         |                     |¦  «                             |                     d	¬¦  «        d|z
  ¬¦  «         |                      ||¦  «        }|                     |¦  «         n\|d         }|                     |¦  «                             |d|z
  ¬¦  «         |                     ¦   «                              |¦  «        }|                     |                      |¦  «        |d         z                       d¬¦  «        ¦  «         |                     |¦  «         |	rC|d         }|                     |d         ¦  «                             |d|d         z
  ¬¦  «         |}|d         dk    r!|
                     |
|d          |z  ¬¦  «         |
                     | ¦  «         |j        t          j        t          j        hv r|                     |
¦  «         �Œ¤�Œ±|S )z¾
        Performs a single optimization step

        Arguments:
            closure (callable, optional): A closure that reevaluates the model
                and returns the loss.
        Nr  z,Adafactor does not support sparse gradients.r   rÖ   Úexp_avgr   r1  r*  r2  Ú
exp_avg_sqr  r	   r#   r  r  r®   )r(  )Úalphar  )r�   r  r  )rÅ   ÚgradÚdtyper/  Úfloat16Úbfloat16r%   Ú	is_sparseÚRuntimeErrorrë   Úshaper!  r‰   Ú
zeros_likeÚzerosÚtor&  r  r8   ÚpowÚmul_Úadd_r+  r5  r.  Údiv_Úclamp_Úcopy_)r„   ÚclosureÚlossr¸   Úpr:  rë   Ú
grad_shaper  r   Úp_data_fp32rQ   Úbeta2tÚupdater1  r2  r8  r7  s                     r   rÖ   zAdafactor.step²  sâ  € ð ˆØÐØ�7‘9”9ˆDàÔ&ð M	)ñ M	)ˆEØ˜8”_ð L)ñ L)�Ø”6�>ØØ”v�Ø”:¥%¤-µ´Ð!@Ð@Ð@ØŸ:š:™<œ<�DØ”>ð WÝ&Ð'UÑVÔVÐVàœ
 1œ�Ø!œZ�
à-1×->Ò->¸uÀjÑ-QÔ-QÑ*�Ð*å�u‘:”: ’?�?Ø$%�E˜&‘Mà'ð Bå+0Ô+;¸DÑ+AÔ+A˜˜iÑ(Øð EÝ27´+¸jÈÈ"È¼oÑ2NÔ2N×2QÒ2QÐRVÑ2WÔ2W˜Ð.Ñ/Ý27´+¸jÈÈ"È¼oÐPZÐ[]Ð[^Ð[^ÔP_Ñ>_Ñ2`Ô2`×2cÒ2cÐdhÑ2iÔ2i˜Ð.Ñ/Ð/å.3Ô.>¸tÑ.DÔ.D˜˜lÑ+à#$�E˜%‘L�Là'ð EØ+0°Ô+;×+>Ò+>¸tÑ+DÔ+D˜˜iÑ(Øð KØ27Ð8HÔ2I×2LÒ2LÈTÑ2RÔ2R˜Ð.Ñ/Ø27Ð8HÔ2I×2LÒ2LÈTÑ2RÔ2R˜Ð.Ñ/Ð/à.3°LÔ.A×.DÒ.DÀTÑ.JÔ.J˜˜lÑ+à�Ø”7�uœ}­e¬nÐ=Ð=Ð=Ø"-×"3Ò"3Ñ"5Ô"5�Kà�f��” Ñ"��‘Ø#Ÿyšy¨Ñ5Ô5��e‘Ø—\’\ %¨Ñ/Ô/�à�tœx¨¨f¬°u¸\Ô7JÑKÔKÑK�Ø ™' U¨5¤\°!¤_Ñ4�Øð ;Ø%*Ð+;Ô%<�NØ%*Ð+;Ô%<�Nà"×'Ò'¨Ñ/Ô/×4Ò4°V·[²[ÀR°[Ñ5HÔ5HÐQTÐW]ÑQ]Ð4Ñ_Ô_Ð_Ø"×'Ò'¨Ñ/Ô/×4Ò4°V·[²[ÀR°[Ñ5HÔ5HÐQTÐW]ÑQ]Ð4Ñ_Ô_Ð_ð "×1Ò1°.À.ÑQÔQ�FØ—K’K Ñ%Ô%Ð%Ð%à!& |Ô!4�Jà—O’O FÑ+Ô+×0Ò0°ÀÀfÁÐ0ÑNÔNÐNØ'×-Ò-Ñ/Ô/×4Ò4°TÑ:Ô:�Fà—’˜TŸYšY vÑ.Ô.°Ð7GÔ1HÑH×PÒPÐUXÐPÑYÔYÑZÔZÐZØ—’˜B‘”�à#ð %Ø# IÔ.�GØ—L’L  w¤Ñ0Ô0×5Ò5°fÀQÈÈwÌÑEWÐ5ÑYÔYÐYØ$�Fà˜Ô(¨AÒ-Ð-Ø×$Ò$ [¸%ÀÔ:OÐ9OÐRTÑ9TÐ$ÑVÔVÐVà× Ò  & Ñ)Ô)Ð)à”7�uœ}­e¬nÐ=Ð=Ð=Ø—G’G˜KÑ(Ô(Ð(ùñYL)ð\ ˆr   )	Nr  r#   r	  Nr.   TTFrî   )r—   r˜   r™   rš   r…   Ústaticmethodr  r!  r&  r5  r/  Úno_gradrÖ   Ú__classcell__©r  s   @r   r  r  !  s  ø€ € € € € ðRð Rðn ØØØØØØØØð+ð +ð +ð +ð +ð +ð> ð)ð )ñ „\ð)ð ð*ð *ñ „\ð*ð
 ð8ð 8ñ „\ð8ð ð-ð -ñ „\ð-ð €U„]�_„_ð[ð [ð [ñ „_ð[ð [ð [ð [ð [r   r  c                  ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚAdafactorSchedulea8  
    Since [`~optimization.Adafactor`] performs its own scheduling, if the training loop relies on a scheduler (e.g.,
    for logging), this class creates a proxy object that retrieves the current lr values from the optimizer.

    It returns `initial_lr` during startup and the actual `lr` during stepping.
    r.   c                ó�   •‡— ˆfd„}|j         D ]}‰|d<   Œt          ¦   «                              ||¦  «         |j         D ]}|d= Œd S )Nc                ó   •— ‰S rî   r   )r   Ú
initial_lrs    €r   r*   z-AdafactorSchedule.__init__.<locals>.lr_lambda  s	   ø€ ØÐr   rY  )rÅ   r  r…   )r„   r   rY  r*   r¸   r  s     `  €r   r…   zAdafactorSchedule.__init__  s   øø€ ð	ð 	ð 	ð 	ð 	ð Ô+ð 	-ð 	-ˆEØ",ˆE�,ÑÐÝ‰Œ×Ò˜ IÑ.Ô.Ð.ØÔ+ð 	$ð 	$ˆEØ�lÐ#Ð#ð	$ð 	$r   c                óp   ‡— | j         Šˆfd„‰j        D ¦   «         }t          |¦  «        dk    r| j        }|S )Nc                ó�   •— g | ]B}|d          d         j         ®‰                     |‰j        |d          d                  ¦  «        ‘ŒCS )r  r   )r:  r  rë   )r·   r¸   Úopts     €r   r¹   z,AdafactorSchedule.get_lr.<locals>.<listcomp>%  sS   ø€ ð 
ð 
ð 
àØ�XŒ˜qÔ!Ô&Ð2ð �KŠK˜˜sœy¨¨x¬¸Ô);Ô<Ñ=Ô=à2Ð2Ð2r   r   )r   rÅ   r‰   Úbase_lrs)r„   Úlrsr\  s     @r   Úget_lrzAdafactorSchedule.get_lr#  sR   ø€ ØŒnˆð
ð 
ð 
ð 
àÔ)ð
ñ 
ô 
ˆõ
 ˆs‰8Œ8�qŠ=ˆ=Ø”-ˆCØˆ
r   ©r.   )r—   r˜   r™   rš   r…   r_  rS  rT  s   @r   rV  rV    sV   ø€ € € € € ðð ð$ð $ð $ð $ð $ð $ð	ð 	ð 	ð 	ð 	ð 	ð 	r   rV  c                ó"   — t          | |¦  «        S )aX  
    Get a proxy schedule for [`~optimization.Adafactor`]

    Args:
        optimizer ([`~torch.optim.Optimizer`]):
            The optimizer for which to schedule the learning rate.
        initial_lr (`float`, *optional*, defaults to 0.0):
            Initial lr

    Return:
        [`~optimization.Adafactor`] proxy schedule object.


    )rV  )r   rY  s     r   Úget_adafactor_schedulerb  /  s   € õ ˜Y¨
Ñ3Ô3Ð3r   rî   )r   )r   r   r   r   )r   r   )r    r   r!   r   )r   r   r!   r   r   r   )r    r   r!   r   r,   r   )r    r   r!   r   r,   r   r3   r%   )r5   r   )
r   r   r!   r   r,   r   r3   r%   r   r   )r    r   r!   r   r,   r   r3   r   )r	   r   )
r   r   r!   r   r,   r   r3   r   r   r   )r    r   r!   r   r,   r   rF   r%   rG   r%   rH   r   )rO   r#   r   )r    r   r!   r   rV   rW   )Nr   )r   r   r!   r   rV   rW   r   r   )
r    r   r!   r   r,   r   r3   r%   r^   r%   )r5   r   NN)r   r   r!   r   r,   r   r3   r%   r   r   ra   rb   r^   rb   )r    r   r!   r   r,   r   r3   r%   r^   r%   rg   rb   )r5   r   NNN)r   r   r!   r   r,   r   r3   r%   r   r   ra   rb   r^   rb   rg   rb   )r    r   r!   r   rl   r   rm   r   rn   ro   rp   ro   rq   r%   r3   r%   )NNrs   rt   r   r5   r   )r   r   r!   r   rm   r   r,   rW   rl   rW   rn   ro   rp   ro   rq   r%   r3   r%   r   r   )NNN)
rñ   rò   r   r   r!   rW   r,   rW   ró   rô   r`  )Arš   Ú
__future__r   r8   rx   Ú	functoolsr   Útypingr   r/  Útorch.optimr   Útorch.optim.lr_schedulerr   r   Útrainer_pt_utilsr
   r   Útrainer_utilsr   Úutilsr   Ú
get_loggerr—   Úloggerr   r   r   r'   r+   r/   r2   r=   rA   rC   rE   rN   rU   r[   r]   rf   ri   rk   rv   rz   r|   rœ   rð   ÚLINEARÚCOSINEÚCOSINE_WITH_RESTARTSÚ
POLYNOMIALrÿ   r  r  r   ÚCOSINE_WITH_MIN_LRÚCOSINE_WARMUP_WITH_MIN_LRr  r  rû   rü   r  rV  rb  r   r   r   ú<module>rs     sÚ  ðð +Ð *à "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @à NÐ NÐ NÐ NÐ NÐ NÐ NÐ NØ (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð ð 
ˆÔ	˜HÑ	%Ô	%€ðð ð ð ðLð Lð Lð Lð Lð"2ð 2ð 2ð 2ð$ð ð ð ðAð Að Að Að Að*uð uð uð uð6ð 6ð 6ð 6ð6Zð Zð Zð Zð vxð6ð 6ð 6ð 6ð 6ðD^ð ^ð ^ð ^ð rtð6ð 6ð 6ð 6ð 6ðBð ð ð ð, Y[ð+6ð +6ð +6ð +6ð\ osð ð ð ð ð ð ð bdðAð Að Að Að Að> svðð ð ð ð ð ð ØØØ $ð16ð 16ð 16ð 16ð 16ðt Ø#'ðð ð ð ð ð ð: ØØØ $Ø#'ð56ð 56ð 56ð 56ð 56ðp#ð #ð #ð #ðT &*Ø#'ØØØØØðF6ð F6ð F6ð F6ð F6ðR%.ð %.ð %.ð %.ð %.ñ %.ô %.ð %.ðPp'ð p'ð p'ð p'ð p'ñ p'ô p'ð p'ðf	)ð )ð )ð )ð" ÔÐ9ØÔÐ9ØÔ&Ð(ZØÔÐGØÔÐ1ØÔ&Ð(IØÔÐ 9ØÔ#Ð%CØÔ$Ð&QØÔ+Ð-`ØÔ%Ð'7ØÔÐ-ðÐ ð& $(Ø%)Ø-1ð^ð ^ð ^ð ^ð ^ðBmð mð mð mð m�	ñ mô mð mð`ð ð ð ð ˜ñ ô ð ð<4ð 4ð 4ð 4ð 4ð 4r   