
    bi
                         d dl Z d dlmZ d dlmZ ddlmZ erddlmZ ddl	m
Z
 dd	lmZmZmZ dd
lmZ  ej        e          Z G d de          ZdS )    N)TYPE_CHECKING)version   )HfQuantizer   )PreTrainedModel)replace_with_aqlm_linear)is_accelerate_availableis_aqlm_availablelogging)QuantizationConfigMixinc                   `     e Zd ZdZdZdef fdZd Z	 	 ddZe	d	e
fd
            Zd Z xZS )AqlmHfQuantizerzS
    Quantizer of the AQLM method. Enables the loading of prequantized models.
    Tquantization_configc                 <     t                      j        |fi | d S )N)super__init__)selfr   kwargs	__class__s      a/root/projects/butler/venv/lib/python3.11/site-packages/transformers/quantizers/quantizer_aqlm.pyr   zAqlmHfQuantizer.__init__(   s)    ,7777777    c                 z    t                      st          d          t                      st          d          d S )NzGUsing `aqlm` quantization requires Accelerate: `pip install accelerate`zDUsing `aqlm` quantization requires AQLM: `pip install aqlm[gpu,cpu]`)r
   ImportErrorr   )r   argsr   s      r   validate_environmentz$AqlmHfQuantizer.validate_environment+   sJ    &(( 	ighhh "" 	fdeee	f 	fr   modelr   c                 H    t          || j        | j        j                   d S )N)r   linear_weights_not_to_quantize)r	   r   r   )r   r   r   s      r   $_process_model_before_weight_loadingz4AqlmHfQuantizer._process_model_before_weight_loading2   s7    
 	! $ 8+/+C+b	
 	
 	
 	
 	
 	
r   returnc                    t          j        t          j                             d                    t          j        d          k    }|rdS t                              dt          j                             d           d           dS )Naqlmz1.0.2Tz$Currently installed `aqlm` version (zw) doesn't support training. If you wish to train a quantized model, please update `aqlm` with `pip install aqlm>=1.0.2`F)r   parse	importlibmetadataloggerwarning)r   aqlm_supports_trainings     r   is_trainablezAqlmHfQuantizer.is_trainable=   s    !(y/A/I/I&/Q/Q!R!RV]VcdkVlVl!l! 	4NN Sy7I7Q7QRX7Y7Y  S  S  S   5r   c                     dS )NT )r   s    r   is_serializablezAqlmHfQuantizer.is_serializableH   s    tr   )r   r   )__name__
__module____qualname____doc__requires_calibrationr   r   r   r    propertyboolr*   r-   __classcell__)r   s   @r   r   r   !   s           8,C 8 8 8 8 8 8f f f	
 	
 	
 	
 	
 d    X      r   r   )r%   typingr   	packagingr   baser   modeling_utilsr   integrationsr	   utilsr
   r   r   utils.quantization_configr   
get_loggerr.   r'   r   r,   r   r   <module>r>      s                                 1000000 3 3 3 3 3 3 G G G G G G G G G G ? ? ? ? ? ? 
	H	%	%( ( ( ( (k ( ( ( ( (r   