
    `i                     B    d dl Z ddlmZ dgZd Z G d de          ZdS )    N   )BaseSchedulerCubicSLc                 >    t          |t          ||                     S N)maxmin)xlohis      ~/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torch/ao/pruning/scheduler/cubic_scheduler.py_clampr   
   s    r3r1::    c                   P     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``.
            r   
   d   Fc	                 `   || _         |                     |          | _        |                     |          | _        |                     |          | _        |                     |          | _        |                     |          | _        t                                          |||           d S 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__*   s     %--g66,,V44--g66--g66"44^DDZ99999r   c                 p    |r||k     rdS || |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@   sY    &  	a#gg1S3Y3!c'b1f)=#=!"CCCS#s##
r   c           	            j         st          j        d            fdt           j         j         j         j         j         j	                  D             S )NzUTo get the last sparsity level computed by the scheduler, please use `get_last_sl()`.c                 `    g | ]*\  }}}}}}                     ||j        ||||           +S ))r%   r&   r'   r(   r)   r*   r   )r,   r    ).0initial_sparsityfinal_sparsityinitial_epochdelta_epochinterval_epochsr   r   s          r   
<listcomp>z"CubicSL.get_sl.<locals>.<listcomp>_   sf     
 
 
 n .-o_m $$$"/!!- %  
 
 
r   )
_get_sl_called_within_stepwarningswarnzipr   base_slr   r   r   r   )r   s   `r   get_slzCubicSL.get_slY   s    . 	M.  
 
 
 
 ru#r r
 
 
 	
r   )r   r   r   r   Fr   F)F)	__name__
__module____qualname____doc__r   staticmethodr,   r;   __classcell__)r"   s   @r   r   r      s         < : : : : : :,    \0
 
 
 
 
 
 
r   )r7   base_schedulerr   __all__r   r    r   r   <module>rE      sv     ) ) ) ) ) ) +  c
 c
 c
 c
 c
m c
 c
 c
 c
 c
r   