
    fTh              	           S SK JrJrJr  SSKJr  SSKJr  \(       a  SSKJ	r	  \" 5       (       a  S SK
r
SSKJrJrJr  \" 5       (       a  S S	KJr  \R"                  " \5      rS
SSSSSSSS.r " S S\5      rg)    )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            
          ^  \ rS rSrSrSrS/rSrU 4S jrS r	SS	 jr
SSS
SS\S\\\4   S\4
S jr  SS jrSS jrSS jr\S 5       rSrU =r$ )QuarkHfQuantizer1   z7
Quark quantizer (https://quark.docs.amd.com/latest/).
Tquarkc                 J   > [         TU ]  " U40 UD6  UR                  U l        g N)super__init__json_export_config)selfquantization_configkwargs	__class__s      _/var/www/auris/envauris/lib/python3.13/site-packages/transformers/quantizers/quantizer_quark.pyr   QuarkHfQuantizer.__init__>   s$    ,77"5"H"H    c                 8    [        5       (       d  [        S5      eg )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_environment%QuarkHfQuantizer.validate_environmentC   s#    !## x  $r&   modelr
   c                     SSK Jn  U" UU R                  R                  U R                  R
                  U R                  R                  S9  U$ )Nr   )_map_to_quark)pack_methodcustom_mode)quark.torch.export.apir.   r!   quant_configr   r/   r0   )r    r,   r"   r.   s       r$   $_process_model_before_weight_loading5QuarkHfQuantizer._process_model_before_weight_loadingI   sD    8$$11//;;00<<		
 r&   param_valueztorch.Tensor
param_name
state_dictreturnc                     g)NT )r    r,   r5   r6   r7   r"   s         r$   check_quantized_param&QuarkHfQuantizer.check_quantized_paramU   s     r&   c                     UR                  S5      S   nU[        ;   a  UR                  U[        U   5      n[        XXBS9  g )N.)value)splitCHECKPOINT_KEYSreplacer   )r    r,   paramr6   param_devicer7   unexpected_keyspostfixs           r$   create_quantized_param'QuarkHfQuantizer.create_quantized_param_   sB     ""3'+o%#++G_W5MNJ#E|Qr&   c                     U$ r   r:   )r    r,   r"   s      r$   #_process_model_after_weight_loading4QuarkHfQuantizer._process_model_after_weight_loadingi   s    r&   c                     gNFr:   )r    safe_serializations     r$   is_serializable QuarkHfQuantizer.is_serializablel   s    r&   c                     grN   r:   )r    s    r$   is_trainableQuarkHfQuantizer.is_trainableo   s    r&   )r   )r,   r
   )r8   ztorch.nn.Parameterr   )__name__
__module____qualname____firstlineno____doc__requires_calibrationrequired_packages requires_parameters_quantizationr   r*   r3   strr   r   boolr;   rH   rK   rP   propertyrS   __static_attributes____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_loggerrU   loggerrB   r   r:   r&   r$   <module>rk      sz     , + +  0 H H <			H	% -(*,6246	@{ @r&   