o
    ¦ôjL  ã                   @   sP  d dl Z d dlmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, eeee&ee*e"e(e e$e,edœZ-e	eeeeeeeeeee
dœZ.G dd„ dƒZ/G dd„ dƒZ0dS )é    N)ÚDictÚOptionalÚUnioné   )Ú
AutoConfig)Ú
AqlmConfigÚ	AwqConfigÚBitNetConfigÚBitsAndBytesConfigÚCompressedTensorsConfigÚ
EetqConfigÚFbgemmFp8ConfigÚ
GPTQConfigÚ	HqqConfigÚQuantizationConfigMixinÚQuantizationMethodÚQuantoConfigÚTorchAoConfigé   )ÚAqlmHfQuantizer)ÚAwqQuantizer)ÚBitNetHfQuantizer)ÚBnb4BitHfQuantizer)ÚBnb8BitHfQuantizer)ÚCompressedTensorsHfQuantizer)ÚEetqHfQuantizer)ÚFbgemmFp8HfQuantizer)ÚGptqHfQuantizer)ÚHqqHfQuantizer)ÚQuantoHfQuantizer)ÚTorchAoHfQuantizer)ÚawqÚbitsandbytes_4bitÚbitsandbytes_8bitÚgptqÚaqlmÚquantoÚeetqÚhqqúcompressed-tensorsÚ
fbgemm_fp8ÚtorchaoÚbitnet)r!   r"   r#   r'   r$   r%   r&   r(   r)   r*   r+   r,   c                   @   s.   e Zd ZdZedefdd„ƒZedd„ ƒZdS )ÚAutoQuantizationConfigz·
    The Auto-HF quantization config class that takes care of automatically dispatching to the correct
    quantization config given a quantization config stored in a dictionary.
    Úquantization_config_dictc                 C   sŽ   |  dd ¡}|  dd¡s|  dd¡r"|  dd¡rdnd}tj| }n|d u r*tdƒ‚|t ¡ vr>td|› d	tt ¡ ƒ› �ƒ‚t| }| |¡S )
NÚquant_methodÚload_in_8bitFÚload_in_4bitÚ_4bitÚ_8bitz‰The model's quantization config from the arguments has no `quant_method` attribute. Make sure that the model has been correctly quantizedúUnknown quantization type, got ú - supported types are: )	Úgetr   ÚBITS_AND_BYTESÚ
ValueErrorÚ AUTO_QUANTIZATION_CONFIG_MAPPINGÚkeysÚlistÚAUTO_QUANTIZER_MAPPINGÚ	from_dict)Úclsr.   r/   ÚsuffixÚ
target_cls© rA   úm/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/transformers/quantizers/auto.pyr=   T   s    ÿ
ÿÿ
z AutoQuantizationConfig.from_dictc                 K   sV   t j|fi |¤Ž}t|dd ƒd u rtd|› d�ƒ‚|j}|  |¡}|jdi |¤Ž |S )NÚquantization_configz)Did not found a `quantization_config` in z2. Make sure that the model is correctly quantized.rA   )r   Úfrom_pretrainedÚgetattrr8   rC   r=   Úupdate)r>   Úpretrained_model_name_or_pathÚkwargsÚmodel_configr.   rC   rA   rA   rB   rD   i   s   
ÿ
z&AutoQuantizationConfig.from_pretrainedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r=   rD   rA   rA   rA   rB   r-   N   s    r-   c                   @   sX   e Zd ZdZedeeef fdd„ƒZedd„ ƒZ	edee
ef dee fdd	„ƒZd
S )ÚAutoHfQuantizerz–
     The Auto-HF quantizer class that takes care of automatically instantiating to the correct
    `HfQuantizer` given the `QuantizationConfig`.
    rC   c                 K   s|   t |tƒr
t |¡}|j}|tjkr|jr|d7 }n|d7 }|t 	¡ vr2t
d|› dtt 	¡ ƒ› �ƒ‚t| }||fi |¤ŽS )Nr3   r2   r4   r5   )Ú
isinstanceÚdictr-   r=   r/   r   r7   r0   r<   r:   r8   r;   )r>   rC   rH   r/   r@   rA   rA   rB   Úfrom_config}   s   




ÿÿzAutoHfQuantizer.from_configc                 K   s   t j|fi |¤Ž}|  |¡S )N)r-   rD   rR   )r>   rG   rH   rC   rA   rA   rB   rD   –   s   
zAutoHfQuantizer.from_pretrainedÚquantization_config_from_argsc                 C   s’   |durd}nd}t |tƒrt |¡}t |tttfƒr>|dur>| ¡ }| ¡ D ]
\}}t	|||ƒ q'|dt
| ¡ ƒ› d�7 }|dkrGt |¡ |S )z„
        handles situations where both quantization_config from args and quantization_config from model config are present.
        NzÑYou passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading already has a `quantization_config` attribute. The `quantization_config` from the model will be used.Ú z"However, loading attributes (e.g. z]) will be overwritten with the one you passed to `from_pretrained`. The rest will be ignored.)rP   rQ   r-   r=   r   r   r   Zget_loading_attributesÚitemsÚsetattrr;   r:   ÚwarningsÚwarn)r>   rC   rS   Úwarning_msgZloading_attr_dictÚattrÚvalrA   rA   rB   Úmerge_quantization_configs›   s    	ÿ

ÿ
z*AutoHfQuantizer.merge_quantization_configsN)rJ   rK   rL   rM   rN   r   r   r   rR   rD   rQ   r   r\   rA   rA   rA   rB   rO   w   s    

þýrO   )1rW   Útypingr   r   r   Úmodels.auto.configuration_autor   Úutils.quantization_configr   r   r	   r
   r   r   r   r   r   r   r   r   r   Zquantizer_aqlmr   Zquantizer_awqr   Zquantizer_bitnetr   Zquantizer_bnb_4bitr   Zquantizer_bnb_8bitr   Zquantizer_compressed_tensorsr   Zquantizer_eetqr   Zquantizer_fbgemm_fp8r   Zquantizer_gptqr   Zquantizer_hqqr   Zquantizer_quantor   Zquantizer_torchaor    r<   r9   r-   rO   rA   rA   rA   rB   Ú<module>   sX   <ôô)