
    gL                     j   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          Z/ G 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                   D    e Zd ZdZedefd            Ze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           	         |                     dd           }|                     dd          s|                     dd          r*|                     dd          rdnd}t          j        |z   }n|t          d          |t                                          vr9t          d| d	t          t                                                               t          |         }|                    |          S )
Nquant_methodload_in_8bitFload_in_4bit_4bit_8bitzThe 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)clsr0   r2   suffix
target_clss        X/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/quantizers/auto.pyr@   z AutoQuantizationConfig.from_dictT   s   /33NDII#''>> 	BZB^B^_motBuBu 	 8 < <^U S S`WWY`F-<vELL! \   ?DDFFFF:, : :/446677: :  
 6lC
##$<===    c                     t          j        |fi |}t          |dd           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. )r   from_pretrainedgetattrr;   rG   r@   update)rA   pretrained_model_name_or_pathkwargsmodel_configr0   rG   s         rD   rI   z&AutoQuantizationConfig.from_pretrainedi   s    !12OZZSYZZ<!6==E N<Y  N  N  N   $0#C !mm,DEE"",,V,,,""rE   N)__name__
__module____qualname____doc__classmethodr   r@   rI   rH   rE   rD   r/   r/   N   s`         
 > > > > [>( 
# 
# [
# 
# 
#rE   r/   c                       e Zd ZdZedeeef         fd            Zed             Z	edee
ef         dee         fd            ZdS )AutoHfQuantizerz
     The Auto-HF quantizer class that takes care of automatically instantiating to the correct
    `HfQuantizer` given the `QuantizationConfig`.
    rG   c           	         t          |t                    rt                              |          }|j        }|t
          j        k    r|j        r|dz  }n|dz  }|t          	                                vr9t          d| dt          t          	                                                     t          |         } ||fi |S )Nr6   r5   r7   r8   )
isinstancedictr/   r@   r2   r   r:   r3   r?   r=   r;   r>   )rA   rG   rM   r2   rC   s        rD   from_configzAutoHfQuantizer.from_config}   s     )400 	X"8"B"BCV"W"W*7 -<<<"/ (''5::<<<<:, : :/446677: :  
 ,L9
z-88888rE   c                 P    t          j        |fi |}|                     |          S )N)r/   rI   rY   )rA   rL   rM   rG   s       rD   rI   zAutoHfQuantizer.from_pretrained   s0    4DEbmmflmm2333rE   quantization_config_from_argsc                    |d}nd}t          |t                    rt                              |          }t          |t          t
          t          f          ri|g|                                }|                                D ]\  }}t          |||           |dt          |                                           dz  }|dk    rt          j        |           |S )z
        handles situations where both quantization_config from args and quantization_config from model config are present.
        NzYou 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.)rW   rX   r/   r@   r   r	   r   get_loading_attributesitemssetattrr>   r=   warningswarn)rA   rG   r[   warning_msgloading_attr_dictattrvals          rD   merge_quantization_configsz*AutoHfQuantizer.merge_quantization_configs   s    )4y K
 K)400 	X"8"B"BCV"W"W *ZO,TUU	~-9 !> T T V V.4466 8 8	c+T37777  ~EVE[E[E]E]@^@^  ~  ~  ~  ~K"M+&&&""rE   N)rO   rP   rQ   rR   rS   r   r   r   rY   rI   rX   r   rg   rH   rE   rD   rU   rU   w   s         
 9e4KT4Q.R 9 9 9 [90 4 4 [4  #"4)@#@A # (00G'H #  #  # [ #  #  #rE   rU   )1ra   typingr   r   r   models.auto.configuration_autor   utils.quantization_configr   r	   r
   r   r   r   r   r   r   r   r   r   r   quantizer_aqlmr   quantizer_awqr   quantizer_bitnetr   quantizer_bnb_4bitr   quantizer_bnb_8bitr   quantizer_compressed_tensorsr   quantizer_eetqr   quantizer_fbgemm_fp8r   quantizer_gptqr   quantizer_hqqr   quantizer_quantor    quantizer_torchaor!   r?   r<   r/   rU   rH   rE   rD   <module>rw      s{    ( ( ( ( ( ( ( ( ( ( 7 7 7 7 7 7                              , + + + + + ' ' ' ' ' ' / / / / / / 2 2 2 2 2 2 2 2 2 2 2 2 F F F F F F + + + + + + 6 6 6 6 6 6 + + + + + + ) ) ) ) ) ) / / / / / / 1 1 1 1 1 1 ++6&!    ++1!$ $   &# &# &# &# &# &# &# &#RE# E# E# E# E# E# E# E# E# E#rE   