
    bip	                         d dl mZ ddlmZ er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)is_accelerate_availableis_torch_availableis_vptq_availablelogging)QuantizationConfigMixinNc                   `     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 )VptqHfQuantizerzS
    Quantizer of the VPTQ 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_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_loading4   ss    
 	<;;;;;&*&E&E4+BED_'
 '
# 	!  $ 8#'#>	
 	
 	
 	
 	
 	
r   returnc                     dS )NF r   s    r   is_trainablezVptqHfQuantizer.is_trainableD   s    ur   c                     dS )NTr*   r+   s    r   is_serializablezVptqHfQuantizer.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O O O
 
 
 
 
  d    X      r   r   )typingr   baser   modeling_utilsr   utilsr   r	   r
   r   utils.quantization_configr   r   
get_loggerr/   loggerr   r*   r   r   <module>r>      s    !                  1000000 [ [ [ [ [ [ [ [ [ [ [ [ ? ? ? ? ? ?  LLL		H	%	%) ) ) ) )k ) ) ) ) )r   