
    6i
                         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y)    N)TYPE_CHECKING)version   )HfQuantizer   )PreTrainedModel)replace_with_aqlm_linear)is_accelerate_availableis_aqlm_availablelogging)QuantizationConfigMixinc                   Z     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        |   |fi | y )N)super__init__)selfr   kwargs	__class__s      b/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_aqlm.pyr   zAqlmHfQuantizer.__init__(   s    ,77    c                 X    t               st        d      t               st        d      y )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+   s+    &(ghh "dee #r   c                 \    t        || j                  | j                  j                         y )N)r   linear_weights_not_to_quantize)r	   r   r   )r   modelr   s      r   $_process_model_before_weight_loadingz4AqlmHfQuantizer._process_model_before_weight_loading2   s'    
 	! $ 8 8+/+C+C+b+b	
r   returnc                    t        j                  t        j                  j                  d            t        j                  d      k\  }|ryt        j                  dt        j                  j                  d       d       y)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=   sr    !(y/A/A/I/I&/Q!RV]VcVcdkVl!l!NN6y7I7I7Q7QRX7Y6Z  [R  S r   c                      y)NT )r   s    r   is_serializablezAqlmHfQuantizer.is_serializableH   s    r   )r   r   )__name__
__module____qualname____doc__requires_calibrationr   r   r   r    propertyboolr*   r-   __classcell__)r   s   @r   r   r   !   sP      8,C 8f	
 	
 d  r   r   )r%   typingr   	packagingr   baser   modeling_utilsr   integrationsr	   utilsr
   r   r   utils.quantization_configr   
get_loggerr.   r'   r   r,   r   r   <module>r>      sG         0 3 G G ? 
		H	%(k (r   