§
    \zni¦h  ã                   óØ  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZmZmZ d dlmZ ddlmZmZ  e¦   «         rd dlZ ej        e¦  «        Z G d„ d	ee¦  «        Z G d
„ dee¦  «        Z G d„ dee¦  «        Ze G d„ d¦  «        ¦   «         Ze G d„ de¦  «        ¦   «         Z G d„ dee¦  «        Ze G d„ de¦  «        ¦   «         Z e G d„ de¦  «        ¦   «         Z!dS )é    N)Ú	dataclass)ÚEnum)ÚAnyÚDictÚListÚOptionalÚUnion)Úversioné   )Úis_torch_availableÚloggingc                   ó   — e Zd ZdZdZdZdS )ÚQuantizationMethodÚbitsandbytesÚgptqÚawqN)Ú__name__Ú
__module__Ú__qualname__ÚBITS_AND_BYTESÚGPTQÚAWQ© ó    ú†/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/utils/quantization_config.pyr   r   %   s   € € € € € Ø#€NØ€DØ
€C€C€Cr   r   c                   ó   — e Zd ZdZdZdS )ÚAWQLinearVersionÚgemmÚgemvN)r   r   r   ÚGEMMÚGEMVr   r   r   r   r   +   s   € € € € € Ø€DØ€D€D€Dr   r   c                   ó   — e Zd ZdZdZdS )ÚAwqBackendPackingMethodÚautoawqzllm-awqN)r   r   r   ÚAUTOAWQÚLLMAWQr   r   r   r#   r#   0   s   € € € € € Ø€GØ€F€F€Fr   r#   c                   ó�   — e Zd ZU dZeed<   edd„¦   «         Zdee	e
j        f         fd„Zdee	ef         fd„Zd	„ Zddede	fd„ZdS )ÚQuantizationConfigMixinz-
    Mixin class for quantization config
    Úquant_methodFc                 óü   —  | di |¤Ž}g }|                      ¦   «         D ];\  }}t          ||¦  «        r&t          |||¦  «         |                     |¦  «         Œ<|D ]}|                     |d¦  «         Œ|r||fS |S )aÍ  
        Instantiates a [`QuantizationConfigMixin`] from a Python dictionary of parameters.

        Args:
            config_dict (`Dict[str, Any]`):
                Dictionary that will be used to instantiate the configuration object.
            return_unused_kwargs (`bool`,*optional*, defaults to `False`):
                Whether or not to return a list of unused keyword arguments. Used for `from_pretrained` method in
                `PreTrainedModel`.
            kwargs (`Dict[str, Any]`):
                Additional parameters from which to initialize the configuration object.

        Returns:
            [`QuantizationConfigMixin`]: The configuration object instantiated from those parameters.
        Nr   )ÚitemsÚhasattrÚsetattrÚappendÚpop)ÚclsÚconfig_dictÚreturn_unused_kwargsÚkwargsÚconfigÚ	to_removeÚkeyÚvalues           r   Ú	from_dictz!QuantizationConfigMixin.from_dict=   s¯   € ð$ �Ð#Ð#�{Ð#Ð#ˆàˆ	Ø Ÿ,š,™.œ.ð 	&ð 	&‰JˆC�Ý�v˜sÑ#Ô#ð &Ý˜  UÑ+Ô+Ð+Ø× Ò  Ñ%Ô%Ð%øØð 	"ð 	"ˆCØ�JŠJ�s˜DÑ!Ô!Ð!Ð!àð 	Ø˜6�>Ð!àˆMr   Újson_file_pathc                 óâ   — t          |dd¬¦  «        5 }|                      ¦   «         }t          j        |dd¬¦  «        dz   }|                     |¦  «         ddd¦  «         dS # 1 swxY w Y   dS )	aÃ  
        Save this instance to a JSON file.

        Args:
            json_file_path (`str` or `os.PathLike`):
                Path to the JSON file in which this configuration instance's parameters will be saved.
            use_diff (`bool`, *optional*, defaults to `True`):
                If set to `True`, only the difference between the config instance and the default
                `QuantizationConfig()` is serialized to JSON file.
        Úwzutf-8)Úencodingr   T©ÚindentÚ	sort_keysú
N)ÚopenÚto_dictÚjsonÚdumpsÚwrite)Úselfr9   Úwriterr1   Újson_strings        r   Úto_json_filez$QuantizationConfigMixin.to_json_file^   s´   € õ �. #°Ð8Ñ8Ô8ð 	&¸FØŸ,š,™.œ.ˆKÝœ* [¸ÀdÐKÑKÔKÈdÑRˆKà�LŠL˜Ñ%Ô%Ð%ð		&ð 	&ð 	&ñ 	&ô 	&ð 	&ð 	&ð 	&ð 	&ð 	&ð 	&ð 	&øøøð 	&ð 	&ð 	&ð 	&ð 	&ð 	&s   “AA$Á$A(Á+A(Úreturnc                 ó4   — t          j        | j        ¦  «        S )ú´
        Serializes this instance to a Python dictionary. Returns:
            `Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance.
        )ÚcopyÚdeepcopyÚ__dict__©rF   s    r   rB   zQuantizationConfigMixin.to_dicto   s   € õ
 Œ}˜Tœ]Ñ+Ô+Ð+r   c                 óH   — | j         j        › d|                      ¦   «         › �S )Nú )Ú	__class__r   Úto_json_stringrP   s    r   Ú__repr__z QuantizationConfigMixin.__repr__v   s'   € Ø”.Ô)ÐCÐC¨D×,?Ò,?Ñ,AÔ,AÐCÐCÐCr   TÚuse_diffc                 ó�   — |du r|                       ¦   «         }n|                      ¦   «         }t          j        |dd¬¦  «        dz   S )a²  
        Serializes this instance to a JSON string.

        Args:
            use_diff (`bool`, *optional*, defaults to `True`):
                If set to `True`, only the difference between the config instance and the default `PretrainedConfig()`
                is serialized to JSON string.

        Returns:
            `str`: String containing all the attributes that make up this configuration instance in JSON format.
        Tr   r=   r@   )Úto_diff_dictrB   rC   rD   )rF   rV   r1   s      r   rT   z&QuantizationConfigMixin.to_json_stringy   sK   € ð �tÐÐØ×+Ò+Ñ-Ô-ˆKˆKàŸ,š,™.œ.ˆKÝŒz˜+¨a¸4Ð@Ñ@Ô@À4ÑGÐGr   N)F)T)r   r   r   Ú__doc__r   Ú__annotations__Úclassmethodr8   r	   ÚstrÚosÚPathLikerI   r   r   rB   rU   ÚboolrT   r   r   r   r(   r(   5   sÙ   € € € € € € ðð ð %Ð$Ð$Ñ$àðð ð ñ „[ðð@&¨5°°b´kÐ1AÔ+Bð &ð &ð &ð &ð",˜˜c 3˜hœð ,ð ,ð ,ð ,ðDð Dð DðHð H tð H°sð Hð Hð Hð Hð Hð Hr   r(   c                   ó|   — e Zd ZdZ	 	 	 	 	 	 	 	 	 dd„Zd„ Zd„ Zd	„ Zd
ee	e
f         fd„Zd„ Zd
ee	e
f         fd„ZdS )ÚBitsAndBytesConfigaÄ  
    This is a wrapper class about all possible attributes and features that you can play with a model that has been
    loaded using `bitsandbytes`.

    This replaces `load_in_8bit` or `load_in_4bit`therefore both options are mutually exclusive.

    Currently only supports `LLM.int8()`, `FP4`, and `NF4` quantization. If more methods are added to `bitsandbytes`,
    then more arguments will be added to this class.

    Args:
        load_in_8bit (`bool`, *optional*, defaults to `False`):
            This flag is used to enable 8-bit quantization with LLM.int8().
        load_in_4bit (`bool`, *optional*, defaults to `False`):
            This flag is used to enable 4-bit quantization by replacing the Linear layers with FP4/NF4 layers from
            `bitsandbytes`.
        llm_int8_threshold (`float`, *optional*, defaults to 6.0):
            This corresponds to the outlier threshold for outlier detection as described in `LLM.int8() : 8-bit Matrix
            Multiplication for Transformers at Scale` paper: https://arxiv.org/abs/2208.07339 Any hidden states value
            that is above this threshold will be considered an outlier and the operation on those values will be done
            in fp16. Values are usually normally distributed, that is, most values are in the range [-3.5, 3.5], but
            there are some exceptional systematic outliers that are very differently distributed for large models.
            These outliers are often in the interval [-60, -6] or [6, 60]. Int8 quantization works well for values of
            magnitude ~5, but beyond that, there is a significant performance penalty. A good default threshold is 6,
            but a lower threshold might be needed for more unstable models (small models, fine-tuning).
        llm_int8_skip_modules (`List[str]`, *optional*):
            An explicit list of the modules that we do not want to convert in 8-bit. This is useful for models such as
            Jukebox that has several heads in different places and not necessarily at the last position. For example
            for `CausalLM` models, the last `lm_head` is kept in its original `dtype`.
        llm_int8_enable_fp32_cpu_offload (`bool`, *optional*, defaults to `False`):
            This flag is used for advanced use cases and users that are aware of this feature. If you want to split
            your model in different parts and run some parts in int8 on GPU and some parts in fp32 on CPU, you can use
            this flag. This is useful for offloading large models such as `google/flan-t5-xxl`. Note that the int8
            operations will not be run on CPU.
        llm_int8_has_fp16_weight (`bool`, *optional*, defaults to `False`):
            This flag runs LLM.int8() with 16-bit main weights. This is useful for fine-tuning as the weights do not
            have to be converted back and forth for the backward pass.
        bnb_4bit_compute_dtype (`torch.dtype` or str, *optional*, defaults to `torch.float32`):
            This sets the computational type which might be different than the input time. For example, inputs might be
            fp32, but computation can be set to bf16 for speedups.
        bnb_4bit_quant_type (`str`,  *optional*, defaults to `"fp4"`):
            This sets the quantization data type in the bnb.nn.Linear4Bit layers. Options are FP4 and NF4 data types
            which are specified by `fp4` or `nf4`.
        bnb_4bit_use_double_quant (`bool`, *optional*, defaults to `False`):
            This flag is used for nested quantization where the quantization constants from the first quantization are
            quantized again.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional parameters from which to initialize the configuration object.
    Fç      @NÚfp4c
                 óª  — t           j        | _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |€t          j        | _        nat          |t          ¦  «        rt!          t          |¦  «        | _        n1t          |t          j        ¦  «        r|| _        nt%          d¦  «        ‚|                      ¦   «          d S )Nz8bnb_4bit_compute_dtype must be a string or a torch.dtype)r   r   r)   Úload_in_8bitÚload_in_4bitÚllm_int8_thresholdÚllm_int8_skip_modulesÚ llm_int8_enable_fp32_cpu_offloadÚllm_int8_has_fp16_weightÚbnb_4bit_quant_typeÚbnb_4bit_use_double_quantÚtorchÚfloat32Úbnb_4bit_compute_dtypeÚ
isinstancer\   ÚgetattrÚdtypeÚ
ValueErrorÚ	post_init)rF   re   rf   rg   rh   ri   rj   ro   rk   rl   r3   s              r   Ú__init__zBitsAndBytesConfig.__init__¿   sÒ   € õ /Ô=ˆÔØ(ˆÔØ(ˆÔØ"4ˆÔØ%:ˆÔ"Ø0PˆÔ-Ø(@ˆÔ%Ø#6ˆÔ Ø)BˆÔ&à!Ð)Ý*/¬-ˆDÔ'Ð'ÝÐ.µÑ4Ô4ð 	YÝ*1µ%Ð9OÑ*PÔ*PˆDÔ'Ð'ÝÐ.µ´Ñ<Ô<ð 	YØ*@ˆDÔ'Ð'åÐWÑXÔXÐXà�ŠÑÔÐÐÐr   c                 ó(  — t          | j        t          ¦  «        st          d¦  «        ‚| j        �)t          | j        t
          ¦  «        st          d¦  «        ‚t          | j        t          ¦  «        st          d¦  «        ‚t          | j        t          ¦  «        st          d¦  «        ‚| j	        �.t          | j	        t          j        ¦  «        st          d¦  «        ‚t          | j        t          ¦  «        st          d¦  «        ‚t          | j        t          ¦  «        st          d¦  «        ‚| j        rVt!          j        t$          j                             d	¦  «        ¦  «        t!          j        d
¦  «        k    st          d¦  «        ‚dS dS )z~
        Safety checker that arguments are correct - also replaces some NoneType arguments with their default values.
        z"llm_int8_threshold must be a floatNz/llm_int8_skip_modules must be a list of stringsz2llm_int8_enable_fp32_cpu_offload must be a booleanz*llm_int8_has_fp16_weight must be a booleanz*bnb_4bit_compute_dtype must be torch.dtypez$bnb_4bit_quant_type must be a stringz+bnb_4bit_use_double_quant must be a booleanr   z0.39.0z[4 bit quantization requires bitsandbytes>=0.39.0 - please upgrade your bitsandbytes version)rp   rg   Úfloatrs   rh   Úlistri   r_   rj   ro   rm   rr   rk   r\   rl   rf   r
   ÚparseÚ	importlibÚmetadatarP   s    r   rt   zBitsAndBytesConfig.post_initá   sˆ  € õ ˜$Ô1µ5Ñ9Ô9ð 	CÝÐAÑBÔBÐBàÔ%Ð1½*ÀTÔE_ÕaeÑ:fÔ:fÐ1ÝÐNÑOÔOÐOÝ˜$Ô?ÅÑFÔFð 	SÝÐQÑRÔRÐRå˜$Ô7½Ñ>Ô>ð 	KÝÐIÑJÔJÐJàÔ&Ð2½:ÀdÔFaÕchÔcnÑ;oÔ;oÐ2ÝÐIÑJÔJÐJå˜$Ô2µCÑ8Ô8ð 	EÝÐCÑDÔDÐDå˜$Ô8½$Ñ?Ô?ð 	LÝÐJÑKÔKÐKàÔð 	¥W¤]µ9Ô3E×3MÒ3MÈnÑ3]Ô3]Ñ%^Ô%^ÕbiÔboØñc
ô c
ò &
ð &
õ Ømñô ð ð	ð 	ð &
ð &
r   c                 ó   — | j         p| j        S )zP
        Returns `True` if the model is quantizable, `False` otherwise.
        )re   rf   rP   s    r   Úis_quantizablez!BitsAndBytesConfig.is_quantizable   s   € ð Ô Ð5 DÔ$5Ð5r   c                 óh   — | j         rdS | j        r| j        dk    rdS | j        r| j        dk    rdS dS )z�
        This method returns the quantization method used for the model. If the model is not quantizable, it returns
        `None`.
        Úllm_int8rc   Únf4N)re   rf   rk   rP   s    r   Úquantization_methodz&BitsAndBytesConfig.quantization_method  sS   € ð
 Ôð 	Ø�:ØÔð 	 4Ô#;¸uÒ#DÐ#DØ�5ØÔð 	 4Ô#;¸uÒ#DÐ#DØ�5à�4r   rJ   c                 óš   — t          j        | j        ¦  «        }t          |d         ¦  «                             d¦  «        d         |d<   |S )rL   ro   ú.é   )rM   rN   rO   r\   Úsplit)rF   Úoutputs     r   rB   zBitsAndBytesConfig.to_dict  sH   € õ
 ”˜tœ}Ñ-Ô-ˆÝ+.¨vÐ6NÔ/OÑ+PÔ+P×+VÒ+VÐWZÑ+[Ô+[Ð\]Ô+^ˆÐ'Ñ(àˆr   c                 óx   — |                       ¦   «         }| j        j        › dt          j        |dd¬¦  «        › d�S )NrR   r   Tr=   r@   )rB   rS   r   rC   rD   )rF   r1   s     r   rU   zBitsAndBytesConfig.__repr__  s=   € Ø—l’l‘n”nˆØ”.Ô)ÐaÐa­D¬J°{È1ÐX\Ð,]Ñ,]Ô,]ÐaÐaÐaÐar   c                 óÈ   — |                       ¦   «         }t          ¦   «                               ¦   «         }i }|                     ¦   «         D ]\  }}|||         k    r|||<   Œ|S )a'  
        Removes all attributes from config which correspond to the default config attributes for better readability and
        serializes to a Python dictionary.

        Returns:
            `Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance,
        )rB   ra   r+   )rF   r1   Údefault_config_dictÚserializable_config_dictr6   r7   s         r   rX   zBitsAndBytesConfig.to_diff_dict"  su   € ð —l’l‘n”nˆõ 1Ñ2Ô2×:Ò:Ñ<Ô<Ðà#%Ð ð &×+Ò+Ñ-Ô-ð 	6ð 	6‰JˆC�ØÐ+¨CÔ0Ò0Ð0Ø05Ð(¨Ñ-øà'Ð'r   )	FFrb   NFFNrc   F)r   r   r   rY   ru   rt   r}   r�   r   r\   r   rB   rU   rX   r   r   r   ra   ra   Œ   sÖ   € € € € € ð/ð /ðf ØØØ"Ø).Ø!&Ø#Ø!Ø"'ð ð  ð  ð  ðDð ð ð>6ð 6ð 6ðð ð ð˜˜c 3˜hœð ð ð ð ðbð bð bð(˜d 3¨ 8œnð (ð (ð (ð (ð (ð (r   ra   c                   ó   — e Zd ZdZdZdS )ÚExllamaVersionr„   r   N)r   r   r   ÚONEÚTWOr   r   r   rŒ   rŒ   9  s   € € € € € Ø
€CØ
€C€C€Cr   rŒ   c            &       óV  ‡ — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d ded	ed
eeee	         e	f                  dede
dededededee         dee	         deee	                  dedee         dee         dee         deee	ef                  def$d„Zd„ Zd„ Zˆ fd„Zd„ Zed„ ¦   «         Zˆ xZS )!Ú
GPTQConfiga^  
    This is a wrapper class about all possible attributes and features that you can play with a model that has been
    loaded using `optimum` api for gptq quantization relying on auto_gptq backend.

    Args:
        bits (`int`):
            The number of bits to quantize to, supported numbers are (2, 3, 4, 8).
        tokenizer (`str` or `PreTrainedTokenizerBase`, *optional*):
            The tokenizer used to process the dataset. You can pass either:
                - A custom tokenizer object.
                - A string, the *model id* of a predefined tokenizer hosted inside a model repo on huggingface.co.
                    Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
                    user or organization name, like `dbmdz/bert-base-german-cased`.
                - A path to a *directory* containing vocabulary files required by the tokenizer, for instance saved
                    using the [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.
        dataset (`Union[List[str]]`, *optional*):
            The dataset used for quantization. You can provide your own dataset in a list of string or just use the
            original datasets used in GPTQ paper ['wikitext2','c4','c4-new','ptb','ptb-new']
        group_size (`int`, *optional*, defaults to 128):
            The group size to use for quantization. Recommended value is 128 and -1 uses per-column quantization.
        damp_percent (`float`, *optional*, defaults to 0.1):
            The percent of the average Hessian diagonal to use for dampening. Recommended value is 0.1.
        desc_act (`bool`, *optional*, defaults to `False`):
            Whether to quantize columns in order of decreasing activation size. Setting it to False can significantly
            speed up inference but the perplexity may become slightly worse. Also known as act-order.
        sym (`bool`, *optional*, defaults to `True`):
            Whether to use symetric quantization.
        true_sequential (`bool`, *optional*, defaults to `True`):
            Whether to perform sequential quantization even within a single Transformer block. Instead of quantizing
            the entire block at once, we perform layer-wise quantization. As a result, each layer undergoes
            quantization using inputs that have passed through the previously quantized layers.
        use_cuda_fp16 (`bool`, *optional*, defaults to `False`):
            Whether or not to use optimized cuda kernel for fp16 model. Need to have model in fp16.
        model_seqlen (`int`, *optional*):
            The maximum sequence length that the model can take.
        block_name_to_quantize (`str`, *optional*):
            The transformers block name to quantize.
        module_name_preceding_first_block (`List[str]`, *optional*):
            The layers that are preceding the first Transformer block.
        batch_size (`int`, *optional*, defaults to 1):
            The batch size used when processing the dataset
        pad_token_id (`int`, *optional*):
            The pad token id. Needed to prepare the dataset when `batch_size` > 1.
        use_exllama (`bool`, *optional*):
            Whether to use exllama backend. Defaults to `True` if unset. Only works with `bits` = 4.
        max_input_length (`int`, *optional*):
            The maximum input length. This is needed to initialize a buffer that depends on the maximum expected input
            length. It is specific to the exllama backend with act-order.
        exllama_config (`Dict[str, Any]`, *optional*):
            The exllama config. You can specify the version of the exllama kernel through the `version` key. Defaults
            to `{"version": 1}` if unset.
        cache_block_outputs (`bool`, *optional*, defaults to `True`):
                Whether to cache block outputs to reuse as inputs for the succeeding block.
    Né€   çš™™™™™¹?FTr„   ÚbitsÚ	tokenizerÚdatasetÚ
group_sizeÚdamp_percentÚdesc_actÚsymÚtrue_sequentialÚuse_cuda_fp16Úmodel_seqlenÚblock_name_to_quantizeÚ!module_name_preceding_first_blockÚ
batch_sizeÚpad_token_idÚuse_exllamaÚmax_input_lengthÚexllama_configÚcache_block_outputsc                 ó‚  — t           j        | _        || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        |                     dd ¦  «        | _        || _        |                      ¦   «          d S ©NÚdisable_exllama)r   r   r)   r“   r”   r•   r–   r—   r˜   r™   rš   r›   rœ   r�   rž   rŸ   r    r¡   r¢   r£   r/   r§   r¤   rt   )rF   r“   r”   r•   r–   r—   r˜   r™   rš   r›   rœ   r�   rž   rŸ   r    r¡   r¢   r£   r¤   r3   s                       r   ru   zGPTQConfig.__init__w  sÅ   € õ, /Ô3ˆÔØˆŒ	Ø"ˆŒØˆŒØ$ˆŒØ(ˆÔØ ˆŒØˆŒØ.ˆÔØ*ˆÔØ(ˆÔØ&<ˆÔ#Ø1RˆÔ.Ø$ˆŒØ(ˆÔØ&ˆÔØ 0ˆÔØ,ˆÔØ%ŸzšzÐ*;¸TÑBÔBˆÔØ#6ˆÔ Ø�ŠÑÔÐÐÐr   c                 ó‚   ‡— t          j        | j        ¦  «        }g d¢Šˆfd„|                     ¦   «         D ¦   «         }|S )N)r§   r¡   r£   r›   r¢   c                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS r   r   )Ú.0ÚiÚjÚloading_attibutess      €r   ú
<dictcomp>z5GPTQConfig.get_loading_attributes.<locals>.<dictcomp>¦  s*   ø€ Ð!dÐ!dÐ!d©4¨1¨aÈQÐRcÐMcÐMc ! QÐMcÐMcÐMcr   )rM   rN   rO   r+   )rF   Úattibutes_dictÚloading_attibutes_dictr­   s      @r   Úget_loading_attributesz!GPTQConfig.get_loading_attributes£  sL   ø€ Ýœ t¤}Ñ5Ô5ˆØuÐuÐuÐØ!dÐ!dÐ!dÐ!d°>×3GÒ3GÑ3IÔ3IÐ!dÑ!dÔ!dÐØ%Ð%r   c                 ó®  — | j         dvrt          d| j         › �¦  «        ‚| j        dk    r| j        dk    rt          d¦  «        ‚d| j        cxk     rdk     sn t          d¦  «        ‚| j        �lt          | j        t          ¦  «        r!| j        d	vrt          d
| j        › �¦  «        ‚n1t          | j        t          ¦  «        st          d| j        › �¦  «        ‚| j        €| j	        €d| _	        nZ| j        �6| j	        €/t                               d¦  «         | j         | _	        d| _        n| j        �| j	        �t          d¦  «        ‚| j        €dt          j        i| _        n\d| j        vrt          d¦  «        ‚| j        d         t          j        t          j        fvr| j        d         }t          d|› �¦  «        ‚| j         dk    �r | j	        rû| j        d         t          j        k    rt                               d¦  «         dS | j        d         t          j        k    r«t#          j        t&          j                             d¦  «        ¦  «        }t#          j        t&          j                             d¦  «        ¦  «        }|t#          j        d¦  «        k    s|t#          j        d¦  «        k    rt          d|› d|› �¦  «        ‚dS dS dS dS )ú;
        Safety checker that arguments are correct
        )r   é   é   é   z6Only support quantization to [2,3,4,8] bits but found éÿÿÿÿr   z0group_size must be greater than 0 or equal to -1r„   z"damp_percent must between 0 and 1.N)Ú	wikitext2Úc4zc4-newÚptbzptb-newz›You have entered a string value for dataset. You can only choose between
                        ['wikitext2','c4','c4-new','ptb','ptb-new'], but we found zˆdataset needs to be either a list of string or a value in
                    ['wikitext2','c4','c4-new','ptb','ptb-new'], but we found Ta  Using `disable_exllama` is deprecated and will be removed in version 4.37. Use `use_exllama` instead and specify the version with `exllama_config`.The value of `use_exllama` will be overwritten by `disable_exllama` passed in `GPTQConfig` or stored in your config file.zVCannot specify both `disable_exllama` and `use_exllama`. Please use just `use_exllama`r
   z/`exllama_config` needs to have a `version` key.zaOnly supported versions are in [ExllamaVersion.ONE, ExllamaVersion.TWO] - not recognized version rµ   z„You have activated exllama backend. Note that you can get better inference speed using exllamav2 kernel by setting `exllama_config`.ÚoptimumÚ	auto_gptqz1.13.2z0.4.2zxYou need optimum > 1.13.2 and auto-gptq > 0.4.2 . Make sure to have that version installed - detected version : optimum z and autogptq )r“   rs   r–   r—   r•   rp   r\   rx   r§   r¡   ÚloggerÚwarningr£   rŒ   r�   rŽ   Úinfor
   ry   rz   r{   )rF   Úexllama_versionÚoptimum_versionÚautogptq_versions       r   rt   zGPTQConfig.post_init©  se  € ð Œ9˜LÐ(Ð(ÝÐaÐVZÔV_ÐaÐaÑbÔbÐbØŒ?˜bÒ Ð  T¤_¸Ò%9Ð%9ÝÐOÑPÔPÐPØ�DÔ%Ð)Ð)Ò)Ð)¨Ò)Ð)Ð)Ð)ÝÐAÑBÔBÐBØŒ<Ð#Ý˜$œ,­Ñ,Ô,ð 
Ø”<Ð'VÐVÐVÝ$ðdØSWÔS_ðdð dñô ð ð Wõ
   ¤­dÑ3Ô3ð Ý ð`ØOSÌ|ð`ð `ñô ð ð
 ÔÐ'¨DÔ,<Ð,Dà#ˆDÔÐØÔ!Ð-°$Ô2BÐ2Jå�NŠNðLñô ð ð $(Ô#7Ð7ˆDÔØ#'ˆDÔ Ð ØÔ!Ð-°$Ô2BÐ2NåÐuÑvÔvÐvàÔÐ&Ø#,­nÔ.@Ð"AˆDÔÐà Ô 3Ð3Ð3Ý Ð!RÑSÔSÐSØÔ$ YÔ/½Ô8JÍNÔL^Ð7_Ð_Ð_Ø"&Ô"5°iÔ"@�Ý ð Jð  yHð  Jð  Jñô ð ð Œ9˜Š>‰>˜dÔ.ˆ>ØÔ" 9Ô-µÔ1CÒCÐCÝ—’ðPñô ð ð ð ð Ô$ YÔ/µ>Ô3EÒEÐEÝ")¤-µ	Ô0B×0JÒ0JÈ9Ñ0UÔ0UÑ"VÔ"V�Ý#*¤=µÔ1C×1KÒ1KÈKÑ1XÔ1XÑ#YÔ#YÐ Ø"¥g¤m°HÑ&=Ô&=Ò=Ð=ÐAQÕU\ÔUbÐcjÑUkÔUkÒAkÐAkÝ$ð Eð  Tcð  Eð  Eð  sCð  Eð  Eñô ð ð ˆ>ˆ>ˆ>ð FÐEð BlÐAkr   c                 ót   •— t          ¦   «                              ¦   «         }|                     dd ¦  «         |S r¦   )ÚsuperrB   r/   )rF   r1   rS   s     €r   rB   zGPTQConfig.to_dictè  s1   ø€ Ý‘g”g—o’oÑ'Ô'ˆØ�ŠÐ)¨4Ñ0Ô0Ð0ØÐr   c                 óD   — |                       ¦   «         }| j         |d<   |S )z=
        Get compatible dict for optimum gptq config
        r§   )rB   r¡   )rF   Ú
quant_dicts     r   Úto_dict_optimumzGPTQConfig.to_dict_optimumí  s(   € ð —\’\‘^”^ˆ
à,0Ô,<Ð(<ˆ
Ð$Ñ%ØÐr   c                 ó@   — d|v r|d          |d<   d|d<    | di |¤Ž}|S )zD
        Get compatible class with optimum gptq config dict
        r§   r¡   Nr   r   )r0   r1   r4   s      r   Úfrom_dict_optimumzGPTQConfig.from_dict_optimumö  sG   € ð  Ð+Ð+Ø-8Ð9JÔ-KÐ)KˆK˜Ñ&à-1ˆKÐ)Ñ*à�Ð#Ð#�{Ð#Ð#ˆØˆr   )NNr‘   r’   FTTFNNNr„   NNNNT)r   r   r   rY   Úintr   r   r	   r   r\   rw   r_   r   ru   r±   rt   rB   rÇ   r[   rÉ   Ú__classcell__)rS   s   @r   r�   r�   >  sÉ  ø€ € € € € ð5ð 5ðt Ø37ØØ!ØØØ $Ø#Ø&*Ø04ØAEØØ&*Ø&*Ø*.Ø37Ø$(ð'*ð *àð*ð ð*ð ˜%  S¤	¨3 Ô/Ô0ð	*ð
 ð*ð ð*ð ð*ð ð*ð ð*ð ð*ð ˜s”mð*ð !)¨¤ð*ð ,4°D¸´IÔ+>ð*ð ð*ð ˜s”mð*ð  ˜d”^ð!*ð" # 3œ-ð#*ð$ !  c¨3 h¤Ô0ð%*ð& "ð'*ð *ð *ð *ðX&ð &ð &ð=ð =ð =ð~ð ð ð ð ð
ð ð ð ðð ñ „[ðð ð ð ð r   r�   c                   óT   — e Zd ZdZdddej        ej        fdedede	ded	ef
d
„Z
d„ ZdS )Ú	AwqConfigaj  
    This is a wrapper class about all possible attributes and features that you can play with a model that has been
    loaded using `auto-awq` library awq quantization relying on auto_awq backend.

    Args:
        bits (`int`, *optional*, defaults to 4):
            The number of bits to quantize to.
        group_size (`int`, *optional*, defaults to 128):
            The group size to use for quantization. Recommended value is 128 and -1 uses per-column quantization.
        zero_point (`bool`, *optional*, defaults to `True`):
            Whether to use zero point quantization.
        version (`AWQLinearVersion`, *optional*, defaults to `AWQLinearVersion.GEMM`):
            The version of the quantization algorithm to use. GEMM is better for big batch_size (e.g. >= 8) otherwise,
            GEMV is better (e.g. < 8 )
        backend (`AwqBackendPackingMethod`, *optional*, defaults to `AwqBackendPackingMethod.AUTOAWQ`):
            The quantization backend. Some models might be quantized using `llm-awq` backend. This is useful for users
            that quantize their own models using `llm-awq` library.
    rµ   r‘   Tr“   r–   Ú
zero_pointr
   Úbackendc                 ó–   — t           j        | _        || _        || _        || _        || _        || _        |                      ¦   «          d S )N)	r   r   r)   r“   r–   rÎ   r
   rÏ   rt   )rF   r“   r–   rÎ   r
   rÏ   r3   s          r   ru   zAwqConfig.__init__  sH   € õ /Ô2ˆÔàˆŒ	Ø$ˆŒØ$ˆŒØˆŒØˆŒà�ŠÑÔÐÐÐr   c                 ó
  — t           j                             ¦   «         st          d¦  «        ‚| j        t
          j        t
          j        fvr1t          dt
          j        › dt
          j        › d| j        › �¦  «        ‚| j        t          j
        t          j        fvrt          d| j        › �¦  «        ‚| j        t
          j        k    r8t           j                             ¦   «         }|\  }}|dk     rt          d¦  «        ‚dS dS )	r³   zAWQ is only available on GPUz(Only supported quantization backends in z and z - not recognized backend zgOnly supported versions are in [AWQLinearVersion.GEMM, AWQLinearVersion.GEMV] - not recognized version r¶   zHLLM-AWQ backend is only supported on GPUs with compute capability >= 8.0N)rm   ÚcudaÚis_availablers   rÏ   r#   r%   r&   r
   r   r    r!   Úget_device_capability)rF   Úcompute_capabilityÚmajorÚminors       r   rt   zAwqConfig.post_init-  s:  € õ Œz×&Ò&Ñ(Ô(ð 	=ÝÐ;Ñ<Ô<Ð<àŒ<Õ 7Ô ?ÕAXÔA_Ð`Ð`Ð`Ýð jÕ;RÔ;Zð  jð  jÕaxÔað  jð  jð  \`ô  \hð  jð  jñô ð ð Œ<Õ 0Ô 5Õ7GÔ7LÐMÐMÐMÝð IÐz~ô  {Gð  Ið  Iñô ð ð Œ<Õ2Ô9Ò9Ð9Ý!&¤×!AÒ!AÑ!CÔ!CÐØ-‰LˆE�5Ø�qŠyˆyÝ Ð!kÑlÔlÐlð	 :Ð9ð ˆyr   N)r   r   r   rY   r   r    r#   r%   rÊ   r_   ru   rt   r   r   r   rÍ   rÍ     s’   € € € € € ðð ð* ØØØ$4Ô$9Ø+BÔ+Jðð àðð ðð ð	ð
 "ðð )ðð ð ð ð&mð mð mð mð mr   rÍ   )"rM   Úimportlib.metadatarz   rC   r]   Údataclassesr   Úenumr   Útypingr   r   r   r   r	   Ú	packagingr
   Úutilsr   r   rm   Ú
get_loggerr   r½   r\   r   r   r#   r(   ra   rÊ   rŒ   r�   rÍ   r   r   r   ú<module>rß      s–  ðð" €€€Ø Ð Ð Ð Ø €€€Ø 	€	€	€	Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3à Ð Ð Ð Ð Ð à /Ð /Ð /Ð /Ð /Ð /Ð /Ð /ð ÐÑÔð Ø€L€L€Lð 
ˆÔ	˜HÑ	%Ô	%€ðð ð ð ð ˜˜dñ ô ð ðð ð ð ð �s˜Dñ ô ð ð
ð ð ð ð ˜c 4ñ ô ð ð
 ðSHð SHð SHð SHð SHñ SHô SHñ „ðSHðl ði(ð i(ð i(ð i(ð i(Ð0ñ i(ô i(ñ „ði(ðXð ð ð ð �S˜$ñ ô ð ð
 ðCð Cð Cð Cð CÐ(ñ Cô Cñ „ðCðL ð<mð <mð <mð <mð <mÐ'ñ <mô <mñ „ð<mð <mð <mr   