Ë
    g^(h  ã                   ó:   — d dl Z ddlmZ dgZd„ Z G d„ de«      Zy)é    Né   )ÚBaseSchedulerÚCubicSLc                 ó.   — t        |t        || «      «      S ©N)ÚmaxÚmin)ÚxÚloÚhis      úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/pruning/scheduler/cubic_scheduler.pyÚ_clampr   
   s   € Üˆr”3�r˜1“:ÓÐó    c                   óJ   ‡ — e Zd ZdZ	 	 	 	 	 	 	 dˆ fd„	Zedd„«       Zd„ Zˆ xZS )r   aÛ  Sets the sparsity level of each parameter group to the final sl
    plus a given exponential function.

    .. math::

        s_i = s_f + (s_0 - s_f) \cdot \left( 1 - \frac{t - t_0}{n\Delta t} \right)^3

    where :math:`s_i` is the sparsity at epoch :math:`t`, :math;`s_f` is the final
    sparsity level, :math:`f(i)` is the function to be applied to the current epoch
    :math:`t`, initial epoch :math:`t_0`, and final epoch :math:`t_f`.
    :math:`\Delta t` is used to control how often the update of the sparsity level
    happens. By default,

    Args:
        sparsifier (BaseSparsifier): Wrapped sparsifier.
        init_sl (int, list): Initial level of sparsity
        init_t (int, list): Initial step, when pruning starts
        delta_t (int, list): Pruning frequency
        total_t (int, list): Total number of pruning steps
        initially_zero (bool, list): If True, sets the level of sparsity to 0
            before init_t (:math:`t_0`). Otherwise, the sparsity level before
            init_t (:math:`t_0`) is set to init_sl(:math:`s_0`)
        last_epoch (int): The index of last epoch. Default: -1.
        verbose (bool): If ``True``, prints a message to stdout for
            each update. Default: ``False``.
    c	                 ó  •— || _         | j                  |«      | _        | j                  |«      | _        | j                  |«      | _        | j                  |«      | _        | j                  |«      | _        t        ‰	| �!  |||«       y r   )	Ú
sparsifierÚ_make_sure_a_listÚinit_slÚinit_tÚdelta_tÚtotal_tÚinitially_zeroÚsuperÚ__init__)
Úselfr   r   r   r   r   r   Ú
last_epochÚverboseÚ	__class__s
            €r   r   zCubicSL.__init__*   sx   ø€ ð %ˆŒà×-Ñ-¨gÓ6ˆŒØ×,Ñ,¨VÓ4ˆŒØ×-Ñ-¨gÓ6ˆŒØ×-Ñ-¨gÓ6ˆŒà"×4Ñ4°^ÓDˆÔä‰Ñ˜ Z°Õ9r   c                 ód   — |r||k  ry|| |z
  d||z
  ||z  z  z
  dz  z  z   }t        || |«      }|S )a^   "Computes the current level of sparsity.

        Based on https://arxiv.org/pdf/1710.01878.pdf

        Args:
            s_0: Initial level of sparsity, :math:`s_i`
            s_f: Target level of sparsity, :math:`s_f`
            t: Current step, :math:`t`
            t_0: Initial step, :math:`t_0`
            dt: Pruning frequency, :math:`\Delta T`
            n: Pruning steps, :math:`n`
            initially_zero: Sets the level of sparsity to 0 before t_0.
                If False, sets to s_0

        Returns:
            The sparsity level :math:`s_t` at the current step :math:`t`
        r   g      ð?é   )r   )Ús_0Ús_fÚtÚt_0ÚdtÚnr   Ús_ts           r   Úsparsity_compute_fnzCubicSL.sparsity_compute_fn@   sM   € ñ& ˜a #šgØØ�S˜3‘Y 3¨!¨c©'°b¸1±fÑ)=Ñ#=À!Ñ"CÑCÑCˆÜ�S˜#˜sÓ#ˆØˆ
r   c                 ón  — | j                   st        j                  d«       t        | j                  | j
                  | j                  | j                  | j                  | j                  «      D ������cg c]+  \  }}}}}}| j                  ||| j                  ||||¬«      ‘Œ- c}}}}}}S c c}}}}}}w )NzUTo get the last sparsity level computed by the scheduler, please use `get_last_sl()`.)r!   r"   r#   r$   r%   r&   r   )Ú_get_sl_called_within_stepÚwarningsÚwarnÚzipr   Úbase_slr   r   r   r   r(   r   )r   Úinitial_sparsityÚfinal_sparsityÚinitial_epochÚdelta_epochÚinterval_epochsr   s          r   Úget_slzCubicSL.get_slY   s±   € Ø×.Ò.Ü�M‰Mð.ôô ruØ—‘Ø—‘Ø—‘Ø—‘Ø—‘Ø×#Ñ#ór÷
ó 
ñ nÐ  .°-ÀÈoÐ_mð ×$Ñ$Ø$Ø"Ø—/‘/Ø!ØØ!Ø-ð %õ ÷
ð 	
ù÷ 
s   Á50B-)g        r   é
   éd   FéÿÿÿÿF)F)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr(   r4   Ú__classcell__)r   s   @r   r   r      s=   ø„ ñð< ØØØØØØõ:ð, òó ðö0
r   )r+   Úbase_schedulerr   Ú__all__r   r   © r   r   ú<module>rA      s'   ðã å )ð ˆ+€òôc
ˆmõ c
r   