§
    Ý˜ºh¼  ã                   ó>   — d Z ddlmZ ddlmZ ddlmZ 	 	 	 	 dd„ZdS )z9VPTQ (Vector Post-Training Quantization) integration fileé    N)Úinit_empty_weights)ÚVQuantLinearFc                 ó°  — |r|ndg}|                       ¦   «         D �]¶\  }}|€g }|                     |¦  «         d                     |¦  «        }|j        }|j        }	t          |t          j        ¦  «        rü||vrø||	v s
|d         |v rê|	                     |d¦  «        p|                     |d         d¦  «        }
t          ¦   «         5  |j
        }|j        }t          |||
d         |
d         |
d         |
d         |
d	         |
d
         |
d         |
d         |
d         dd|j        du¬¦  «        | j        |<   d}| j        |                              d¦  «         ddd¦  «         n# 1 swxY w Y   t!          t#          |                     ¦   «         ¦  «        ¦  «        dk    rt'          |||||¬¦  «        \  }}|                     d¦  «         �Œ¸| |fS )aw  
    Public method that recursively replaces the Linear layers of the given model with VPTQ quantized layers.
    `accelerate` is needed to use this method. Returns the converted model and a boolean that indicates if the
    conversion has been successful or not.

    Args:
        model (`torch.nn.Module`):
            The model to convert, can be any `torch.nn.Module` instance.
        quantization_config (`VptqConfig`):
            The quantization config object that contains the quantization parameters.
        modules_to_not_convert (`list[`str`]`, *optional*, defaults to `["lm_head"]`):
            Names of the modules to not convert in `VQuantLinear`. In practice we keep the `lm_head` in full precision
            for numerical stability reasons.
        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.
    Úlm_headNú.éÿÿÿÿÚvector_lensÚnum_centroidsÚnum_res_centroidsÚ	group_numÚ
group_sizeÚoutlier_sizeÚindices_as_floatÚenable_normÚenable_permTF)r	   r
   r   r   r   r   r   r   r   Úis_indice_packedÚenable_proxy_errorÚbiasr   )Úquantization_configÚmodules_to_not_convertÚcurrent_key_nameÚhas_been_replaced)Únamed_childrenÚappendÚjoinÚshared_layer_configÚconfig_for_layersÚ
isinstanceÚnnÚLinearÚgetr   Úin_featuresÚout_featuresr   r   Ú_modulesÚrequires_grad_ÚlenÚlistÚchildrenÚreplace_with_vptq_linearÚpop)Úmodelr   r   r   r   ÚnameÚmoduleÚ
layer_namer   r   Úlayer_paramsr"   r#   Ú_s                 úf/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/transformers/integrations/vptq.pyr)   r)      s}  € ð6 8NÐ^Ð3Ð3ÐT]ÐS^Ðà×,Ò,Ñ.Ô.ð 2!ñ 2!‰ˆˆfØÐ#Ø!ÐØ×Ò Ñ%Ô%Ð%Ø—X’XÐ.Ñ/Ô/ˆ
Ø1ÔEÐØ/ÔAÐõ �v�rœyÑ)Ô)ð 	;àÐ"8Ð8Ð8ØÐ 1Ð1Ð1Ð7GÈÔ7KÐObÐ7bÐ7bà,×0Ò0°¸TÑBÔBð ÐFY×F]ÒF]Ø  Ô$ dñGô GˆLõ $Ñ%Ô%ð ;ð ;Ø$Ô0�Ø%Ô2�å'3ØØ Ø ,¨]Ô ;Ø".¨Ô"?Ø&2Ð3FÔ&GØ*¨;Ô7Ø+¨LÔ9Ø!-¨nÔ!=Ø%1Ð2DÔ%EØ ,¨]Ô ;Ø ,¨]Ô ;Ø%)Ø',Øœ¨DÐ0ð(ñ (ô (�”˜tÑ$ð  %)Ð!ð ”˜tÔ$×3Ò3°EÑ:Ô:Ð:ð/;ð ;ð ;ñ ;ô ;ð ;ð ;ð ;ð ;ð ;ð ;øøøð ;ð ;ð ;ð ;õ0 �t�F—O’OÑ%Ô%Ñ&Ô&Ñ'Ô'¨!Ò+Ð+Ý#;ØØ$7Ø'=Ø!1Ø"3ð$ñ $ô $Ñ ˆAÐ ð 	×Ò˜RÑ Ô Ð Ñ ØÐ#Ð#Ð#s   Ã
BE)Å)E-	Å0E-	)NNNF)Ú__doc__Útorch.nnr   Ú
accelerater   Úvptqr   r)   © ó    r1   ú<module>r8      su   ðð <Ð ;à Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ø Ð Ð Ð Ð Ð ð
 ØØØðP$ð P$ð P$ð P$ð P$ð P$r7   