§
    ‚Štj  ã            
       óÞ   — d Z ddlmZ ddlmZmZ  e¦   «         r
ddlZddlmZ  ej	        e
¦  «        Zdddœdd	dœdd	dœdd
dœdddœdd	dœdddœdd	dœdœZd„ Z	 	 	 ddeez  dz  defd„ZdS )z;AWQ (Activation aware Weight Quantization) integration fileé   )Úshould_convert_module)Úis_torch_availableÚloggingé    NÚactÚc_fc)r   Úlayer_before_actÚdense_h_to_4hÚup_projÚfc_inÚ	gelu_impl)Ú
starcoder2ÚRefinedWebModelÚfalconÚmptÚgptjÚgpt_neoxÚgpt_bigcodeÚbloomc                 ó”  — ddl m} |t          vr| S |                      ¦   «         D ]¡\  }}t          |         d         }t          |         d         }||k    r`t	          | |¦  «        rPt          | t          |         d         ¦  «        }|j        }t          j        |¦  «        }	 |||	¦  «        | j	        |<   t          ||¦  «        }
Œ¢| S )Nr   )ÚScaledActivationr   r	   )Ú&gptqmodel.quantization.awq.modules.actr   ÚAWQ_SCALES_MAPPINGSÚnamed_childrenÚhasattrÚgetattrÚout_featuresÚtorchÚonesÚ_modulesÚreplace_quantization_scales)ÚmodelÚ
model_typer   ÚnameÚmoduleÚact_nameÚlayer_before_act_namer	   ÚsizeÚ
scale_likeÚ_s              ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/integrations/awq.pyr!   r!   '   sá   € ØGÐGÐGÐGÐGÐGàÕ,Ð,Ð,ØˆØ×,Ò,Ñ.Ô.ð <ð <‰ˆˆfÝ& zÔ2°5Ô9ˆÝ 3°JÔ ?Ð@RÔ SÐØ�8ÒÐ¥¨Ð/DÑ EÔ EÐÝ& uÕ.AÀ*Ô.MÐN`Ô.aÑbÔbÐØ#Ô0ˆDÝœ DÑ)Ô)ˆJØ#3Ð#3°F¸JÑ#GÔ#GˆEŒN˜4Ñ Ý'¨°
Ñ;Ô;ˆˆØ€Ló    Ú
device_mapÚreturnc                 ó~  — ddl m} ddlm}  ||j        |j        dd|j        |j        ||j        |j	        d¬¦
  «
        }|  
                    ¦   «         D ]Ì\  }}t          ||¦  «        sŒt          j        d¦  «        5  t          |t          j        ¦  «        rp ||j        |j        |j        |j        |j        |j        |j        du|j        j        d¬	¦	  «	        }	|	                     d¦  «         |                      ||	¦  «         d}
ddd¦  «         n# 1 swxY w Y   ŒÍ|
st2                               d
¦  «         | S )aæ  
    Public method that replaces the linear layers of the given model with awq quantized layers.

    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[str]`, *optional*, defaults to `None`):
            A list of nn.Linear weights to not convert. If a parameter path is in the list (e.g. `lm_head.weight`), the corresponding module will not be
            converted.
        device_map (`Union[str, dict]`, *optional*, defaults to `None`):
            The device map that maps the parameters to the device
    r   )ÚMETHOD)Úhf_select_quant_linear_v2F)
ÚbitsÚ
group_sizeÚdesc_actÚsymÚformatÚbackendr-   Úquant_methodÚ
zero_pointÚpackÚmetaNT)	r2   r5   r4   r3   Úin_featuresr   ÚbiasÚdevÚregister_buffersz»You are loading your model using eetq but no linear modules were found in your model. Please double check your model architecture, or submit an issue on github if you think this is a bug.)Úgptqmodel.quantizationr0   Úgptqmodel.utils.importerr1   r2   r3   r6   r7   ÚAWQr9   Únamed_modulesr   r   ÚdeviceÚ
isinstanceÚnnÚLinearr5   r4   r<   r   r=   ÚweightÚrequires_grad_Úset_submoduleÚloggerÚwarning)r"   Úmodules_to_not_convertÚquantization_configr-   r0   r1   Ú
target_clsÚmodule_namer%   Ú
new_moduleÚhas_been_replaceds              r+   Úreplace_with_awq_linearrS   8   sÍ  € ð( .Ð-Ð-Ð-Ð-Ð-ØBÐBÐBÐBÐBÐBà*Ð*Ø Ô%Ø&Ô1ØØØ"Ô)Ø#Ô+ØØ”ZØ&Ô1Øðñ ô €Jð  %×2Ò2Ñ4Ô4ð )ð )Ñˆ�VÝ$ [Ð2HÑIÔIð 	ØÝŒ\˜&Ñ!Ô!ð 	)ð 	)Ý˜&¥"¤)Ñ,Ô,ð )Ø'˜ZØ,Ô1Ø+Ô/Ø0Ô9Ø2Ô=Ø &Ô 2Ø!'Ô!4Øœ¨DÐ0ØœÔ,Ø%)ð
ñ 
ô 
�
ð ×)Ò)¨%Ñ0Ô0Ð0Ø×#Ò# K°Ñ<Ô<Ð<Ø$(Ð!ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)øð" ð 
Ý�Šðñ	
ô 	
ð 	
ð €Ls   Á>BDÄD	ÄD	)NNN)Ú__doc__Úquantizers.quantizers_utilsr   Úutilsr   r   r   Útorch.nnrF   Ú
get_loggerÚ__name__rK   r   r!   ÚstrÚdictÚboolrS   © r,   r+   ú<module>r^      s8  ðð >Ð =à ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /ð ÐÑÔð Ø€L€L€LØÐÐÐÐÐà	ˆÔ	˜HÑ	%Ô	%€ð  °VÐ<Ð<Ø$¸/ÐJÐJØ°ÐAÐAØ¨iÐ8Ð8Ø¨wÐ7Ð7Ø°?ÐCÐCØ °fÐ=Ð=Ø °oÐFÐFð	ð 	Ð ðð ð ð&  ØØ$(ð	?ð ?ð �d‘
˜TÑ!ð	?ð
 
ð?ð ?ð ?ð ?ð ?ð ?r,   