
    gl                         d dl Z d dlmZ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mZ dd
lmZ  e            rd dlZ ej        e          Z G d de          ZdS )    N)TYPE_CHECKINGOptional)version   )HfQuantizer   )PreTrainedModel)replace_with_aqlm_linear)is_accelerate_availableis_aqlm_availableis_torch_availablelogging)QuantizationConfigMixinc                        e Zd ZdZdZdgZdZdef fdZd Z	ddZ
	 	 ddZddZedded         fd            ZddZ xZS )AqlmHfQuantizerzS
    Quantizer of the AQLM method. Enables the loading of prequantized models.
    TaqlmNquantization_configc                 J     t                      j        |fi | || _        d S N)super__init__r   )selfr   kwargs	__class__s      b/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/quantizers/quantizer_aqlm.pyr   zAqlmHfQuantizer.__init__-   s1    ,77777#6       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_environment1   sJ    &(( 	ighhh "" 	fdeee	f 	fr   torch_dtypetorch.dtypereturnc                     |kt           j                                        r't           j        }t                              d           n&t           j        }t                              d           |S )NzCUDA available. Assuming AQLM inference on GPU and loading the model in `torch.float16`. To overwrite it, set `torch_dtype` manually.zCUDA is unavailable. Assuming AQLM inference on CPU and loading the model in `torch.float32`. To overwrite it, set `torch_dtype` manually.)torchcudais_availablefloat16loggerinfofloat32)r   r!   s     r   update_torch_dtypez"AqlmHfQuantizer.update_torch_dtype8   ss    z&&(( 	#m \    $m a   r   modelr	   c                 j    t          || j        | j        j                   | j        |j        _        d S )N)r   linear_weights_not_to_quantize)r
   r   r/   configr   r-   r   s      r   $_process_model_before_weight_loadingz4AqlmHfQuantizer._process_model_before_weight_loadingF   sB    
 	! $ 8+/+C+b	
 	
 	
 	

 ,0+C(((r   c                     |S r    r1   s      r   #_process_model_after_weight_loadingz3AqlmHfQuantizer._process_model_after_weight_loadingR   s    r   c                    t          j        t          j                             d                    t          j        d          k    }|rdS t                              dt          j                             d           d           dS )Nr   z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metadatar)   warning)r   r-   aqlm_supports_trainings      r   is_trainablezAqlmHfQuantizer.is_trainableU   s    !(y/A/I/I&/Q/Q!R!RV]VcdkVlVl!l! 	4NN Sy7I7Q7QRX7Y7Y  S  S  S   5r   c                     dS )NTr4   )r   safe_serializations     r   is_serializablezAqlmHfQuantizer.is_serializable`   s    tr   )r!   r"   r#   r"   )r-   r	   r   )__name__
__module____qualname____doc__requires_calibrationrequired_packagesoptimum_quantizerr   r   r    r,   r2   r5   propertyr   r<   r?   __classcell__)r   s   @r   r   r   $   s          7,C 7 7 7 7 7 7f f f   
D 
D 
D 
D 
D     (+<"=    X       r   r   )r8   typingr   r   	packagingr   baser   modeling_utilsr	   integrationsr
   utilsr   r   r   r   utils.quantization_configr   r%   
get_loggerr@   r)   r   r4   r   r   <module>rQ      s       * * * * * * * *              1000000 3 3 3 3 3 3 [ [ [ [ [ [ [ [ [ [ [ [ ? ? ? ? ? ?  LLL		H	%	%= = = = =k = = = = =r   