
    Z j              	           S SK Jr  SSKJr  \(       a  SSKJr  SSKJr  SSKJ	r	J
r
  \
R                  " \5      rSS	S
SSSSSS.r " S S\5      rg)    )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                   ~   ^  \ rS rSr% SrSrS\S'   U 4S jrS rSS
 jr	SS	S\
S\4S jrS r\S 5       rS rSrU =r$ )QuarkHfQuantizer*   z7
Quark quantizer (https://quark.docs.amd.com/latest/).
Tr   quantization_configc                 J   > [         TU ]  " U40 UD6  UR                  U l        g )N)super__init__json_export_config)selfr   kwargs	__class__s      x/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/quantizers/quantizer_quark.pyr   QuarkHfQuantizer.__init__2   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_environment7   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)   r*   )r   r&   r   r(   s       r   $_process_model_before_weight_loading5QuarkHfQuantizer._process_model_before_weight_loading=   sD    8$$11//;;00<<		
 r    
param_namereturnc                     g)NT )r   r&   r/   r   s       r   param_needs_quantization)QuarkHfQuantizer.param_needs_quantizationI   s    r    c                     gNFr2   r   s    r   is_serializable QuarkHfQuantizer.is_serializableL   s    r    c                     gr6   r2   r7   s    r   is_trainableQuarkHfQuantizer.is_trainableO   s    r    c           
          SSK Jn  SSKJn  / n[        R                  5        H$  u  pEUR                  U" U/UU" U 5      /S95        M&     U$ )Nr   )WeightConverter)QuarkDeserialize)source_patternstarget_patterns
operations)core_model_loadingr>   integrations.quarkr?   CHECKPOINT_KEYSitemsappend)r   r>   r?   
converters
source_key
target_keys         r   get_weight_conversions'QuarkHfQuantizer.get_weight_conversionsS   sV    89 
&5&;&;&="J%/L$. 0 67 '> r    )r   )r&   r   )__name__
__module____qualname____firstlineno____doc__requires_calibration__annotations__r   r$   r-   strboolr3   r8   propertyr;   rK   __static_attributes____classcell__)r   s   @r   r   r   *   se      &&I

.? S _c    r    r   N)typingr   baser   modeling_utilsr   utils.quantization_configr   utilsr	   r
   
get_loggerrM   loggerrE   r   r2   r    r   <module>r`      sZ    !  07 / 
		H	% -(*,6246	>{ >r    