
    }-j~
                         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d
S )    )TYPE_CHECKING   )HfQuantizer   )PreTrainedModel)is_auto_round_availablelogging)QuantizationConfigMixinc                   d     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                      j        |fi | d S )N)super__init__)selfr   kwargs	__class__s      l/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/transformers/quantizers/quantizer_auto_round.pyr   zAutoRoundQuantizer.__init__%   s)    ,7777777    c                 t    |                     d          | _        t                      st          d          d S )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(   sB     **\22&(( 	t  	 	r   modelr   c                     |j         j        dk    rt                              d           ddlm}m} | j        r( || j                  } |||          \  }}|| _	        d S d S )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   r   r   r   r    target_devicer&   s          r   $_process_model_before_weight_loadingz7AutoRoundQuantizer._process_model_before_weight_loading/   s    ?*k99NNoppp\\\\\\\\ 	///@@M#3#3E=#I#I E=!.D	/ 	/r   c                 `    | j         rddlm}  ||| j                   d S 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   sJ     	LDDDDDDIeT/00000JKKKr   returnc                     dS )NF r   s    r   is_trainablezAutoRoundQuantizer.is_trainableA   s    ur   c                     dS )NTr/   r0   s    r   is_serializablez"AutoRoundQuantizer.is_serializableE   s    tr   )r   r   )__name__
__module____qualname____doc__requires_calibrationr
   r   r   r(   r,   propertyboolr1   r3   __classcell__)r   s   @r   r   r      s         
  8,C 8 8 8 8 8 8  / / / /L L L L d    X      r   r   N)typingr   baser   modeling_utilsr   utilsr   r	   utils.quantization_configr
   
get_loggerr4   r"   r   r/   r   r   <module>rB      s    !                  1000000 4 4 4 4 4 4 4 4 ? ? ? ? ? ? 
	H	%	%* * * * * * * * * *r   