Ë
    ùÿæiNZ  ã            
       óŒ  — d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ ddlZddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ g d¢ZddlmZ eeedf   ee   f   Zdd„Z d„ Z!dd„Z"d„ Z# G d„ de«      Z$ ejJ                  «       	 ddee
   dede&ejN                  z  dz  ddfd„«       Z( G d„ de«      Z)y)z>Implementation for Stochastic Weight Averaging implementation.é    N)ÚCallableÚIterable)Údeepcopy)ÚAnyÚcastÚLiteralÚUnion)Úoverride)ÚTensor)ÚModule)Ú_format_paramÚLRScheduler)Ú&_get_foreach_kernels_supported_devicesé   )Ú	Optimizer)ÚAveragedModelÚ	update_bnÚSWALRÚget_ema_multi_avg_fnÚget_swa_multi_avg_fnÚget_ema_avg_fnÚget_swa_avg_fn)Ú"_group_tensors_by_device_and_dtype.c                 ó�   ‡ — ‰ dk  s‰ dkD  rt        d‰ › d�«      ‚t        j                  «       dt        dt        ddfˆ fd	„«       }|S )
áÕ  Get the function applying exponential moving average (EMA) across multiple params.

    The EMA is computed as:

    .. math::
        W_0^{\text{EMA}} = W_0^{\text{model}}

    .. math::
        W_{t+1}^{\text{EMA}} = \text{decay} \times W_t^{\text{EMA}} + (1 - \text{decay}) \times W_{t+1}^{\text{model}}

    where :math:`W_t^{\text{EMA}}` is the EMA parameter at step :math:`t`,
    :math:`W_t^{\text{model}}` is the model parameter at step :math:`t`,
    and :math:`\text{decay}` is the decay rate (default: 0.999).

    Args:
        decay (float): Decay rate for EMA. Must be in the range [0, 1]. Default: 0.999

    Returns:
        Callable: A function that updates EMA parameters given current model parameters
    ç        ç      ð?úInvalid decay value ú1 provided. Please provide a value in [0,1] range.Úema_param_listÚcurrent_param_listÚreturnNc                 ó  •— t        j                  | d   «      st        j                  | d   «      rt        j                  | |d‰z
  «       y t	        | |d¬«      D ]"  \  }}|j                  |‰z  |d‰z
  z  z   «       Œ$ y )Nr   r   T©Ústrict)ÚtorchÚis_floating_pointÚ
is_complexÚ_foreach_lerp_ÚzipÚcopy_)r    r!   Ú_Úp_emaÚp_modelÚdecays        €új/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch/optim/swa_utils.pyÚ
ema_updatez(get_ema_multi_avg_fn.<locals>.ema_update@   s~   ø€ ô
 ×"Ñ" >°!Ñ#4Ô5¼×9IÑ9IØ˜1Ñô:
ô × Ñ  Ð1CÀQÈÁYÕOä"% nÐ6HÐQU×"V‘��wØ—‘˜E E™M¨G°q¸5±yÑ,AÑAÕBñ #Wó    )Ú
ValueErrorr&   Úno_gradÚ
PARAM_LIST©r/   r1   s   ` r0   r   r   %   sk   ø€ ð, ˆs‚{�e˜c’kÜØ" 5 'Ð)ZÐ[ó
ð 	
ô ‡]�]ƒ_ð
CÜ"ð
CÜ8Bð
Cà	ô
Có ð
Cð Ðr2   c            	      ór   — t        j                  «       dt        dt        dt        t        z  ddfd„«       } | S )zQGet the function applying stochastic weight average (SWA) across multiple params.Úaveraged_param_listr!   Únum_averagedr"   Nc           
      ó”  — t        j                  | d   «      st        j                  | d   «      r,t        j                  | |t	        t
        d|dz   z  «      «       y t        j                  || «      }t        |t        «      r(t        j                  | ||dz   gt        | «      z  «       y t        j                  | |d|dz   z  ¬«       y )Nr   r   r   )Úalpha)r&   r'   r(   r)   r   ÚfloatÚ_foreach_subÚ
isinstancer   Ú_foreach_addcdiv_ÚlenÚ_foreach_add_)r8   r!   r9   Údiffss       r0   Ú
swa_updatez(get_swa_multi_avg_fn.<locals>.swa_updateS   sÂ   € ô ×"Ñ"Ð#6°qÑ#9Ô:¼e×>NÑ>NØ Ñ"ô?
ô × Ñ Ø#Ø"Ü”U˜A °Ñ!1Ñ2Ó3õô ×&Ñ&Ð'9Ð;NÓOˆEÜ˜,¬Ô/Ü×'Ñ'Ø'ØØ! AÑ%Ð&¬Ð-@Ó)AÑAõô ×#Ñ#Ø'¨°c¸\ÈAÑ=MÑ6Nör2   )r&   r4   r5   r   Úint©rC   s    r0   r   r   P   sL   € ô ‡]�]ƒ_ðÜ'ðä&ðô œs‘lðð 
ò	ó ðð6 Ðr2   c                 óŒ   ‡ — ‰ dk  s‰ dkD  rt        d‰ › d�«      ‚t        j                  «       dt        dt        fˆ fd„«       }|S )r   r   r   r   r   Ú	ema_paramÚcurrent_paramc                 ó    •— ‰| z  d‰z
  |z  z   S ©Nr   © )rG   rH   r9   r/   s      €r0   r1   z"get_ema_avg_fn.<locals>.ema_update�   s   ø€ à�yÑ  A¨¡I°Ñ#>Ñ>Ð>r2   )r3   r&   r4   r   r6   s   ` r0   r   r   r   s\   ø€ ð, ˆs‚{�e˜c’kÜØ" 5 'Ð)ZÐ[ó
ð 	
ô ‡]�]ƒ_ð?œfð ?´Vô ?ó ð?ð Ðr2   c                  ón   — t        j                  «       dt        dt        dt        t        z  fd„«       } | S )zPGet the function applying stochastic weight average (SWA) across a single param.Úaveraged_paramrH   r9   c                 ó   — | || z
  |dz   z  z   S rJ   rK   )rM   rH   r9   s      r0   rC   z"get_swa_avg_fn.<locals>.swa_update—   s   € ð  °Ñ!?ÀLÐSTÑDTÑ UÑUÐUr2   )r&   r4   r   rD   rE   s    r0   r   r   ”   sE   € ô ‡]�]ƒ_ðVÜðVÜ/5ðVÜEKÌcÁ\òVó ðVð
 Ðr2   c                   ó¼   ‡ — e Zd ZU dZeed<   	 	 	 	 ddedeej                  z  dz  de
eeeez  gef   dz  de
eeeez  gdf   dz  ddf
ˆ fd	„Zd
„ Zdeddfd„Zˆ xZS )r   aÇ  Implements averaged model for Stochastic Weight Averaging (SWA) and Exponential Moving Average (EMA).

    Stochastic Weight Averaging was proposed in `Averaging Weights Leads to
    Wider Optima and Better Generalization`_ by Pavel Izmailov, Dmitrii
    Podoprikhin, Timur Garipov, Dmitry Vetrov and Andrew Gordon Wilson
    (UAI 2018).

    Exponential Moving Average is a variation of `Polyak averaging`_,
    but using exponential weights instead of equal weights across iterations.

    AveragedModel class creates a copy of the provided module :attr:`model`
    on the device :attr:`device` and allows to compute running averages of the
    parameters of the :attr:`model`.

    Args:
        model (torch.nn.Module): model to use with SWA/EMA
        device (torch.device, optional): if provided, the averaged model will be
            stored on the :attr:`device`
        avg_fn (function, optional): the averaging function used to update
            parameters; the function must take in the current value of the
            :class:`AveragedModel` parameter, the current value of :attr:`model`
            parameter, and the number of models already averaged; if None,
            an equally weighted average is used (default: None)
        multi_avg_fn (function, optional): the averaging function used to update
            parameters inplace; the function must take in the current values of the
            :class:`AveragedModel` parameters as a list, the current values of :attr:`model`
            parameters as a list, and the number of models already averaged; if None,
            an equally weighted average is used (default: None)
        use_buffers (bool): if ``True``, it will compute running averages for
            both the parameters and the buffers of the model. (default: ``False``)

    Example:
        >>> # xdoctest: +SKIP("undefined variables")
        >>> loader, optimizer, model, loss_fn = ...
        >>> swa_model = torch.optim.swa_utils.AveragedModel(model)
        >>> scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer,
        >>>                                     T_max=300)
        >>> swa_start = 160
        >>> swa_scheduler = SWALR(optimizer, swa_lr=0.05)
        >>> for i in range(300):
        >>>      for input, target in loader:
        >>>          optimizer.zero_grad()
        >>>          loss_fn(model(input), target).backward()
        >>>          optimizer.step()
        >>>      if i > swa_start:
        >>>          swa_model.update_parameters(model)
        >>>          swa_scheduler.step()
        >>>      else:
        >>>          scheduler.step()
        >>>
        >>> # Update bn statistics for the swa_model at the end
        >>> torch.optim.swa_utils.update_bn(loader, swa_model)

    You can also use custom averaging functions with the `avg_fn` or `multi_avg_fn` parameters.
    If no averaging function is provided, the default is to compute
    equally-weighted average of the weights (SWA).

    Example:
        >>> # xdoctest: +SKIP("undefined variables")
        >>> # Compute exponential moving averages of the weights and buffers
        >>> ema_model = torch.optim.swa_utils.AveragedModel(model,
        >>>             torch.optim.swa_utils.get_ema_multi_avg_fn(0.9), use_buffers=True)

    .. note::
        When using SWA/EMA with models containing Batch Normalization you may
        need to update the activation statistics for Batch Normalization.
        This can be done either by using the :meth:`torch.optim.swa_utils.update_bn`
        or by setting :attr:`use_buffers` to `True`. The first approach updates the
        statistics in a post-training step by passing data through the model. The
        second does it during the parameter update phase by averaging all buffers.
        Empirical evidence has shown that updating the statistics in normalization
        layers increases accuracy, but you may wish to empirically test which
        approach yields the best results in your problem.

    .. note::
        :attr:`avg_fn` and `multi_avg_fn` are not saved in the :meth:`state_dict` of the model.

    .. note::
        When :meth:`update_parameters` is called for the first time (i.e.
        :attr:`n_averaged` is `0`) the parameters of `model` are copied
        to the parameters of :class:`AveragedModel`. For every subsequent
        call of :meth:`update_parameters` the function `avg_fn` is used
        to update the parameters.

    .. _Averaging Weights Leads to Wider Optima and Better Generalization:
        https://arxiv.org/abs/1803.05407
    .. _There Are Many Consistent Explanations of Unlabeled Data: Why You Should
        Average:
        https://arxiv.org/abs/1806.05594
    .. _SWALP: Stochastic Weight Averaging in Low-Precision Training:
        https://arxiv.org/abs/1904.11943
    .. _Stochastic Weight Averaging in Parallel: Large-Batch Training That
        Generalizes Well:
        https://arxiv.org/abs/2001.02312
    .. _Polyak averaging:
        https://paperswithcode.com/method/polyak-averaging
    Ú
n_averagedNÚmodelÚdeviceÚavg_fnÚmulti_avg_fnr"   c                 ó:  •— t         ‰| �  «        |�|�t        d«      ‚t        |«      | _        |� | j                  j                  |«      | _        | j                  dt        j                  dt        j                  |¬«      «       || _
        || _        || _        y )Nz6Only one of avg_fn and multi_avg_fn should be providedrP   r   )ÚdtyperR   )ÚsuperÚ__init__ÚAssertionErrorr   ÚmoduleÚtoÚregister_bufferr&   ÚtensorÚlongrS   rT   Úuse_buffers)ÚselfrQ   rR   rS   rT   r_   Ú	__class__s         €r0   rX   zAveragedModel.__init__  s�   ø€ ô 	‰ÑÔØÐ ,Ð":Ü ØHóð ô ˜u“oˆŒØÐØŸ+™+Ÿ.™.¨Ó0ˆDŒKØ×ÑØœ%Ÿ,™, q´·
±
À6ÔJô	
ð ˆŒØ(ˆÔØ&ˆÕr2   c                 ó&   —  | j                   |i |¤ŽS )zForward pass.)rZ   )r`   ÚargsÚkwargss      r0   ÚforwardzAveragedModel.forward  s   € àˆt�{‰{˜DÐ+ FÑ+Ð+r2   c           	      óL  — | j                   rFt        j                  | j                  j	                  «       | j                  j                  «       «      n| j	                  «       }| j                   r2t        j                  |j	                  «       |j                  «       «      n|j	                  «       }g }g }t        | j                  dk(  «      }t        ||d¬«      D ]€  \  }}|j                  «       j                  |j                  «      }	|j                  |j                  «       «       |j                  |	«       |sŒb|j                  «       j                  |	«       Œ‚ | j                  dkD  �r”| j                  €| j                  �€t!        ||g«      }
|
j#                  «       D ]á  \  \  }}\  \  }}}| j                  r-| j                  ||| j                  j                  |«      «       ŒH|�D|j$                  t'        «       v r.t)        «       } |||| j                  j                  |«      «       ŒŽt+        «       }| j                  j                  |«      }t        ||d¬«      D ]  \  }}|j                   ||||«      «       Œ  Œã nyt        ||d¬«      D ]h  \  }}| j                  j                  |j                  «      }|j                  «       j                  | j                  |j                  «       ||«      «       Œj | j                   s‚t        | j                  j                  «       |j                  «       d¬«      D ]K  \  }}|j                  «       j                  |j                  «       j                  |j                  «      «       ŒM | xj                  dz  c_        y)zUpdate model parameters.r   Fr$   NTr   )r_   Ú	itertoolsÚchainrZ   Ú
parametersÚbuffersÚboolrP   r*   Údetachr[   rR   Úappendr+   rT   rS   r   ÚitemsÚtyper   r   r   )r`   rQ   Ú
self_paramÚmodel_paramÚself_param_detachedÚmodel_param_detachedÚ
copy_paramÚ
p_averagedr.   Úp_model_Úgrouped_tensorsrR   r,   Úself_paramsÚmodel_paramsrT   rS   rP   Úb_swaÚb_models                       r0   Úupdate_parameterszAveragedModel.update_parameters!  s  € ð
 ×Òô �O‰O˜DŸK™K×2Ñ2Ó4°d·k±k×6IÑ6IÓ6KÔLà—‘Ó"ð	 	ð ×Òô �O‰O˜E×,Ñ,Ó.°·±³Ô@à×!Ñ!Ó#ð	 	ð 46ÐØ46ÐÜ˜$Ÿ/™/¨QÑ.Ó/ˆ
Ü#& z°;Àu×#MÑˆJ˜Ø—~‘~Ó'×*Ñ*¨:×+<Ñ+<Ó=ˆHØ×&Ñ& z×'8Ñ'8Ó':Ô;Ø ×'Ñ'¨Ô1ÚØ×!Ñ!Ó#×)Ñ)¨(Õ3ð $Nð �?‰?˜QÓØ× Ñ Ð,°·±Ñ0CÜ"DØ(Ð*>Ð?ó#�ð %×*Ñ*Ö,ñ‘K�V˜Qñ "Ù/�[ ,Øà×(Ò(Ø×)Ñ)Ø'Ø(Ø ŸO™O×.Ñ.¨vÓ6õð Ð*Ø"ŸK™KÔ+QÓ+SÑSä';Ó'=˜Ù$Ø'¨°t·±×7IÑ7IÈ&Ó7Qõô "0Ó!1˜Ø%)§_¡_×%7Ñ%7¸Ó%?˜
Ü36Ø'¨¸d÷4Ñ/˜J¨ð '×,Ñ,©V°JÀÈÓ-TÕUñ	4ñ% -ô0 ,/Ø'Ð)=Àd÷,Ñ'�J ð "&§¡×!3Ñ!3°J×4EÑ4EÓ!F�Jà×%Ñ%Ó'×-Ñ-àŸ™ J×$5Ñ$5Ó$7¸À*ÓMõð,ð ×Òô #&Ø—‘×#Ñ#Ó% u§}¡}£¸t÷#‘��wð —‘“×$Ñ$ W§^¡^Ó%5×%8Ñ%8¸¿¹Ó%FÕGð#ð 	�Š˜1ÑŽr2   )NNNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   rD   r&   rR   r   r5   rX   re   r|   Ú__classcell__©ra   s   @r0   r   r       sµ   ø… ñ`ðD Óð
 -1ØJNàØñ'àð'ð �e—l‘lÑ" TÑ)ð'ð ˜& &¨&°3©,Ð7¸Ð?Ñ@À4ÑGð	'ð
  
¨J¸À¹ÐEÀtÐKÑLØ
ñð'ð 
õ'ò0,ðJ vð J°$÷ Jr2   r   ÚloaderrQ   rR   r"   c                 óú  — i }|j                  «       D ]Z  }t        |t        j                  j                   j                  j
                  «      sŒ<|j                  «        |j                  ||<   Œ\ |sy|j                  }|j                  «        |D ]	  }d|_        Œ | D ]8  }t        |t        t        f«      r|d   }|�|j                  |«      } ||«       Œ: |D ]  }||   |_        Œ |j                  |«       y)a˜  Update BatchNorm running_mean, running_var buffers in the model.

    It performs one pass over data in `loader` to estimate the activation
    statistics for BatchNorm layers in the model.

    Args:
        loader (torch.utils.data.DataLoader): dataset loader to compute the
            activation statistics on. Each data batch should be either a
            tensor, or a list/tuple whose first element is a tensor
            containing data.
        model (torch.nn.Module): model for which we seek to update BatchNorm
            statistics.
        device (torch.device, optional): If set, data will be transferred to
            :attr:`device` before being passed into :attr:`model`.

    Example:
        >>> # xdoctest: +SKIP("Undefined variables")
        >>> loader, model = ...
        >>> torch.optim.swa_utils.update_bn(loader, model)

    .. note::
        The `update_bn` utility assumes that each data batch in :attr:`loader`
        is either a tensor or a list or tuple of tensors; in the latter case it
        is assumed that :meth:`model.forward()` should be called on the first
        element of the list or tuple corresponding to the data batch.
    Nr   )Úmodulesr>   r&   ÚnnÚ	batchnormÚ
_BatchNormÚreset_running_statsÚmomentumÚtrainingÚtrainÚlistÚtupler[   )r„   rQ   rR   ÚmomentarZ   Úwas_trainingÚinputÚ	bn_modules           r0   r   r   n  sá   € ð@ €GØ—-‘-–/ˆÜ�fœeŸh™h×.Ñ.×8Ñ8×CÑCÕDØ×&Ñ&Ô(Ø$Ÿo™oˆG�FŠOð "ñ
 Øà—>‘>€LØ	‡K�K„MÛˆØˆ�ð ó ˆÜ�eœd¤E˜]Ô+Ø˜!‘HˆEØÐØ—H‘H˜VÓ$ˆEáˆe�ð ó ˆ	Ø$ YÑ/ˆ	Õð à	‡K�K�Õr2   c            	       óÜ   ‡ — e Zd ZdZ	 	 	 ddededed   ddfˆ fd„Zed	„ «       Z	ed
„ «       Z
ed„ «       Zed„ «       Zded   ddfd„Zedeeef   fd„«       Zedeeef   ddfd„«       Zˆ xZS )r   aD  Anneals the learning rate in each parameter group to a fixed value.

    This learning rate scheduler is meant to be used with Stochastic Weight
    Averaging (SWA) method (see `torch.optim.swa_utils.AveragedModel`).

    Args:
        optimizer (torch.optim.Optimizer): wrapped optimizer
        swa_lrs (float or list): the learning rate value for all param groups
            together or separately for each group.
        annealing_epochs (int): number of epochs in the annealing phase
            (default: 10)
        annealing_strategy (str): "cos" or "linear"; specifies the annealing
            strategy: "cos" for cosine annealing, "linear" for linear annealing
            (default: "cos")
        last_epoch (int): the index of the last epoch (default: -1)

    The :class:`SWALR` scheduler can be used together with other
    schedulers to switch to a constant learning rate late in the training
    as in the example below.

    Example:
        >>> # xdoctest: +SKIP("Undefined variables")
        >>> loader, optimizer, model = ...
        >>> lr_lambda = lambda epoch: 0.9
        >>> scheduler = torch.optim.lr_scheduler.MultiplicativeLR(optimizer,
        >>>        lr_lambda=lr_lambda)
        >>> swa_scheduler = torch.optim.swa_utils.SWALR(optimizer,
        >>>        anneal_strategy="linear", anneal_epochs=20, swa_lr=0.05)
        >>> swa_start = 160
        >>> for i in range(300):
        >>>      for input, target in loader:
        >>>          optimizer.zero_grad()
        >>>          loss_fn(model(input), target).backward()
        >>>          optimizer.step()
        >>>      if i > swa_start:
        >>>          swa_scheduler.step()
        >>>      else:
        >>>          scheduler.step()

    .. _Averaging Weights Leads to Wider Optima and Better Generalization:
        https://arxiv.org/abs/1803.05407
    Ú	optimizerÚswa_lrÚanneal_strategy©ÚcosÚlinearr"   Nc                 ó$  •— t        d||«      }t        ||j                  d¬«      D ]
  \  }}||d<   Œ |dvrt        d|› �«      ‚| j	                  |«       t        |t        «      r|dk  rt        d|› �«      ‚|| _        t        ‰| �%  ||«       y )Nr–   Tr$   r˜   z>anneal_strategy must by one of 'cos' or 'linear', instead got r   z3anneal_epochs must be equal or greater than 0, got )
r   r*   Úparam_groupsr3   Ú_set_anneal_funcr>   rD   Úanneal_epochsrW   rX   )	r`   r•   r–   rž   r—   Ú
last_epochÚswa_lrsÚgroupra   s	           €r0   rX   zSWALR.__init__Õ  s±   ø€ ô   ¨)°VÓ<ˆÜ  ¨)×*@Ñ*@È×N‰MˆF�EØ$ˆE�(ŠOð OàÐ"3Ñ3ÜðØ.Ð/ð1óð ð 	×Ñ˜oÔ.Ü˜-¬Ô-°ÀÒ1BÜØEÀmÀ_ÐUóð ð +ˆÔÜ‰Ñ˜ JÕ/r2   c                 ó   — | S ©NrK   ©Úts    r0   Ú_linear_annealzSWALR._linear_annealí  s   € àˆr2   c                 óZ   — dt        j                  t         j                  | z  «      z
  dz  S )Nr   é   )Úmathr™   Úpir¤   s    r0   Ú_cosine_annealzSWALR._cosine_annealñ  s#   € à”D—H‘HœTŸW™W q™[Ó)Ñ)¨QÑ.Ð.r2   c                 ó,   — |dk(  r|S | ||z  z
  d|z
  z  S rJ   rK   )Úlrr–   r;   s      r0   Ú_get_initial_lrzSWALR._get_initial_lrõ  s&   € à�AŠ:ØˆMØ�U˜V‘^Ñ#¨¨E©	Ñ2Ð2r2   c                 ó¶  — | j                   st        j                  dt        d¬«       | j                  dz
  }| j
                  dk(  rt        d|«      }t        dt        d|dz
  t        d| j
                  «      z  «      «      }| j                  |«      }| j                  j                  D �cg c]  }| j                  |d   |d   |«      ‘Œ }}t        dt        d|t        d| j
                  «      z  «      «      }| j                  |«      }t        | j                  j                  |d¬	«      D ��cg c]  \  }}|d   |z  |d|z
  z  z   ‘Œ c}}S c c}w c c}}w )
a…  Compute the next learning rate for each of the optimizer's
        :attr:`~torch.optim.Optimizer.param_groups`.

        Uses :attr:`anneal_func` to interpolate between each group's
        ``group["lr"]`` and ``group["swa_lr"]`` over :attr:`anneal_epochs`
        epochs. Once :attr:`anneal_epochs` is reached, keeps the learning rate
        fixed at ``group["swa_lr"]``.

        Returns:
            list[float | Tensor]: A :class:`list` of learning rates for each of
            the optimizer's :attr:`~torch.optim.Optimizer.param_groups` with the
            same types as their current ``group["lr"]``\s.

        .. note::
            If you're trying to inspect the most recent learning rate, use
            :meth:`get_last_lr()` instead.

        .. note::
            The returned :class:`~torch.Tensor`\s are copies, and never alias
            the optimizer's ``group["lr"]``\s.
        zTTo get the last learning rate computed by the scheduler, please use `get_last_lr()`.r¨   )Ú
stacklevelr   r   r­   r–   Tr$   )Ú_get_lr_called_within_stepÚwarningsÚwarnÚUserWarningÚ_step_countrž   ÚmaxÚminÚanneal_funcr•   rœ   r®   r*   )	r`   ÚstepÚprev_tÚ
prev_alphar¡   Úprev_lrsr¥   r;   r­   s	            r0   Úget_lrzSWALR.get_lrû  s\  € ð2 ×.Ò.Ü�M‰Mð.äØõ	ð ×Ñ !Ñ#ˆØ×Ñ Ò"Ü�q˜$“<ˆDä�Qœ˜A  q¡¬C°°4×3EÑ3EÓ,FÑFÓGÓHˆØ×%Ñ% fÓ-ˆ
ð Ÿ™×4Ò4ó
á4�ð × Ñ   t¡¨e°H©o¸zÕJØ4ð 	ð 
ô
 �”3�q˜$¤ Q¨×(:Ñ(:Ó!;Ñ;Ó<Ó=ˆØ× Ñ  Ó#ˆô ! §¡×!<Ñ!<¸hÈtÕTô
áT‘	��rð �(‰O˜eÑ# b¨A°©IÑ&6Ó6ØTò
ð 	
ùò
ùó
s   Â, EÄ1Ec                 ób   — || _         |dk(  r| j                  | _        y | j                  | _        y )Nr™   )Ú_anneal_strategyr«   r¸   r¦   )r`   r—   s     r0   r�   zSWALR._set_anneal_func.  s.   € Ø /ˆÔØ˜eÒ#Ø#×2Ñ2ˆDÕà#×2Ñ2ˆDÕr2   c                 ór   — | j                   j                  «       D ��ci c]  \  }}|dvr||“Œ c}}S c c}}w )z³Return the state of the scheduler as a :class:`dict`.

        It contains an entry for every variable in self.__dict__ which
        is not the optimizer or anneal_func.
        )r•   r¸   )Ú__dict__rn   )r`   ÚkeyÚvalues      r0   Ú
state_dictzSWALR.state_dict5  sG   € ð #Ÿm™m×1Ñ1Ô3ô
á3‘
��UØÐ6Ñ6ð �‰JØ3ò
ð 	
ùó 
s   ž3rÄ   c                 óp   — | j                   j                  |«       | j                  | j                  «       y)z³Load the scheduler's state.

        Args:
            state_dict (dict): scheduler state. Should be an object returned
                from a call to :meth:`state_dict`.
        N)rÁ   Úupdater�   r¿   )r`   rÄ   s     r0   Úload_state_dictzSWALR.load_state_dictB  s*   € ð 	�‰×Ñ˜ZÔ(Ø×Ñ˜d×3Ñ3Õ4r2   )é
   r™   éÿÿÿÿ)r}   r~   r   r€   r   r<   r   rX   Ústaticmethodr¦   r«   r®   r
   r½   r�   ÚdictÚstrr   rÄ   rÇ   r‚   rƒ   s   @r0   r   r   ©  sú   ø„ ñ)ð^ Ø49Øñ0àð0ð ð0ð
 ! Ñ1ð0ð 
õ0ð0 ñó ðð ñ/ó ð/ð ñ3ó ð3ð
 ñ0
ó ð0
ðd3°¸Ñ0Hð 3ÈTó 3ð ð

˜D  c ™Nò 

ó ð

ð ð5¨$¨s°C¨x©.ð 5¸Tò 5ó ô5r2   r   )g+‡ÙÎ÷ï?r£   )*r€   rg   r©   r²   Úcollections.abcr   r   Úcopyr   Útypingr   r   r   r	   Útyping_extensionsr
   r&   r   Útorch.nnr   Útorch.optim.lr_schedulerr   r   Útorch.utils._foreach_utilsr   r•   r   Ú__all__r   r�   rŽ   r5   r   r   r   r   r   r4   rD   rR   r   r   rK   r2   r0   Ú<module>rÕ      sé   ðá Eã Û Û ß .Ý ß ,Ó ,Ý &ã Ý Ý ß ?Ý Må  ò€õ Jð �5˜ ˜Ñ% t¨F¡|Ð3Ñ4€
ó(òVóDòD	ôK�Fô Kð\ €‡�ƒð )-ñ7Ø�S‰Mð7àð7ð �%—,‘,Ñ Ñ%ð7ð 
ò	7ó ð7ôtb5ˆKõ b5r2   