§
    Þ˜ºhŒ  ã                   óº   — 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      €ún/var/www/html/services/rag-service/venv/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   € Øˆ=Ý”MˆEÝ�KŠKÐbÑcÔcÐcÐcØ•e”mÒ#Ð#Ýð,ñô ð ð ˆ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Ô+ÔBÐDXñ'
ô '
ˆÔ#õ 	!ØØ $Ô 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ð ' t¨C¤yÔ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Ø [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?ð ÐÑÔð Ø€L€L€Là	ˆÔ	˜HÑ	%Ô	%€ð9ð 9ð 9ð 9ð 9�kñ 9ô 9ð 9ð 9ð 9r   