Ë
    T^(h  ã            	       óÔ   — d dl mZmZmZ ddlmZ ddlmZ erddlm	Z	  e«       rd dl
Z
ddlmZmZmZ  e«       rd d	lmZ  ej"                  e«      Zd
ddddddddœZ G d„ de«      Zy)é    )ÚTYPE_CHECKINGÚAnyÚDicté   )Úis_torch_availableé   )ÚHfQuantizer)ÚPreTrainedModelN)Úis_accelerate_availableÚis_quark_availableÚlogging)Úset_module_tensor_to_devicezweight_quantizer.scalezbias_quantizer.scalezinput_quantizer.scalezoutput_quantizer.scalezweight_quantizer.zero_pointzbias_quantizer.zero_pointzinput_quantizer.zero_pointzoutput_quantizer.zero_point)Úweight_scaleÚ
bias_scaleÚinput_scaleÚoutput_scaleÚweight_zero_pointÚbias_zero_pointÚinput_zero_pointÚoutput_zero_pointc            
       ó�   ‡ — e Zd ZdZdZdgZdZˆ fd„Zd„ Zdd„Z	ddd	d
de
dee
ef   def
d„Z	 	 dd„Zdd„Zdd„Zed„ «       Zˆ xZS )ÚQuarkHfQuantizerz?
    Quark quantizer (https://quark.docs.amd.com/latest/).
    TÚquarkc                 óH   •— t        ‰| �  |fi |¤Ž |j                  | _        y ©N)ÚsuperÚ__init__Újson_export_config)ÚselfÚquantization_configÚkwargsÚ	__class__s      €úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_quark.pyr   zQuarkHfQuantizer.__init__>   s$   ø€ Ü‰ÑÐ,Ñ7°Ò7à"5×"HÑ"HˆÕó    c                 ó.   — t        «       st        d«      ‚y )Nz¥Loading a Quark quantized model requires the `quark` library but it was not found in the environment. Please refer to https://quark.docs.amd.com/latest/install.html.)r   ÚImportError)r   Úargsr!   s      r#   Úvalidate_environmentz%QuarkHfQuantizer.validate_environmentC   s    € Ü!Ô#Üð xóð ð $r$   Úmodelr
   c                 ó¢   — ddl m}  ||| j                  j                  | j                  j
                  | j                  j                  ¬«       |S )Nr   )Ú_map_to_quark)Úpack_methodÚcustom_mode)Úquark.torch.export.apir+   r    Úquant_configr   r,   r-   )r   r)   r!   r+   s       r#   Ú$_process_model_before_weight_loadingz5QuarkHfQuantizer._process_model_before_weight_loadingI   sD   € Ý8áØØ×$Ñ$×1Ñ1Ø×/Ñ/×;Ñ;Ø×0Ñ0×<Ñ<õ		
ð ˆr$   Úparam_valueztorch.TensorÚ
param_nameÚ
state_dictÚreturnc                  ó   — y)NT© )r   r)   r1   r2   r3   r!   s         r#   Úcheck_quantized_paramz&QuarkHfQuantizer.check_quantized_paramU   s   € ð r$   c                 óŒ   — |j                  d«      d   }|t        v r|j                  |t        |   «      }t        ||||¬«       y )Nú.éÿÿÿÿ)Úvalue)ÚsplitÚCHECKPOINT_KEYSÚreplacer   )r   r)   Úparamr2   Úparam_devicer3   Úunexpected_keysÚpostfixs           r#   Úcreate_quantized_paramz'QuarkHfQuantizer.create_quantized_param_   sF   € ð ×"Ñ" 3Ó'¨Ñ+ˆà”oÑ%Ø#×+Ñ+¨G´_ÀWÑ5MÓNˆJä# E¨:°|È5ÖQr$   c                 ó   — |S r   r6   )r   r)   r!   s      r#   Ú#_process_model_after_weight_loadingz4QuarkHfQuantizer._process_model_after_weight_loadingi   s   € Øˆr$   c                  ó   — y©NFr6   )r   Úsafe_serializations     r#   Úis_serializablez QuarkHfQuantizer.is_serializablel   s   € Ør$   c                  ó   — yrG   r6   )r   s    r#   Úis_trainablezQuarkHfQuantizer.is_trainableo   s   € àr$   )r)   r
   )r4   ztorch.nn.Parameterr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationÚrequired_packagesÚ requires_parameters_quantizationr   r(   r0   Ústrr   r   Úboolr7   rC   rE   rI   ÚpropertyrK   Ú__classcell__)r"   s   @r#   r   r   1   sš   ø„ ñð  ÐØ ˜	Ðð
 (,Ð$ôIò
ó
ðà ðð $ðð ð	ð
 ˜˜c˜‘Nðð 
óðRà	óRóóð ñó ôr$   r   )Útypingr   r   r   Ú
file_utilsr   Úbaser	   Úmodeling_utilsr
   ÚtorchÚutilsr   r   r   Úaccelerate.utilsr   Ú
get_loggerrL   Úloggerr=   r   r6   r$   r#   ú<module>r`      sv   ð÷  ,Ñ +å +Ý ñ Ý0áÔÛç HÑ Hñ ÔÝ<à	ˆ×	Ñ	˜HÓ	%€ð -Ø(Ø*Ø,Ø6Ø2Ø4Ø6ñ	€ô@�{õ @r$   