§
    Ý˜ºh•  ã                   óN   — d Z ddlmZmZmZ  e¦   «         rddlmZ 	 	 	 	 dd„ZdS )z7SpQR (Sparse-Quantized Representation) integration fileé   )Úis_accelerate_availableÚis_spqr_availableÚis_torch_availableé    NFc                 ó^  — |€g }t          ¦   «         rddlm} t          ¦   «         rddlm} |                      ¦   «         D �]è\  }}|€g }|                     |¦  «         t          |t          j
        ¦  «        �rPd                     |¦  «        dz   |v�r4 |¦   «         5  d                     |¦  «        }	|j        }
|
                     ¦   «         }|	› d�|v o|	› d�|v o|	› d	�|v o|	› d
�|v }|st          d|	› d�¦  «        ‚|
|	› d�         }|
|	› d�         }|
|	› d	�         }|
|	› d
�         }|j        }|j        }|                     |||j        |j        |j        ||||¬¦	  «	        | j        |<   d}t-          |¦  «        | j        |         _        | j        |                              d¦  «         ddd¦  «         n# 1 swxY w Y   n	 t3          t5          |                     ¦   «         ¦  «        ¦  «        dk    rt9          |||||¬¦  «        \  }}|                     d¦  «         �Œê| |fS )af  
    Public method that recursively replaces the Linear layers of the given model with SpQR 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 (`SpQRConfig`):
            The quantization config object that contains the quantization parameters.
        modules_to_not_convert (`list[str]`, *optional*):
            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.
        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.
    Nr   )Úinit_empty_weights)ÚQuantizedLinearú.z.weightz.dense_weights.shapez.row_offsets.shapez.col_vals.shapez.in_perm.shapezJThe SpQR quantization config does not contain the shape configuration for zG. This indicates that the configuration is either invalid or corrupted.)	ÚrowsÚcolsÚbitsÚbeta1Úbeta2Údense_weights_shapeÚrow_offsets_shapeÚcol_vals_shapeÚin_perm_shapeTF)Úquantization_configÚmodules_to_not_convertÚcurrent_key_nameÚhas_been_replacedéÿÿÿÿ)r   Ú
accelerater   r   Ú
spqr_quantr	   Únamed_childrenÚappendÚ
isinstanceÚnnÚLinearÚjoinÚshapesÚkeysÚ
ValueErrorÚin_featuresÚout_featuresÚcreate_placehodlerr   r   r   Ú_modulesÚtypeÚ
source_clsÚrequires_grad_ÚlenÚlistÚchildrenÚreplace_with_spqr_linearÚpop)Úmodelr   r   r   r   r   r	   ÚnameÚmoduleÚtensor_namer!   Úshapes_keysÚshapes_validr   r   r   r   r$   r%   Ú_s                       úf/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/transformers/integrations/spqr.pyr.   r.      s?  € ð4 Ð%Ø!#ÐåÑ Ô ð 2Ø1Ð1Ð1Ð1Ð1Ð1ÝÑÔð /Ø.Ð.Ð.Ð.Ð.Ð.à×,Ò,Ñ.Ô.ð @!ñ @!‰ˆˆfØÐ#Ø!ÐØ×Ò Ñ%Ô%Ð%å�f�bœiÑ(Ô(ñ 1	à�xŠxÐ(Ñ)Ô)¨IÑ5Ð=SÐSÑSØ'Ð'Ñ)Ô)ð ,?ð ,?Ø"%§(¢(Ð+;Ñ"<Ô"<�Kà0Ô7�FØ"(§+¢+¡-¤-�Kð 'Ð<Ð<Ð<ÀÐKð JØ*Ð>Ð>Ð>À+ÐMðJà*Ð;Ð;Ð;¸{ÐJðJð  +Ð:Ð:Ð:¸kÐIð	 !ð (ð Ý(ðMØ1<ðMð Mð Mñô ð ð +1°KÐ1UÐ1UÐ1UÔ*VÐ'Ø(.°+Ð/QÐ/QÐ/QÔ(RÐ%Ø%+¨{Ð,KÐ,KÐ,KÔ%L�NØ$*¨kÐ+IÐ+IÐ+IÔ$J�Mà"(Ô"4�KØ#)Ô#6�Là+:×+MÒ+MØ)Ø(Ø0Ô5Ø1Ô7Ø1Ô7Ø,?Ø*;Ø'5Ø&3ð ,Nñ 
,ô 
,�E”N 4Ñ(ð )-Ð%õ 7;¸6±l´l�E”N 4Ô(Ô3à”N 4Ô(×7Ò7¸Ñ>Ô>Ð>ðY,?ð ,?ð ,?ñ ,?ô ,?ð ,?ð ,?ð ,?ð ,?ð ,?ð ,?øøøð ,?ð ,?ð ,?ð ,?øð\ Ý�t�F—O’OÑ%Ô%Ñ&Ô&Ñ'Ô'¨!Ò+Ð+Ý#;ØØ$7Ø'=Ø!1Ø"3ð$ñ $ô $Ñ ˆAÐ ð 	×Ò˜RÑ Ô Ð Ñ ØÐ#Ð#Ð#s   Â DF>Æ>G	ÇG	)NNNF)Ú__doc__Úutilsr   r   r   Útorch.nnr   r.   © ó    r7   ú<module>r=      s‚   ðð :Ð 9à RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rð ÐÑÔð ØÐÐÐÐÐð
 ØØØðc$ð c$ð c$ð c$ð c$ð c$r<   