
    }-j              	           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dS )    )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                   v     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                 T     t                      j        |fi | |j        | _        d S )N)super__init__json_export_config)selfr   kwargs	__class__s      g/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/transformers/quantizers/quantizer_quark.pyr   zQuarkHfQuantizer.__init__2   s4    ,77777"5"H    c                 @    t                      st          d          d S )NzLoading 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   s2    !## 	 x  	 	r   modelr   c                 l    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=   sR    888888$1/;0<		
 	
 	
 	
 r   
param_namereturnc                     dS )NT )r   r#   r+   r   s       r   param_needs_quantizationz)QuarkHfQuantizer.param_needs_quantizationI   s    tr   c                     dS NFr.   r   s    r   is_serializablez QuarkHfQuantizer.is_serializableL   s    ur   c                     dS r1   r.   r2   s    r   is_trainablezQuarkHfQuantizer.is_trainableO   s    ur   c           
          ddl m} ddlm} g }t                                          D ]1\  }}|                     ||g| ||           g                     2|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88888999999 
&5&;&;&=&= 	 	"J
%/L$. 0 0 6 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 I I I I
  
 
 
 
.? S _c         X      r   r   N)typingr   baser   modeling_utilsr   utils.quantization_configr   utilsr	   r
   
get_loggerrE   loggerr>   r   r.   r   r   <module>rV      s    !                  8000000777777 / / / / / / / / 
	H	%	% -(*,6246	 	> > > > >{ > > > > >r   