
    eTh                     R    S r SSKJrJrJr  \" 5       (       a  SSKJr      SS jrg)z7SpQR (Sparse-Quantized Representation) integration file   )is_accelerate_availableis_spqr_availableis_torch_available    Nc                 d   Uc  / n[        5       (       a  SSKJn  [        5       (       a  SSKJn  U R                  5        GH  u  pxUc  / nUR                  U5        [        U[        R                  5      (       GaV  SR                  U5      S-   U;  Ga<  W" 5          SR                  U5      n	UR                  n
U
R                  5       nU	 S3U;   =(       a&    U	 S3U;   =(       a    U	 S	3U;   =(       a    U	 S
3U;   nU(       d  [        SU	 S35      eX S3   nX S3   nX S	3   nX S
3   nUR                  nUR                   nWR#                  UUUR$                  UR&                  UR(                  UUUUS9	U R*                  U'   Sn[-        U5      U R*                  U   l        U R*                  U   R1                  S5        SSS5        O [3        [5        UR7                  5       5      5      S:  a  [9        UUUUUS9u  nnUR;                  S5        GM     X4$ ! , (       d  f       N]= f)a"  
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                       V/var/www/auris/envauris/lib/python3.13/site-packages/transformers/integrations/spqr.pyr.   r.      st   4 %!#  1.,,.#!%fbii((xx()I5=SS')"%((+;"<K077F"(++-K '-';<K J*m+=>+MJ*m?;{JJ  +m>:kI	 ! ((11< >LM  +1=@T1U*V'(.>P/Q(R%%+m?,K%LN$*].+I$JM"("4"4K#)#6#6L+:+M+M)(055177177,?*;'5&3 ,N 
,ENN4( )-% 7;6lENN4(3NN4(77>Y *)\ tFOO%&'!+#;$7'=!1"3$ A  	R A /B ##s *)s   D,H!!
H/	)NNNF)__doc__utilsr   r   r   torch.nnr   r.        r7   <module>r=      s2    : R R 
 c$r<   