§
    Þ˜º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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)Úis_accelerate_availableÚis_torch_availableÚis_vptq_availableÚlogging)ÚQuantizationConfigMixinNc                   ó˜   ‡ — e Zd ZdZdZdg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	efd„¦   «         Zdd„Zˆ xZS )ÚVptqHfQuantizerzS
    Quantizer of the VPTQ method. Enables the loading of prequantized models.
    TÚvptqÚ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_vptq.pyr   zVptqHfQuantizer.__init__(   s1   ø€ Ø�‰ŒÔÐ,Ð7Ð7°Ð7Ð7Ð7Ø#6ˆÔ Ð Ð ó    c                 óz   — t          ¦   «         st          d¦  «        ‚t          ¦   «         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`)r	   ÚImportErrorr   )r   Úargsr   s      r   Úvalidate_environmentz$VptqHfQuantizer.validate_environment,   sJ   € Ý&Ñ(Ô(ð 	iÝÐgÑhÔhÐhå Ñ"Ô"ð 	gÝÐeÑfÔfÐfð	gð 	gr   Údtypeútorch.dtypeÚreturnc                 óD  — |€�t           j                             ¦   «         r't           j        }t                               d¦  «         nXdd l}t          |dd„ ¦  «        } |d¦  «        du rt          d¦  «        ‚t           j	        }t                               d¦  «         |S )	NzCUDA available. Assuming VPTQ inference on GPU and loading the model in `torch.float16`. To overwrite it, set `dtype` manually.r   Údevice_availabilityc                 ó   — dS ©NF© )Údevices    r   ú<lambda>z.VptqHfQuantizer.update_dtype.<locals>.<lambda>=   s   € ÐZ_€ r   ÚcpuTzKNo GPU found. Please wait for the next release of VPTQ to use CPU inferencezVNo GPU found. Assuming VPTQ inference on CPU and loading the model in `torch.float32`.)
ÚtorchÚcudaÚis_availableÚfloat16ÚloggerÚinfor   ÚgetattrÚRuntimeErrorÚfloat32)r   r   r   r#   s       r   Úupdate_dtypezVptqHfQuantizer.update_dtype3   s¬   € Øˆ=ÝŒz×&Ò&Ñ(Ô(ð vÝœ�Ý—’ð Vñô ð ð ð ���å&-¨dÐ4IÐK_ÐK_Ñ&`Ô&`Ð#Ø&Ð& uÑ-Ô-°Ð5Ð5Ý&Ð'tÑuÔuÐuÝœ�Ý—’ÐtÑuÔuÐuØˆr   NÚmodelr   Úkeep_in_fp32_modulesc                 ó°   — ddl m} |                      || j        j        |¦  «        | _         ||| j        | j        ¬¦  «         | j        |j        _        dS )zÄ
        we don't have param like modules_to_not_convert to indicate which layers should not be quantized
        because `quantization_config` include the layers that should be quantized
        r   )Úreplace_with_vptq_linear)r   Úmodules_to_not_convertN)Úintegrationsr7   Úget_modules_to_not_convertr   r8   Úconfig)r   r4   r5   r   r7   s        r   Ú$_process_model_before_weight_loadingz4VptqHfQuantizer._process_model_before_weight_loadingD   s|   € ð 	<Ð;Ð;Ð;Ð;Ð;à&*×&EÒ&EØ�4Ô+ÔBÐDXñ'
ô '
ˆÔ#ð 	!Ð ØØ $Ô 8Ø#'Ô#>ð	
ñ 	
ô 	
ð 	
ð
 ,0Ô+CˆŒÔ(Ð(Ð(r   c                 ó   — |S r   r&   )r   r4   r   s      r   Ú#_process_model_after_weight_loadingz3VptqHfQuantizer._process_model_after_weight_loading[   s   € Øˆr   c                 ó   — dS r%   r&   )r   s    r   Úis_trainablezVptqHfQuantizer.is_trainable^   s   € àˆur   c                 ó   — dS )NTr&   )r   Úsafe_serializations     r   Úis_serializablezVptqHfQuantizer.is_serializableb   s   € Øˆtr   )r   r    r!   r    r   )r4   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationÚrequired_packagesr   r   r   r3   r   ÚlistÚstrr<   r>   ÚpropertyÚboolr@   rC   Ú__classcell__)r   s   @r   r   r       s  ø€ € € € € ðð ð  ÐØ˜Ðð7Ð,Cð 7ð 7ð 7ð 7ð 7ð 7ðgð gð gðð ð ð ð( 59ðDð Dà ðDð ' t¨C¤yÔ1ðDð Dð Dð Dð.ð ð ð ð ð˜dð ð ð ñ „Xððð ð ð ð ð ð ð r   r   )Útypingr   r   Úbaser   Úmodeling_utilsr   Úutilsr	   r
   r   r   Úutils.quantization_configr   r*   Ú
get_loggerrD   r.   r   r&   r   r   ú<module>rU      sï   ðð +Ð *Ð *Ð *Ð *Ð *Ð *Ð *à Ð Ð Ð Ð Ð ð ð 1Ø0Ð0Ð0Ð0Ð0Ð0à [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?ð ÐÑÔð Ø€L€L€Là	ˆÔ	˜HÑ	%Ô	%€ðCð Cð Cð Cð C�kñ Cô Cð Cð Cð Cr   