Ë
    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	 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)Ú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de	d   fd„«       Zdd„Zˆ xZS )ÚSpQRHfQuantizerzS
    Quantizer of the SpQR method. Enables the loading of prequantized models.
    TÚ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_spqr.pyr   zSpQRHfQuantizer.__init__(   s   ø€ Ü‰ÑÐ,Ñ7°Ò7Ø#6ˆÕ ó    c                 óª   — t         j                  j                  «       st        d«      ‚t	        «       st        d«      ‚t        «       st        d«      ‚y )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,   sG   € Ü�z‰z×&Ñ&Ô(ÜÐMÓNÐNä&Ô(ÜÐgÓhÐhä Ô"ÜÐfÓgÐgð #r   c                 ó”   — |€'t         j                  }t        j                  d«       |S |t         j                  k7  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   Útorch_dtypes     r   Úupdate_torch_dtypez"SpQRHfQuantizer.update_torch_dtype6   sN   € ØÐÜŸ-™-ˆKÜ�K‰KÐbÔcð Ðð œEŸM™MÒ)Üð,óð ð Ðr   Úmodelr	   Úkeep_in_fp32_modulesc                 óÖ   — | j                  || j                  j                  |«      | _        t        || j                  | j                  ¬«       | j                  |j                  _        y )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   s^   € ð '+×&EÑ&EØ�4×+Ñ+×BÑBÐDXó'
ˆÔ#ô 	!ØØ $× 8Ñ 8Ø#'×#>Ñ#>õ	
ð
 ,0×+CÑ+Cˆ�‰Õ(r   c                 ó   — |S r   © )r   r+   r   s      r   Ú#_process_model_after_weight_loadingz3SpQRHfQuantizer._process_model_after_weight_loadingR   s   € Øˆr   c                  ó   — y)NFr3   )r   r+   s     r   Úis_trainablezSpQRHfQuantizer.is_trainableU   s   € àr   c                  ó   — y)NTr3   )r   Úsafe_serializations     r   Úis_serializablezSpQRHfQuantizer.is_serializableY   s   € Ør   )r)   útorch.dtypeÚreturnr:   r   )r+   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationr   r   r#   r*   r   r   Ústrr1   r4   Úpropertyr6   r9   Ú__classcell__)r   s   @r   r   r   !   s{   ø„ ñð  Ðð7Ð,Cõ 7òhó	ð 59ñDà ðDð ' t¨C¡yÑ1óDó"ð ñ (Ð+<Ñ"=ò ó ð÷r   r   )Útypingr   r   r   Úbaser   Úmodeling_utilsr	   Úintegrationsr
   Úutilsr   r   r   r   Úutils.quantization_configr   r   Ú
get_loggerr<   r&   r   r3   r   r   ú<module>rK      sM   ð÷ 1Ñ 0å ñ Ý0å 3ß [Ó [Ý ?ñ ÔÛà	ˆ×	Ñ	˜HÓ	%€ô9�kõ 9r   