§
    [zniå  ã                   ó`   — d Z ddlmZmZ ddlmZmZ  e¦   «         rddlmZ 	 	 	 	 d	de	fd„Z
dS )
z;AWQ (Activation aware Weight Quantization) integration fileé   )Úis_auto_awq_availableÚis_torch_available)ÚAwqBackendPackingMethodÚAWQLinearVersioné    NFÚreturnc           	      ór  ‡— |€g }|j         }t          ¦   «         st          d¦  «        ‚|t          j        k    r	ddlm}m} n|t          j        k    rddl	m
} |t          j        k    r|j        t          j        k    r|n|}	n|}	|                      ¦   «         D �]\  }
}‰€g Š‰                     |
¦  «         t!          |t"          j        ¦  «        rƒ|
|vrt'          ˆfd„|D ¦   «         ¦  «        sd|j        }|j        } |	|j        |j        |||j        du|j        j        ¬¦  «        | j        |
<   d}| j        |
                              d	¦  «         t;          t=          |                     ¦   «         ¦  «        ¦  «        dk    rtA          ||‰||¬
¦  «        \  }}‰ !                    d¦  «         �Œ| |fS )a¥  
    Public method that recursively replaces the Linear layers of the given model with AWQ quantized layers.
    `accelerate` is needed to use this method. Returns the converted model and a boolean that indicates if the
    conversion has been successfull or not.

    During the module replacement, we also infer the backend to use through the `quantization_config` object.

    Args:
        model (`torch.nn.Module`):
            The model to convert, can be any `torch.nn.Module` instance.
        quantization_config (`AwqConfig`):
            The quantization config object that contains the quantization parameters.
        modules_to_not_convert (`list`, *optional*):
            A list of modules to not convert. If a module name is in the list (e.g. `lm_head`), it will not be
            converted.
        current_key_name (`list`, *optional*):
            A list that contains the current key name. This is used for recursion and should not be passed by the user.
        has_been_replaced (`bool`, *optional*):
            A boolean that indicates if the conversion has been successful or not. This is used for recursion and
            should not be passed by the user.
    Nz¯AWQ (either `autoawq` or `llmawq`) is not available. Please install it with `pip install autoawq` or check out the installation guide in https://github.com/mit-han-lab/llm-awqr   )ÚWQLinear_GEMMÚWQLinear_GEMV)ÚWQLinearc              3   óF   •K  — | ]}|d                       ‰¦  «        v V — ŒdS )ú.N)Újoin)Ú.0ÚkeyÚcurrent_key_names     €ú}/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/integrations/awq.pyú	<genexpr>z*replace_with_awq_linear.<locals>.<genexpr>N   s5   øè è € Ð[Ð[¸S�s˜cŸhšhÐ'7Ñ8Ô8Ð8Ð[Ð[Ð[Ð[Ð[Ð[ó    )Úw_bitÚ
group_sizeÚin_featuresÚout_featuresÚbiasÚdevTF)Úmodules_to_not_convertr   Úquantization_configÚhas_been_replacedéÿÿÿÿ)"Úbackendr   Ú
ValueErrorr   ÚAUTOAWQÚawq.modules.linearr
   r   ÚLLMAWQÚawq.quantize.qmoduler   Úversionr   ÚGEMMÚnamed_childrenÚappendÚ
isinstanceÚnnÚLinearÚanyr   r   Úbitsr   r   ÚweightÚdeviceÚ_modulesÚrequires_grad_ÚlenÚlistÚchildrenÚreplace_with_awq_linearÚpop)Úmodelr   r   r   r   r    r
   r   r   Ú
target_clsÚnameÚmoduler   r   Ú_s      `           r   r6   r6      s*  ø€ ð8 Ð%Ø!#Ðà!Ô)€Gå Ñ"Ô"ð 
Ýð ~ñ
ô 
ð 	
ð Õ)Ô1Ò1Ð1ØCÐCÐCÐCÐCÐCÐCÐCÐCØ	Õ+Ô2Ò	2Ð	2Ø1Ð1Ð1Ð1Ð1Ð1àÕ)Ô1Ò1Ð1Ø&9Ô&AÕEUÔEZÒ&ZÐ&Z�]�]Ð`mˆ
ˆ
àˆ
à×,Ò,Ñ.Ô.ð  !ñ  !‰ˆˆfØÐ#Ø!ÐØ×Ò Ñ%Ô%Ð%å�f�bœiÑ(Ô(ð 	;¨TÐ9OÐ-OÐ-OåÐ[Ð[Ð[Ð[ÐDZÐ[Ñ[Ô[Ñ[Ô[ð ;Ø$Ô0�Ø%Ô2�à'1 zØ-Ô2Ø2Ô=Ø +Ø!-Øœ¨DÐ0ØœÔ,ð(ñ (ô (�”˜tÑ$ð %)Ð!ð ”˜tÔ$×3Ò3°EÑ:Ô:Ð:Ý�t�F—O’OÑ%Ô%Ñ&Ô&Ñ'Ô'¨!Ò+Ð+Ý#:ØØ'=Ø!1Ø$7Ø"3ð$ñ $ô $Ñ ˆAÐ ð 	×Ò˜RÑ Ô Ð Ñ ØÐ#Ð#Ð#r   )NNNF)Ú__doc__Úutilsr   r   Úutils.quantization_configr   r   Útorch.nnr+   Úboolr6   © r   r   ú<module>rC      s¥   ðð >Ð =Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ Qð ÐÑÔð ØÐÐÐÐÐð
  ØØØðQ$ð Q$ð 
ðQ$ð Q$ð Q$ð Q$ð Q$ð Q$r   