o
    ¾e¦i~
  ã                   @   sb   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 e¡ZG dd	„ d	eƒZd
S )é    )ÚTYPE_CHECKINGé   )ÚHfQuantizeré   )ÚPreTrainedModel)Úis_auto_round_availableÚlogging)ÚQuantizationConfigMixinc                       s`   e Zd ZdZdZdef‡ fdd„Zdd„ Zdd
d„Zddd„Z	e
defdd„ƒZdd„ Z‡  ZS )ÚAutoRoundQuantizerzW
    Quantizer of the AutoRound method. (https://huggingface.co/papers/2309.05516)
    TÚquantization_configc                    s   t ƒ j|fi |¤Ž d S )N)ÚsuperÚ__init__)Úselfr   Úkwargs©Ú	__class__© új/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/transformers/quantizers/quantizer_auto_round.pyr   %   s   zAutoRoundQuantizer.__init__c                 O   s   |  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   r   r   r   Úvalidate_environment(   s   ÿÿz'AutoRoundQuantizer.validate_environmentÚmodelr   c                 K   sR   |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"   r   r   r   Ú$_process_model_before_weight_loading/   s   


ýz7AutoRoundQuantizer._process_model_before_weight_loadingc                 K   s*   | 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%   r   r   r   Ú#_process_model_after_weight_loading9   s   z6AutoRoundQuantizer._process_model_after_weight_loadingÚreturnc                 C   ó   dS )NFr   ©r   r   r   r   Úis_trainableA   ó   zAutoRoundQuantizer.is_trainablec                 C   r)   )NTr   r*   r   r   r   Úis_serializableE   r,   z"AutoRoundQuantizer.is_serializable)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_calibrationr	   r   r   r$   r'   ÚpropertyÚboolr+   r-   Ú__classcell__r   r   r   r   r
      s    


r
   N)Útypingr   Úbaser   Úmodeling_utilsr   Úutilsr   r   Úutils.quantization_configr	   Ú
get_loggerr.   r   r
   r   r   r   r   Ú<module>   s   
