Ë
    îÍ:jÈ  ã            	       óŒ   — d dl mZ ddlmZ erddlmZ ddlmZmZ  ej                  e
«      Zddd	d
dddddœZ G d„ de«      Zy)é    )ÚTYPE_CHECKINGé   )ÚHfQuantizeré   )ÚPreTrainedModel)Úis_quark_availableÚloggingz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                   óx   ‡ — e Zd ZdZdZdgZdZˆ fd„Zd„ Zdd„Z	ddd	e
d
efd„Z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      €ú|/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_quark.pyr   zQuarkHfQuantizer.__init__7   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_environment<   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_loadingB   sD   € Ý8áØØ×$Ñ$×1Ñ1Ø×/Ñ/×;Ñ;Ø×0Ñ0×<Ñ<õ		
ð ˆr   Ú
param_nameÚreturnc                  ó   — y)NT© )r   r$   r,   r   s       r   Úparam_needs_quantizationz)QuarkHfQuantizer.param_needs_quantizationN   s   € Ør   c                 ó¬   — ddl m} |j                  d«      d   }|t        v r|j	                  |t        |   «      } ||||j                  |«      «       y )Nr   )Ú_load_parameter_into_modelú.éÿÿÿÿ)Úmodeling_utilsr2   ÚsplitÚCHECKPOINT_KEYSÚreplaceÚto)r   r$   Úparamr,   Úparam_devicer   r2   Úpostfixs           r   Úcreate_quantized_paramz'QuarkHfQuantizer.create_quantized_paramQ   sN   € Ý?à×"Ñ" 3Ó'¨Ñ+ˆà”oÑ%Ø#×+Ñ+¨G´_ÀWÑ5MÓNˆJá" 5¨*°e·h±h¸|Ó6LÕMr   c                 ó   — |S r   r/   )r   r$   r   s      r   Ú#_process_model_after_weight_loadingz4QuarkHfQuantizer._process_model_after_weight_loading[   s   € Øˆr   c                  ó   — y©NFr/   )r   Úsafe_serializations     r   Úis_serializablez QuarkHfQuantizer.is_serializable^   s   € Ør   c                  ó   — yrA   r/   )r   s    r   Úis_trainablezQuarkHfQuantizer.is_trainablea   s   € àr   )r$   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationÚrequired_packagesÚ requires_parameters_quantizationr   r#   r+   ÚstrÚboolr0   r=   r?   rC   ÚpropertyrE   Ú__classcell__)r   s   @r   r   r   *   sp   ø„ ñð  ÐØ ˜	Ðð
 (,Ð$ôIò
ó
ðÐ.?ð ÈSð Ð_có òNóóð ñó ôr   r   N)Útypingr   Úbaser   r5   r   Úutilsr   r	   Ú
get_loggerrF   Úloggerr7   r   r/   r   r   ú<module>rV      sY   ðõ  !å ñ Ý0ç /ð 
ˆ×	Ñ	˜HÓ	%€ð -Ø(Ø*Ø,Ø6Ø2Ø4Ø6ñ	€ô9�{õ 9r   