
    }-j	                         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 )    )TYPE_CHECKING   )HfQuantizer   )PreTrainedModel)
VptqConfig)is_accelerate_availableis_torch_availableis_vptq_availablelogging)QuantizationConfigMixinNc                   l     e Zd ZU dZdZded<   def fdZd Z	 	 dd	Z	e
d
efd            Zd Z xZS )VptqHfQuantizerzS
    Quantizer of the VPTQ method. Enables the loading of prequantized models.
    Tr   quantization_configc                 <     t                      j        |fi | d S )N)super__init__)selfr   kwargs	__class__s      f/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/transformers/quantizers/quantizer_vptq.pyr   zVptqHfQuantizer.__init__)   s)    ,7777777    c                     t                      st          d          t                      st          d          t          j                                        st          d          d S )NzGUsing `vptq` quantization requires Accelerate: `pip install accelerate`zEUsing `vptq` quantization requires VPTQ>=0.0.4: `pip install -U vptq`z,GPU is required to run VTPQ quantized model.)r	   ImportErrorr   torchcudais_availableRuntimeError)r   argsr   s      r   validate_environmentz$VptqHfQuantizer.validate_environment,   sp    &(( 	ighhh "" 	gefffz&&(( 	OMNNN	O 	Or   modelr   c                     ddl m} |                     || j        j        |j                  | _         ||| j        | j                   d S )Nr   )replace_with_vptq_linear)r   modules_to_not_convert)integrationsr#   get_modules_to_not_convertr   r$   _keep_in_fp32_modules)r   r!   r   r#   s       r   $_process_model_before_weight_loadingz4VptqHfQuantizer._process_model_before_weight_loading6   ss    
 	<;;;;;&*&E&E4+BED_'
 '
# 	!  $ 8#'#>	
 	
 	
 	
 	
 	
r   returnc                     dS )NF r   s    r   is_trainablezVptqHfQuantizer.is_trainableF   s    ur   c                     dS )NTr+   r,   s    r   is_serializablezVptqHfQuantizer.is_serializableJ   s    tr   )r!   r   )__name__
__module____qualname____doc__requires_calibration__annotations__r   r   r    r(   propertyboolr-   r/   __classcell__)r   s   @r   r   r   !   s            %%%%8,C 8 8 8 8 8 8O O O
 
 
 
 
  d    X      r   r   )typingr   baser   modeling_utilsr   utils.quantization_configr   utilsr	   r
   r   r   r   r   
get_loggerr0   loggerr   r+   r   r   <module>r@      s    !                  7000000666666 [ [ [ [ [ [ [ [ [ [ [ [ ? ? ? ? ? ?  LLL		H	%	%* * * * *k * * * * *r   