
    }-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	 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)
SpQRConfig)replace_with_spqr_linear)is_accelerate_availableis_spqr_availableis_torch_availablelogging)QuantizationConfigMixinNc                   n     e Zd ZU dZdZded<   def fdZd Zdd
Z		 	 ddZ
ed             Zd Z xZS )SpQRHfQuantizerzS
    Quantizer of the SpQR 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_spqr.pyr   zSpQRHfQuantizer.__init__*   s)    ,7777777    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                 D    |t           j        k    rt          d          |S )NzdYou cannot use any type other than torch.float16 for SpQR. Please set it totorch.float16 explicitly.)r   float16
ValueError)r   r"   s     r   update_dtypezSpQRHfQuantizer.update_dtype7   s+    EM!!v   r   modelr   c                     |                      || j        j        |j                  | _        t	          || j        | j                   d S )N)r   modules_to_not_convert)get_modules_to_not_convertr   r+   _keep_in_fp32_modulesr	   )r   r)   r   s      r   $_process_model_before_weight_loadingz4SpQRHfQuantizer._process_model_before_weight_loading>   s^    
 '+&E&E4+BED_'
 '
# 	! $ 8#'#>	
 	
 	
 	
 	
 	
r   c                     dS )NF r   s    r   is_trainablezSpQRHfQuantizer.is_trainableL   s    ur   c                     dS )NTr0   r1   s    r   is_serializablezSpQRHfQuantizer.is_serializableP   s    tr   )r"   r#   r$   r#   )r)   r   )__name__
__module____qualname____doc__requires_calibration__annotations__r   r   r!   r(   r.   propertyr2   r4   __classcell__)r   s   @r   r   r   "   s            %%%%8,C 8 8 8 8 8 8h h h   
 
 
 
 
   X      r   r   )typingr   baser   modeling_utilsr   utils.quantization_configr   integrationsr	   utilsr
   r   r   r   r   r   
get_loggerr5   loggerr   r0   r   r   <module>rE      s   !                  7000000666666 3 3 3 3 3 3 [ [ [ [ [ [ [ [ [ [ [ [ ? ? ? ? ? ?  LLL		H	%	%/ / / / /k / / / / /r   