Ë
    T^(hÝ  ã                   ó¨   — d dl mZ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y)é    )ÚTYPE_CHECKINGÚListÚ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de
d	   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                 ó4   •— t        ‰| �  |fi |¤Ž || _        y ©N)ÚsuperÚ__init__r   )Úselfr   ÚkwargsÚ	__class__s      €úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_vptq.pyr   zVptqHfQuantizer.__init__(   s   ø€ Ü‰ÑÐ,Ñ7°Ò7Ø#6ˆÕ ó    c                 óX   — t        «       st        d«      ‚t        «       st        d«      ‚y )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,   s+   € Ü&Ô(ÜÐgÓhÐhä Ô"ÜÐeÓfÐfð #r   c                 ó,  — |€‘t         j                  j                  «       r't         j                  }t        j                  d«       |S dd l}t        |dd„ «      } |d«      du rt        d«      ‚t         j                  }t        j                  d«       |S )	Nz…CUDA available. Assuming VPTQ inference on GPU and loading the model in `torch.float16`. To overwrite it, set `torch_dtype` manually.r   Údevice_availabilityc                  ó   — y©NF© )Údevices    r   ú<lambda>z4VptqHfQuantizer.update_torch_dtype.<locals>.<lambda>=   s   � 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   Útorch_dtyper   r!   s       r   Úupdate_torch_dtypez"VptqHfQuantizer.update_torch_dtype3   s†   € ØÐÜ�z‰z×&Ñ&Ô(Ü#Ÿm™m�Ü—‘ð \ôð Ðó ä&-¨dÐ4IÑK_Ó&`Ð#Ù& uÓ-°Ñ5Ü&Ð'tÓuÐuÜ#Ÿm™m�Ü—‘ÐtÔuØÐr   Úmodelr	   Úkeep_in_fp32_modulesc                 óÜ   — ddl m} | j                  || j                  j                  |«      | _         ||| j                  | j                  ¬«       | j                  |j
                  _        y)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)Úintegrationsr6   Úget_modules_to_not_convertr   r7   Úconfig)r   r3   r4   r   r6   s        r   Ú$_process_model_before_weight_loadingz4VptqHfQuantizer._process_model_before_weight_loadingD   sa   € õ 	<à&*×&EÑ&EØ�4×+Ñ+×BÑBÐDXó'
ˆÔ#ñ 	!ØØ $× 8Ñ 8Ø#'×#>Ñ#>õ	
ð
 ,0×+CÑ+Cˆ�‰Õ(r   c                 ó   — |S r   r$   )r   r3   r   s      r   Ú#_process_model_after_weight_loadingz3VptqHfQuantizer._process_model_after_weight_loading[   s   € Øˆr   c                  ó   — yr#   r$   )r   r3   s     r   Úis_trainablezVptqHfQuantizer.is_trainable^   s   € àr   c                  ó   — y)NTr$   )r   Úsafe_serializations     r   Úis_serializablezVptqHfQuantizer.is_serializableb   s   € Ør   )r1   útorch.dtypeÚreturnrC   r   )r3   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationÚrequired_packagesr   r   r   r2   r   r   Ústrr;   r=   Úpropertyr?   rB   Ú__classcell__)r   s   @r   r   r       sƒ   ø„ ñð  ÐØ˜Ðð7Ð,Cõ 7ògóð( 59ñDà ðDð ' t¨C¡yÑ1óDó.ð ñ (Ð+<Ñ"=ò ó ð÷r   r   )Útypingr   r   r   Úbaser   Úmodeling_utilsr	   Úutilsr
   r   r   r   Úutils.quantization_configr   r(   Ú
get_loggerrE   r,   r   r$   r   r   ú<module>rT      sL   ð÷ 1Ñ 0å ñ Ý0ç [Ó [Ý ?ñ ÔÛà	ˆ×	Ñ	˜HÓ	%€ôC�kõ Cr   