Ë
    Hêñi  ã            	       ó˜   — d dl 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
  e
j                  e«      Zdd	d
ddddddœZ G d„ de«      Zy)é    )ÚTYPE_CHECKINGé   )ÚHfQuantizeré   )ÚPreTrainedModel)ÚQuarkConfig)Ú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                   óp   ‡ — e Zd ZU dZdZded<   ˆ fd„Zd„ Zdd	„Zddd
e	de
fd„Zd„ Zed„ «       Zd„ Zˆ xZS )ÚQuarkHfQuantizerz?
    Quark quantizer (https://quark.docs.amd.com/latest/).
    Tr   Úquantization_configc                 óH   •— t        ‰| �  |fi |¤Ž |j                  | _        y )N)ÚsuperÚ__init__Újson_export_config)Úselfr   ÚkwargsÚ	__class__s      €úi/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_quark.pyr   zQuarkHfQuantizer.__init__2   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_environment7   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_loading=   sD   € Ý8áØØ×$Ñ$×1Ñ1Ø×/Ñ/×;Ñ;Ø×0Ñ0×<Ñ<õ		
ð ˆr   Ú
param_nameÚreturnc                  ó   — y)NT© )r   r#   r+   r   s       r   Úparam_needs_quantizationz)QuarkHfQuantizer.param_needs_quantizationI   s   € Ør   c                  ó   — y©NFr.   ©r   s    r   Úis_serializablez QuarkHfQuantizer.is_serializableL   s   € Ør   c                  ó   — yr1   r.   r2   s    r   Úis_trainablezQuarkHfQuantizer.is_trainableO   s   € àr   c           
      óž   — ddl m} ddlm} g }t        j                  «       D ]'  \  }}|j                   ||g| || «      g¬«      «       Œ) |S )Nr   )ÚWeightConverter)ÚQuarkDeserialize)Úsource_patternsÚtarget_patternsÚ
operations)Úcore_model_loadingr7   Úintegrations.quarkr8   ÚCHECKPOINT_KEYSÚitemsÚappend)r   r7   r8   Ú
convertersÚ
source_keyÚ
target_keys         r   Úget_weight_conversionsz'QuarkHfQuantizer.get_weight_conversionsS   s]   € Ý8Ý9ð ˆ
Ü&5×&;Ñ&;Ó&=ò 	Ñ"ˆJ˜
Ø×ÑÙØ%/ LØ$.Ù 0°Ó 6Ð7ôõð	ð Ðr   )r#   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationÚ__annotations__r   r"   r*   ÚstrÚboolr/   r3   Úpropertyr5   rD   Ú__classcell__)r   s   @r   r   r   *   s`   ø… ñð  ÐØ&Ó&ôIò
ó
ðÐ.?ð ÈSð Ð_có òð ñó ðör   r   N)Útypingr   Úbaser   Úmodeling_utilsr   Úutils.quantization_configr   Úutilsr	   r
   Ú
get_loggerrE   Úloggerr>   r   r.   r   r   ú<module>rV      s\   ðõ !å ñ Ý0Ý7ç /ð 
ˆ×	Ñ	˜HÓ	%€ð -Ø(Ø*Ø,Ø6Ø2Ø4Ø6ñ	€ô>�{õ >r   