o
    i
                     @   s   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eZG dd deZdS )    N)TYPE_CHECKING)version   )HfQuantizer   )PreTrainedModel)replace_with_aqlm_linear)is_accelerate_availableis_aqlm_availablelogging)QuantizationConfigMixinc                       sZ   e Zd ZdZdZdef fddZdd Z			dd
dZe	de
fddZdd Z  ZS )AqlmHfQuantizerzS
    Quantizer of the AQLM method. Enables the loading of prequantized models.
    Tquantization_configc                    s   t  j|fi | d S )N)super__init__)selfr   kwargs	__class__ h/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/transformers/quantizers/quantizer_aqlm.pyr   (   s   zAqlmHfQuantizer.__init__c                 O   s    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   r   r   r   validate_environment+   s
   z$AqlmHfQuantizer.validate_environmentmodelr   c                 K   s   t || j| jjd d S )N)r   linear_weights_not_to_quantize)r   r   r   )r   r   r   r   r   r   $_process_model_before_weight_loading2   s
   
z4AqlmHfQuantizer._process_model_before_weight_loadingreturnc                 C   sB   t tj dt 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_trainingr   r   r   is_trainable=   s   zAqlmHfQuantizer.is_trainablec                 C   s   dS )NTr   )r   r   r   r   is_serializableH   s   zAqlmHfQuantizer.is_serializable)r   r   )__name__
__module____qualname____doc__requires_calibrationr   r   r   r   propertyboolr%   r&   __classcell__r   r   r   r   r   !   s    

r   )r    typingr   	packagingr   baser   modeling_utilsr   integrationsr   utilsr	   r
   r   utils.quantization_configr   
get_loggerr'   r"   r   r   r   r   r   <module>   s   
