
     `i                         d dl mZ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Optional   )HfQuantizer   )PreTrainedModel)replace_with_spqr_linear)is_accelerate_availableis_spqr_availableis_torch_availablelogging)QuantizationConfigMixinNc                        e Zd ZdZdZdef fdZd Zdd	Z	 dddde	e
e                  fdZddZed             ZddZ xZS )SpQRHfQuantizerzS
    Quantizer of the SpQR method. Enables the loading of prequantized models.
    Tquantization_configc                 J     t                      j        |fi | || _        d S N)super__init__r   )selfr   kwargs	__class__s      z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/quantizers/quantizer_spqr.pyr   zSpQRHfQuantizer.__init__(   s1    ,77777#6       c                     t           j                                        st          d          t	                      st          d          t                      st          d          d S )Nz,GPU is required to run SpQR quantized model.zGUsing `spqr` quantization requires Accelerate: `pip install accelerate`zFUsing `spqr` quantization requires SpQR: `pip install spqr_quant[gpu]`)torchcudais_availableRuntimeErrorr
   ImportErrorr   )r   argsr   s      r   validate_environmentz$SpQRHfQuantizer.validate_environment,   sp    z&&(( 	OMNNN&(( 	ighhh "" 	hfggg	h 	hr   dtypetorch.dtypereturnc                     |'t           j        }t                              d           n|t           j        k    rt	          d          |S )NzHAssuming SpQR inference on GPU and loading the model in `torch.float16`.z|You cannot use any type other than torch.float16 for SpQR. Please either leave it None or set it totorch.float16 explicitly.)r   float16loggerinfo
ValueError)r   r#   s     r   update_dtypezSpQRHfQuantizer.update_dtype6   sO    =MEKKbccccem##,   r   Nmodelr   keep_in_fp32_modulesc                     |                      || j        j        |          | _        t          || j        | j                   | j        |j        _        d S )N)r   modules_to_not_convert)get_modules_to_not_convertr   r/   r	   config)r   r,   r-   r   s       r   $_process_model_before_weight_loadingz4SpQRHfQuantizer._process_model_before_weight_loadingA   sg     '+&E&E4+BDX'
 '
# 	! $ 8#'#>	
 	
 	
 	

 ,0+C(((r   c                     |S r    )r   r,   r   s      r   #_process_model_after_weight_loadingz3SpQRHfQuantizer._process_model_after_weight_loadingR   s    r   c                     dS )NFr4   )r   s    r   is_trainablezSpQRHfQuantizer.is_trainableU   s    ur   c                     dS )NTr4   )r   safe_serializations     r   is_serializablezSpQRHfQuantizer.is_serializableY   s    tr   )r#   r$   r%   r$   r   )r,   r   )__name__
__module____qualname____doc__requires_calibrationr   r   r"   r+   r   liststrr2   r5   propertyr7   r:   __classcell__)r   s   @r   r   r   !   s           7,C 7 7 7 7 7 7h h h	 	 	 	 59D D D 'tCy1D D D D"      X       r   r   )typingr   r   baser   modeling_utilsr   integrationsr	   utilsr
   r   r   r   utils.quantization_configr   r   
get_loggerr;   r(   r   r4   r   r   <module>rK      s    + * * * * * * *        1000000 3 3 3 3 3 3 [ [ [ [ [ [ [ [ [ [ [ [ ? ? ? ? ? ?  LLL		H	%	%9 9 9 9 9k 9 9 9 9 9r   