
    6i~
                         d dl mZ ddlmZ erddlmZ ddlmZmZ ddl	m
Z
  ej                  e      Z G d d	e      Zy
)    )TYPE_CHECKING   )HfQuantizer   )PreTrainedModel)is_auto_round_availablelogging)QuantizationConfigMixinc                   ^     e Zd ZdZdZdef fdZd ZddZddZ	e
defd	       Zd
 Z xZS )AutoRoundQuantizerzW
    Quantizer of the AutoRound method. (https://huggingface.co/papers/2309.05516)
    Tquantization_configc                 &    t        |   |fi | y )N)super__init__)selfr   kwargs	__class__s      h/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/quantizers/quantizer_auto_round.pyr   zAutoRoundQuantizer.__init__%   s    ,77    c                 Z    |j                  d      | _        t               st        d      y )N
device_mapzbLoading an AutoRound quantized model requires auto-round library (`pip install 'auto-round>=0.5'`))getr   r   ImportError)r   argsr   s      r   validate_environmentz'AutoRoundQuantizer.validate_environment(   s-     **\2&(t  )r   c                     |j                   j                  dk7  rt        j                  d       ddlm}m} | j                  r& || j                        } |||      \  }}|| _	        y y )N	input_idszRAutoRound offers only limited support for models that are not strictly text-based.r   )convert_hf_modelinfer_target_device)
r   main_input_nameloggerwarning"auto_round.inference.convert_modelr   r   pre_quantizedr   used_backends)r   modelr   r   r   target_devicer%   s          r   $_process_model_before_weight_loadingz7AutoRoundQuantizer._process_model_before_weight_loading/   sY    ??**k9NNop\/@M#3E=#I E=!.D r   c                 d    | j                   rddlm}  ||| j                         y t	        d      )Nr   )	post_initz+AutoRound only sports pre-quantized models.)r$   r#   r*   r%   
ValueError)r   r&   r   r*   s       r   #_process_model_after_weight_loadingz6AutoRoundQuantizer._process_model_after_weight_loading9   s*    DeT//0JKKr   returnc                      y)NF r   s    r   is_trainablezAutoRoundQuantizer.is_trainableA   s    r   c                      y)NTr/   r0   s    r   is_serializablez"AutoRoundQuantizer.is_serializableE   s    r   )r&   r   )__name__
__module____qualname____doc__requires_calibrationr
   r   r   r(   r,   propertyboolr1   r3   __classcell__)r   s   @r   r   r      sM    
  8,C 8/L d  r   r   N)typingr   baser   modeling_utilsr   utilsr   r	   utils.quantization_configr
   
get_loggerr4   r!   r   r/   r   r   <module>rB      s;    !  0 4 ? 
		H	%* *r   