
    qip	                         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y)    )TYPE_CHECKING   )HfQuantizer   )PreTrainedModel)is_accelerate_availableis_torch_availableis_vptq_availablelogging)QuantizationConfigMixinNc                   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 )VptqHfQuantizerzS
    Quantizer of the VPTQ method. Enables the loading of prequantized models.
    Tquantization_configc                 &    t        |   |fi | y )N)super__init__)selfr   kwargs	__class__s      X/opt/pipecat/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_vptq.pyr   zVptqHfQuantizer.__init__'   s    ,77    c                     t               st        d      t               st        d      t        j                  j                         st        d      y )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*   sG    &(ghh "effzz&&(MNN )r   c                     ddl m} | j                  || j                  j                  |j
                        | _         ||| j                  | j                         y )Nr   )replace_with_vptq_linear)r   modules_to_not_convert)integrationsr!   get_modules_to_not_convertr   r"   _keep_in_fp32_modules)r   modelr   r!   s       r   $_process_model_before_weight_loadingz4VptqHfQuantizer._process_model_before_weight_loading4   sR    
 	<&*&E&E4++BBED_D_'
# 	! $ 8 8#'#>#>	
r   returnc                      y)NF r   s    r   is_trainablezVptqHfQuantizer.is_trainableD   s    r   c                      y)NTr*   r+   s    r   is_serializablezVptqHfQuantizer.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O
 
  d  r   r   )typingr   baser   modeling_utilsr   utilsr   r	   r
   r   utils.quantization_configr   r   
get_loggerr/   loggerr   r*   r   r   <module>r>      sG    !  0 [ [ ? 			H	%)k )r   