CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
auto.cpython-310.pyc75 linesDownload Raw Back to __pycache__
1o

20�Yi�5�@s�ddlZddlmZmZddlmZddlmZddlm	Z	m3Z4mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZdd	l m!Z!dd5l"m#Z#ddl$m%Z%ddl&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGide%�de)�de+�d e7�d!e!�d"e?�d#eA�d$e5�d%e/�d&e9�d'e;�d(e-�d)e1�d*eE�d+e'�d,eG�d-eC�e3e#e=d.��ZHide�de
�de
�d%e�d e�d!e	�d"e�d#e�d$e�d'e�d(e�d)e�d&e�d*e�d+e�d,e�d-e�ee6ed.��ZIe�JeK�ZLGd/d0�d0�ZMGd1d2�d2�ZNd3eOfd4d5�ZPd6eOfd7d8�ZQd9d:�ZRdS);�N)�Optional�Union�)�7AutoConfig)�logging)�8AqlmConfig�AutoRoundConfig�	AwqConfig�BitNetQuantConfig�BitsAndBytesConfig�CompressedTensorsConfig�9EetqConfig�FbgemmFp8Config�FineGrainedFP8Config�
FPQuantConfig�10GPTQConfig�HiggsConfig�	HqqConfig�Mxfp4Config�QuantizationConfigMixin�QuantizationMethod�QuantoConfig�QuarkConfig�11SpQRConfig�
TorchAoConfig�12VptqConfig�)�HfQuantizer)�AqlmHfQuantizer)�AutoRoundQuantizer)�AwqQuantizer)�BitNetHfQuantizer)�Bnb4BitHfQuantizer)�Bnb8BitHfQuantizer)�CompressedTensorsHfQuantizer)�EetqHfQuantizer)�FbgemmFp8HfQuantizer)�FineGrainedFP8HfQuantizer)�FPQuantHfQuantizer)�GptqHfQuantizer)�HiggsHfQuantizer)�HqqHfQuantizer)�Mxfp4HfQuantizer)�QuantoHfQuantizer)�QuarkHfQuantizer)�SpQRHfQuantizer)�TorchAoHfQuantizer)�VptqHfQuantizerZawqZbitsandbytes_4bitZbitsandbytes_8bitZgptqZaqlmZquantoZquarkZfp_quantZeetqZhiggsZhqqzcompressed-tensorsZ13fbgemm_fp8ZtorchaoZbitnetZvptqZspqr)Zfp8z14auto-roundZmxfp4c@s.eZdZdZedefdd��Zedd��ZdS)�AutoQuantizationConfigz�15    The Auto-HF quantization config class that takes care of automatically dispatching to the correct16    quantization config given a quantization config stored in a dictionary.17    �quantization_config_dictcCs�|�d�}|�dd�s|�dd�r!|�dd�rdnd}tj|}n|dur)td��|tvr;td|�d	tt�������t|}|�|�S)18N�quant_method�load_in_8bitF�load_in_4bit�_4bit�_8bit��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�19ValueError� AUTO_QUANTIZATION_CONFIG_MAPPING�list�AUTO_QUANTIZER_MAPPING�keys�	from_dict)�clsr3r4�suffix�20target_cls�rG��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\transformers/quantizers/auto.pyrCys 21�22��23z AutoQuantizationConfig.from_dictcKsVtj|fi|��}t|dd�durtd|�d���|j}|�|�}|jdi|��|S)N�quantization_configz)Did not found a `quantization_config` in z2. Make sure that the model is correctly quantized.rG)r�from_pretrained�getattrr>rIrC�update)rD�pretrained_model_name_or_path�kwargsZmodel_configr3rIrGrGrHrJ�s24�25z&AutoQuantizationConfig.from_pretrainedN)�__name__�26__module__�__qualname__�__doc__�classmethod�dictrCrJrGrGrGrHr2ssr2c@sdeZdZdZedeeeffdd��Zedd��Z	edeeefde27efdd	��Zed28d��Z
dS)
�AutoHfQuantizerz�29     The Auto-HF quantizer class that takes care of automatically instantiating to the correct30    `HfQuantizer` given the `QuantizationConfig`.31    rIcKsxt|t�r32t�|�}|j}|tjkr|jr|d7}n|d7}|tvr0t	d|�dt33t�������t|}||fi|��S)Nr8r7r:r;)�34isinstancerTr2rCr4rr=r5rAr>r@rB)rDrIrNr4rFrGrGrH�from_config�s3536373839��zAutoHfQuantizer.from_configcKstj|fi|��}|�|�S)N)r2rJrW)rDrMrNrIrGrGrHrJ�s40zAutoHfQuantizer.from_pretrained�quantization_config_from_argscCs�|durd}nd}t|t�rt|t�rt�|�}nt�|�}|dur9|jj|jjkr9td|jj�d|jj�d���t|tt	tt41ttf�rg|durg|�
�}|��D]42\}}t|||�qP|dt|����d�7}|dkrwt|t�swt�|�|St�|�|S)	z�43        handles situations where both quantization_config from args and quantization_config from model config are present.44        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.�zThe model is quantized with z but you are passing a z| config. Please make sure to pass the same quantization config class to `from_pretrained` with different loading attributes.z"However, loading attributes (e.g. z]) will be overwritten with the one you passed to `from_pretrained`. The rest will be ignored.)rVrTrrCr2�	__class__rOr>rr	rrrZget_loading_attributes�items�setattrr@rB�warnings�warn�logger�info)rDrIrXZwarning_msgZloading_attr_dict�attr�valrGrGrH�merge_quantization_configs�s8	�454647���4849�z*AutoHfQuantizer.merge_quantization_configscCs�|�dd�}|�dd�s|�dd�r"|�dd�rdnd}tj|}n|dur*td��|tvr@t�d|�d	tt�	���d50��dSdS)Nr4r5Fr6r7r8r9r:r;z~. Hence, we will skip the quantization. To remove the warning, you can delete the quantization_config attribute in config.jsonT)51r<rr=r>r?r_�warningr@rArB)r3r4rErGrGrH�supports_quant_method�s �52��z%AutoHfQuantizer.supports_quant_methodN)rOrPrQrRrSrrrTrWrJrrc�staticmethodrerGrGrGrHrU�s5354��4rU�methodc��fdd�}|S)z-Register a custom quantization configuration.cs6�tvrtd��d���t|t�std��|t�<|S)NzConfig '�' already registeredz*Config must extend QuantizationConfigMixin)r?r>�55issubclassr�	TypeError�rD�rgrGrH�register_config_fn
�56z8register_quantization_config.<locals>.register_config_fnrG)rgrnrGrmrH�register_quantization_config57�58rp�namecrh)zRegister a custom quantizer.cs6�tvrtd��d���t|t�std��|t�<|S)NzQuantizer 'riz!Quantizer must extend HfQuantizer)rAr>rjrrl�rrrGrH�register_quantizer_fnroz1register_quantizer.<locals>.register_quantizer_fnrG)rrrtrGrsrH�register_quantizerrqrucCs�t|d�}|rt�|j�sd}|s|dur,|r t�|j|�|_n||_tj|j|d�}	nd}	|	durc|	j|||||d�|	�|�}|	�|�}|	�	|�}|	�59|�}t|	jdd�sc|	jj}60t|61d|62�|d<|	|||fS)NrIF)�
pre_quantized)�dtype�from_tf�	from_flax�63device_map�weights_onlyZ64dequantize�valueZquant)
�hasattrrUrerIrcrWZvalidate_environmentZupdate_dtypeZupdate_device_mapZupdate_tp_planZupdate_ep_planrKr4)�configrIrwrxryrzr{�65user_agentrvZhf_quantizerr4rGrGrH�get_hf_quantizer*s<66���67686970r�)Sr]�typingrrZmodels.auto.configuration_autor�utilsrZutils.quantization_configrrr	r71rrr
rrrrrrrrrrrrrr�baserZquantizer_aqlmrZquantizer_auto_roundrZ
quantizer_awqr Zquantizer_bitnetr!Zquantizer_bnb_4bitr"Zquantizer_bnb_8bitr#Zquantizer_compressed_tensorsr$Zquantizer_eetqr%Zquantizer_fbgemm_fp8r&Zquantizer_finegrained_fp8r'Zquantizer_fp_quantr(Zquantizer_gptqr)Zquantizer_higgsr*Z
quantizer_hqqr+Zquantizer_mxfp4r,Zquantizer_quantor-Zquantizer_quarkr.Zquantizer_spqrr/Zquantizer_torchaor0Zquantizer_vptqr1rAr?Z72get_loggerrOr_r2rU�strrprur�rGrGrGrH�<module>s�\��������	�73���
��������������	�74���
������75)n
Aluode/PerceptionLabPortable · CoolFace